This might be a noob question. As I understand it, glBindAttribLocation(..., AAA, ...) will bind an attribute within the program to the location ID of AAA, as long as AAA is unique. If I have the following code:
glBindAttribLocation(..., 0, "XXX");
glBindAttribLocation(..., 1, "YYY");
This will bind my two variables to location ID 0 and 1. I would then call:
glBindBuffer(GL_ARRAY_BUFFER, VBId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBId);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 6, 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 6, (void *) 0 + sizeof(float) * 3);
glEnableVertexAttribArray(1);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
Up to this point, I understand that the IDs of 0 and 1 are passed into glVertexAttribPointer() as the first parameter.
Would it be safe to assume that if I obtained the location IDs of the attributes (as above) through glGetAttribLocation() calls, such that the IDs returned were 5 and 6 instead of 0 and 1, could I pass 5 and 6 into glVertexAttribPointer() and glEnableVertexAttribArray() instead of 0 and 1??
glGetAttribLocation() returns the correct index. So yes, it is safe to use those values in glVertexAttribPointer() and glEnableVertexAttribArray().
But calling glGetAttribLocation for each shader might be expensive if you don't cache it. Using glBindAttribLocation() allows to use a convention, position always in 0, normal in 1 and so on.
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