opengl Program Introspection Vertex Attribute Information

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Information about vertex attributes can be retrieved with the OGL function glGetProgram and the parameters GL_ACTIVE_ATTRIBUTES and GL_ACTIVE_ATTRIBUTE_MAX_LENGTH.

The location of an active shader attribute can be determined by the OGL function glGetAttribLocation, by the index of the attribute.

GLuint shaderProg = ...;
std::map< std::string, GLint > attributeLocation;

GLint maxAttribLen, nAttribs;
glGetProgramiv( shaderProg, GL_ACTIVE_ATTRIBUTES, &nAttribs );
glGetProgramiv( shaderProg, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttribLen 
GLint written, size;
GLenum type;
std::vector< GLchar >attrName( maxAttribLen );
for( int attribInx = 0; attribInx < nAttribs; attribInx++ )
{
    glGetActiveAttrib( shaderProg, attribInx, maxAttribLen, &written, &size, &type, &attrName[0] );
    attributeLocation[attrName] = glGetAttribLocation( shaderProg, attrName.data() );
}


Got any opengl Question?