Information about active uniforms in a program can be retrieved with the OGL function glGetProgram and the parameters GL_ACTIVE_UNIFORMS
and GL_ACTIVE_UNIFORM_MAX_LENGTH
.
The location of an active shader uniform variable can be determined by the OGL function glGetActiveUniform, by the index of the attribute.
GLuint shaderProg = ...;
std::map< std::string, GLint > unifomLocation;
GLint maxUniformLen, nUniforms;
glGetProgramiv( shaderProg, GL_ACTIVE_UNIFORMS, &nUniforms );
glGetProgramiv( shaderProg, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformLen );
GLint written, size;
GLenum type;
std::vector< GLchar >uniformName( maxUniformLen );
for( int uniformInx = 0; uniformInx < nUniforms; uniformInx++ )
{
glGetActiveUniform( shaderProg, uniformInx, maxUniformLen, &written, &size, &type, &uniformName[0] );
unifomLocation[uniformName] = glGetUniformLocation( shaderProg, uniformName.data() );
}