glBindAttribLocation "binds" the index to the attribute name. This allows you to use the same indexes for the same attributes in different shaders. For example: vertex coordinates = 0, texture coordinates = 1, normals = 2. This simplifies the drawing code by matching the shader with your code, and not vice versa (requesting places for attributes).
In my code, I create an enum for common vertex attributes:
enum { GRAPHICS_ATTRIB_VERTEX = 0, GRAPHICS_ATTRIB_NORMAL, GRAPHICS_ATTRIB_TEXTURE, };
Bind them using glBindAttribLocation , then I can use them as follows:
glVertexAttribPointer(GRAPHICS_ATTRIB_VERTEX, ....);
This will work with all my shaders without calling glGetAttribLocation .
source share