Question

The OpenGL Wiki: Vertex Specification states that:

Note: The GL_ARRAY_BUFFER​ binding is NOT part of the VAO's state! I know that's confusing, but that's the way it is.

Below is how I use the VAO, which seems to work as intended. What is wrong here? My understanding of OpenGL (or OpenGL Wiki), my OpenGL driver (OSX 10.9) or the OpenGL Wiki?

// ------ Pseudo-code ------ 
// setup
[...]
glBindVertexArray(vertexArrayObjectIdx1);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferId1);
for each vertex attribute
    glEnableVertexAttribArray(...);
    glVertexAttribPointer(...);

glBindVertexArray(vertexArrayObjectIdx2);
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferId2);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBufferId2);
for each vertex attribute
    glEnableVertexAttribArray(...);
    glVertexAttribPointer(...);

// rendering
[...]
glBindVertexArray(vertexArrayObjectIdx1);
glDrawElements(...);
glBindVertexArray(vertexArrayObjectIdx2);
glDrawElements(...);
Was it helpful?

Solution

It means that when you rebind the VAO the GL_ARRAY_BUFFER does not get rebound

However the glVertexAttribPointer does bind the (then) bound GL_ARRAY_BUFFER to the correct attribute in the VAO so it does work like you want.

Actually they could have defined glVertexAttribPointer as:

void glVertexAttribPointer(GLuint index​, GLint size​, GLenum type​, GLboolean normalized​, GLsizei stride​, uint bufferName, const GLvoid * pointer​);

and eliminate it's dependency on the bound GL_ARRAY_BUFFER. But hindsight and all that...

Important to remember is that the GL_ARRAY_BUFFER is not important to drawing but the how the vertex attributes are bound is.

in contrast the GL_ELEMENT_ARRAY_BUFFER is stored in the VAO

OTHER TIPS

Down below in the same Wiki entry, you can see the explanation as well - This is also why GL_ARRAY_BUFFER​ is not VAO state; the actual association between an attribute index and a buffer is made by glVertexAttribPointer​. ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top