How to do it...

After linking and enabling the shader program, use the following code to display the list of active uniforms:

  1. Start by querying for the number of active uniform variables:
GLint numUniforms = 0; 
glGetProgramInterfaceiv( handle, GL_UNIFORM,    GL_ACTIVE_RESOURCES, &numUniforms);
  1. Loop through each uniform index and query for the length of the name, the type, the location, and the block index:
GLenum properties[] = {GL_NAME_LENGTH, GL_TYPE,    GL_LOCATION, GL_BLOCK_INDEX}; 
 
std::cout << "Active uniforms" << std::endl; 
for( int i = 0; i < numUniforms; ++i ) { 
  GLint results[4]; 
  glGetProgramResourceiv(handle, GL_UNIFORM, i, 4,  properties, 4, NULL, results); if( results[3] != -1 ) continue; // Skip uniforms in blocks GLint nameBufSize ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.