# Binding consecutive attributes in buffer to non-consecutive indices

This topic is 1260 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Wondering if this is an issue people deal with or if I'm complicating something unnecessarily. If I make a series of calls like the following during shader compilation / linking:

glBindAttribLocation(program, 0, "position");
glBindAttribLocation(program, 1, "normal");
glBindAttribLocation(program, 2, "color");

and I later have a vertex array that only contains position and color, I sort of expected the following to work:

glEnableVertexAttribArray(0);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, ...); // assume I've proven that all other parameters are valid
glVertexAttribPointer(2, ...);

However it doesn't. My triangles are rendered in the correct positions but their color is a solid red (when it should be a gradient). Binding color to attrib location 1 instead of 2 obviously solves the problem, but I was expecting that the first parameter to glVertexAttribPointer was just a logical relation to the index we previously bound to that attribute in the shader we're using -- not something that actually mandated the ordering of our data in memory (which I thought was the purpose of our attribute 'offset').

The motivation behind this sounds simple to me: I want to be able to define a standard ordering for all attributes and bind them to every shader during compilation. Is it really assumed that you always put your attributes in the same order in memory? If so, what's the point of specifying an offset to glVertexAttribPointer? I've seen suggestions on various sites and forums (including this one) that suggest you should explicitly set the order of all of your attributes. I just don't see how that would work in the case that you have some shaders that know about, say, Position and Normal while others only know about Position and Color.

Am I missing something? Is there a simpler solution?

##### Share on other sites

In case anyone was interested, I figured out the issue. As it seems to always go this was a user-error and the functionality works as expected when used correctly. I was trying to explicitly bind my attributes AFTER my GLSL program was linked, rather than before. My explicit choices were being discarded and the linker was using the automatic values instead.

1. 1
2. 2
JoeJ
17
3. 3
4. 4
5. 5
frob
11

• 13
• 16
• 13
• 20
• 12
• ### Forum Statistics

• Total Topics
632178
• Total Posts
3004608

×