0
GLuint index = 0;
glBindAttribLocation(mprogram, index, name);

For example, the '0' index is gl_position, but what about the other indexes like 1 and 2?

@Nicolas The problem is that when I set the index to zero, I noticed that the calls to glVertexAttrib(index...) would modify the vertex positions instead of the attribute I assigned it to...

user52343
  • 773
  • 1
  • 7
  • 19

1 Answers1

0

First, gl_Position is the output position from the vertex shader, not the input. It's not a vertex attribute and it never has been. You're probably thinking about gl_Vertex.

Most importantly second, the built-in attributes like gl_Vertex, gl_Color, etc do not have generic attribute indices. gl_Vertex is not the same thing as generic attribute 0. The OpenGL specification explicitly forbids these two being the same. Generic attributes (things that have attribute indices) and built-in attributes do not "alias" with one another. They don't share the same resources or space.

Now, NVIDIA's OpenGL implementation allows aliasing, in direction contravention of the OpenGL specification. But such code is non-portable (and terrible). If you want to find exactly how NVIDIA does their mapping, I'm sure documentation on NVIDIA's site will spell it out somewhere.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • But I thought it to be specified, that generic attribute 0 is indeed aliased with the builtin vertex position (at least in the old non-deprecated days). Well, at least the *Orange Book* states this and I believed it that far. – Christian Rau Apr 27 '12 at 20:21
  • @ChristianRau: You may be getting this confused with the need to use either attribute 0 or `gl_Vertex` when rendering (under compatibility rules). They both serve to "provoke" the vertex under `glBegin/glEnd`, so you have to have something in one of them, and you can't use both for the same render call. But if that's what it says, then the Orange Book is wrong. From the OpenGL 3.3 compatibility specification: "It is not possible to alias generic attributes with conventional ones." No exception is made for `gl_Vertex` and attribute 0. – Nicol Bolas Apr 27 '12 at 20:26
  • Looked it up. The 2.1-spec says (in chapter 2.7): *"Setting generic vertex attribute zero specifies a vertex; the four vertex coordinates are taken from the values of attribute zero. A Vertex2, Vertex3, or Vertex4 command is completely equivalent to the corresponding VertexAttrib command with an index of zero. Setting any other generic vertex attribute updates the current values of the attribute. There are no current values for vertex attribute zero."* To be *"completely equivalent"*, doesn't it have to send values to the same attribute channel? – Christian Rau Apr 27 '12 at 20:26
  • @ChristianRau: Then the spec is arguing with itself, because the *very next paragraph* starts with, "There is no aliasing among generic attributes and conventional attributes". – Nicol Bolas Apr 27 '12 at 20:32
  • In this paragraph it says: *"In other words, an application can set all MAX VERTEX ATTRIBS generic attributes and all conventional attributes without fear of one particular attribute overwriting the value of another attribute."*. This is the case because there are no current values for position and attrib 0 and calling either `glVertex` or `glVertexAttrib(0)` provokes a new vertex so they cannot interfere anyway, but to behave *"completely equivalent"* they have to send values to `gl_Vertex` and the attribute bound to index 0. I'll go look what it says about arrays now. – Christian Rau Apr 27 '12 at 20:57
  • And indeed the next section about arrays treats index 0 specially, using only one of index 0 and buitlin position (if both are enabled). So they cannot interfere here, too. So I don't think the spec contradicts itself anywhere, although the paragraph about no aliasing misses the context of the other paragraphs it doesn't contradict them. – Christian Rau Apr 27 '12 at 21:04