我有一种初始化我的 VBO/VAO 的方法:
glBindBuffer(GL_ARRAY_BUFFER, mVBO_VertexShader);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indexData), indexData, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// setup VAO
glBindVertexArray(mVAO);
glBindBuffer(GL_ARRAY_BUFFER, mVBO_VertexShader);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
然后是一个单独的绘图方法;
glBindVertexArray(mVAO);
glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_SHORT, &mIndexBuffer);
glBindVertexArray(0);
我是否需要GL_ELEMENT_ARRAY_BUFFER
在调用后解除绑定,glDrawElements
或者它的状态是否“绑定”到 VAO?(所以如果我解除绑定 VAO,GL_ELEMENT_ARRAY_BUFFER
也会解除绑定)?