问题
I'm the process of converting some opengl code to DSA and everywhere its written not to bind the vertex array, because its inherit in DSA. So I use
GLuint VBO, VAO, indexBuffer;
glCreateVertexArrays(1, &VAO);
glCreateBuffers(1, &indexBuffer);
glCreateBuffers(1, &VBO);
...
instead of the glGen... counterparts.
But now I just wonder whether there is a DSA version of binding the vertex arrays in the update loop. Now I have
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Draw the triangle
ourShader.Use();
const auto Textureloc = glGetUniformLocation(ourShader.Program, "ourTexture");
glBindTextureUnit(Textureloc, texture);
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 9, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
glBindTextureUnit(0, 0);
glfwSwapBuffers(window);
}
which works all right. But will I run into some interesting problems later in my coding if I don't replace the glBindVertexArray
to something else. Just as I replaced glBindTexture
with glBindTextureUnit
回答1:
To wrap things up, it is perfectly correct to write the update loop as in the example shown in the question. The VAO should be bound when it is used in the update loop. But when you use DSA you don't need to bind the VAO (nor the VBO nor the index buffer) when you modify them.
Therefore there is no alternative glDrawElements
that takes VAO id as a parameter like e.g. glVertexArrayElementBuffer
does.
来源:https://stackoverflow.com/questions/54117299/using-glbindvertexarray-in-update-loop-in-dsa-code-or-not