Contributors: 2 Tuesday, July 18, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial:
Roadmap: roadmap

Vertex Attribute Information

Download opengl eBook


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, );