static std::string GetCompiledShaderText(ShHandle parser) { std::string txt = Hlsl2Glsl_GetShader (parser); int count = Hlsl2Glsl_GetUniformCount (parser); if (count > 0) { const ShUniformInfo* uni = Hlsl2Glsl_GetUniformInfo(parser); txt += "\n// uniforms:\n"; for (int i = 0; i < count; ++i) { char buf[1000]; snprintf(buf,1000,"// %s:%s type %d arrsize %d", uni[i].name, uni[i].semantic?uni[i].semantic:"<none>", uni[i].type, uni[i].arraySize); txt += buf; if (uni[i].registerSpec) { txt += " register "; txt += uni[i].registerSpec; } txt += "\n"; } } return txt; }
// // Save the uniform info to a file // bool SaveUniforms( const char* fn, ShHandle handle) { // // Uniform type conversion string // const char typeStrings[][32] = { "void", "bool", "bvec2", "bvec3", "bvec4", "int", "ivec2", "ivec3", "ivec4", "float", "vec2", "vec3", "vec4", "mat2", "mat3", "mat4", "sampler", "sampler1D", "sampler2D", "sampler3D", "samplerCube", "struct" }; // // Uniform element count lookup table by uniform type // const int elementCount[] = { 0, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 4, 9, 16, 0, 0, 0, 0, 0, 0 }; FILE* fp = fopen( fn, "w"); if (!fp) return false; // failed to open file const ShUniformInfo* uniforms = Hlsl2Glsl_GetUniformInfo( handle); const int nUniforms = Hlsl2Glsl_GetUniformCount( handle); for (int ii=0; ii<nUniforms; ii++) { fprintf( fp, "%s %s", typeStrings[uniforms[ii].type], uniforms[ii].name); if ( uniforms[ii].arraySize) fprintf( fp, "[%d]", uniforms[ii].arraySize); if (uniforms[ii].semantic) fprintf( fp, " : %s", uniforms[ii].semantic); if (uniforms[ii].init) { int as = uniforms[ii].arraySize; as = (as) ? as : 1; fprintf( fp, " =\n {"); for ( int jj=0; jj < elementCount[uniforms[ii].type]*as; jj++) { fprintf( fp, " %f,", uniforms[ii].init[jj]); } fprintf( fp, "}\n"); } else fprintf( fp, "\n"); } fclose(fp); return true; }