1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #ifndef IGL_SHADER_PROGRAM_UNIFORMS_MAP_H
- #define IGL_SHADER_PROGRAM_UNIFORMS_MAP_H
- #include <string>
- #include <map>
- #ifdef __APPLE__
- # include <OpenGL/gl.h>
- #else
- # include <GL/gl.h>
- #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<std::string,GLint> & uniforms);
- }
- // Implementation
- #include "verbose.h"
- #include "report_gl_error.h"
- void igl::shader_program_uniforms_map(
- const GLuint id,
- std::map<std::string,GLint> & 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
|