#ifndef IGL_SHADER_PROGRAM_UNIFORMS_MAP_H #define IGL_SHADER_PROGRAM_UNIFORMS_MAP_H #include #include #ifdef __APPLE__ # include #else # include #endif namespace igl { // Builds a map of *active* uniform names as strings to their respective // locations as GLuint. // Input: // id index id of the program to query // Output: // uniforms map of names to locations // Returns true on success, false on errors void shader_program_uniforms_map( const GLuint id, std::map & uniforms); } // Implementation #include "verbose.h" #include "report_gl_error.h" void igl::shader_program_uniforms_map( const GLuint id, std::map & uniforms) { // empty the map of previous contents uniforms.clear(); // get number of active uniforms GLint n = 200; glGetProgramiv(id,GL_ACTIVE_UNIFORMS,&n); // get max uniform name length GLint max_name_length; glGetProgramiv(id,GL_ACTIVE_UNIFORM_MAX_LENGTH,&max_name_length); // buffer for name GLchar * name = new GLchar[max_name_length]; // buffer for length GLsizei length = 100; GLenum type; GLint size; // loop over active uniforms getting each's name for(GLuint u = 0;u < n;u++) { // I have no idea why glGetActiveUniformName doesn't work but // glGetActiveUniform does... //glGetActiveUniformName(id,u,max_name_length,&length,name); glGetActiveUniform(id,u,max_name_length,&length,&size,&type,name); // insert into map uniforms[string(name)] = u; } delete[] name; } #endif