Possible Duplicate:
Explicit vs Automatic attribute location binding for OpenGL shaders
Why should I use glBindAttribLocation?
I tried to call glGetAttribLocation without binding any attrib locations and it seemed to work. So I can always cache the attrib locations in array if I want to have instant access. What is the purpose of using glBindAttribLocation then ?
[OpenGL 2.0]
glBindAttribLocation
"binds" an index to an attribute name. This allows you to use the same indices for the same attributes across different shaders. For example: vertex coordinates = 0, texture coordinates = 1, normals = 2. This simplifies drawing code, by conforming the shader to your code, rather than the other way around (requesting attrib locations).
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 like this:
glVertexAttribPointer(GRAPHICS_ATTRIB_VERTEX, ....);
This will work with all my shaders with no calls to glGetAttribLocation
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With