Skip to content

Instantly share code, notes, and snippets.

@esmitt
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esmitt/9511117 to your computer and use it in GitHub Desktop.
Save esmitt/9511117 to your computer and use it in GitHub Desktop.
A function part of CGLSLProgram class (any class that to manage GLSL program/shaders in GLSL) to print the active Uniforms and Attributes variables in our shaders.
// We assume that the location of GLSL program is stored in the variable <code>m_uIdProgram</code> as an unsigned int
// #include <iomanip> is necessary to use of setw (text formatting)
void CGLSLProgram::showDebugging()
{
GLint iMaxLength, iNumAttrib, iNumUniform;
glGetProgramiv(m_uIdProgram, GL_ACTIVE_ATTRIBUTES, &iNumAttrib);
glGetProgramiv(m_uIdProgram, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &iMaxLength);
GLchar* name = new GLchar[iMaxLength];
GLint written, size, location;
GLenum type;
std:cout << "Index | Attribute Name" << std::endl;
std::cout << std::string(23, '-') << std::endl;
for(int i = 0; i < iNumAttrib; i++)
{
glGetActiveAttrib(m_uIdProgram, i, iMaxLength, &written, &size, &type, name);
location = glGetAttribLocation(m_uIdProgram, name);
std::cout << setw(5) << location << " | " << name << "," << std::endl;
}
delete name;
glGetProgramiv(m_uIdProgram, GL_ACTIVE_UNIFORMS, &iNumUniform);
glGetProgramiv(m_uIdProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, &iMaxLength);
name = new GLchar[iMaxLength];
std::cout << "Index | Uniform Name" << std::endl;
std::cout << std::string(21, '-') << std::endl;
for (int i = 0; i < iNumUniform; i++)
{
glGetActiveUniform(m_uIdProgram, i, iMaxLength, &written, &size, &type, name);
location = glGetUniformLocation(m_uIdProgram, name);
std::cout << setw(5) << location << " | " << name << "," << std::endl;
}
delete name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment