Reputation: 883
For example, I have the following piece of code:
//Create a vbo and bind it to the GL_ARRAY_BUFFER
glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
//vertexPosition is an array of floats that stores the position of 3 vertices (x, y, z, w)
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
//Enable the vbo at index 0 of the vao (assuming I have stored it previously at index 0)
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
//Finally draw the triangle
glDrawArrays(GL_TRIANGLES, 0, 3);
My question is, how does glDrawArrays() know that whatever is bound to the GL_ARRAY_BUFFER refers to information about position, and not about colors for example?
Upvotes: 0
Views: 221
Reputation: 18015
Where gl_Vertex
is available (ie not a core profile), the specification calls out that position and vertex attribute 0 alias.
From the gl 4.5 compatibility profile specification (page 401/1005):
Setting generic vertex attribute zero specifies a vertex, as described in section 10.7.2. Setting any other generic vertex attribute updates the current values of the attribute. There are no current values for vertex attribute zero
Upvotes: 2