void glBindAttribLocation(GLuint program, GLuint index, const GLchar *name);
If name refers to a matrix attribute variable, index refers to the first column of the matrix. Other matrix columns are then automatically bound to locations index+1 for a matrix of type mat2; index+1 and index+2 for a matrix of type mat3; and index+1, index+2, and index+3 for a matrix of type mat4.
This command makes it possible for vertex shaders to use descriptive names for attribute variables rather than generic variables that are numbered from zero to the value of GL_MAX_VERTEX_ATTRIBS minus one. The values sent to each generic attribute index are part of current state. If a different program object is made current by calling glUseProgram(), the generic vertex attributes are tracked in such a way that the same values will be observed by attributes in the new program object that are also bound to index.
Attribute variable name-to-generic attribute index bindings for a program object can be explicitly assigned at any time by calling glBindAttribLocation. Attribute bindings do not go into effect until glLinkProgram() is called. After a program object has been linked successfully, the index values for generic attributes remain fixed (and their values can be queried) until the next link command occurs.
Any attribute binding that occurs after the program object has been linked will not take effect until the next time the program object is linked.
If name was bound previously, that information is lost. Thus you cannot bind one user-defined attribute variable to multiple indices, but you can bind multiple user-defined attribute variables to the same index.
Applications are allowed to bind more than one user-defined attribute variable to the same generic vertex attribute index. This is called aliasing, and it is allowed only if just one of the aliased attributes is active in the executable program, or if no path through the shader consumes more than one attribute of a set of attributes aliased to the same location. The compiler and linker are allowed to assume that no aliasing is done and are free to employ optimizations that work only in the absence of aliasing. OpenGL implementations are not required to do error checking to detect aliasing.
Active attributes that are not explicitly bound will be bound by the linker when glLinkProgram() is called. The locations assigned can be queried by calling glGetAttribLocation().
OpenGL copies the name string when glBindAttribLocation is called, so an application may free its copy of the name string immediately after the function returns.
Generic attribute locations may be specified in the shader source text using a location layout qualifier. In this case, the location of the attribute specified in the shader's source takes precedence and may be queried by calling glGetAttribLocation().
GL_INVALID_OPERATION is generated if name starts with the reserved prefix "gl_".
GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.
GL_INVALID_OPERATION is generated if program is not a program object.
glGetActiveAttrib() with argument program
glGetAttribLocation() with arguments program and name
|Function / Feature Name||2.0||2.1||3.0||3.1||3.2||3.3||4.0||4.1||4.2||4.3||4.4||4.5|
Copyright © 2010-2014 Khronos Group