1

OpenGL Wiki:顶点规范指出:

注意:GL_ARRAY_BUFFER绑定不是VAO 状态的一部分!我知道这很令人困惑,但事实就是如此。

下面是我如何使用 VAO,它似乎按预期工作。这里有什么问题?我对 OpenGL(或 OpenGL Wiki)、我的 OpenGL 驱动程序(OSX 10.9)或 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(...);
4

2 回答 2

5

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

于 2014-01-03T15:47:32.233 回答
1

在同一个 Wiki 条目的下方,您也可以看到解释 - 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​....

于 2014-01-03T15:42:06.043 回答