简体   繁体   English

是否在DSA代码的更新循环中使用glBindVertexArray

[英]Using glBindVertexArray in update loop in DSA code or not

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. 我正在将一些opengl代码转换为DSA的过程,其编写的每个地方都没有绑定顶点数组,因为它是在DSA中继承的。 So I use 所以我用

GLuint VBO, VAO, indexBuffer;
glCreateVertexArrays(1, &VAO);
glCreateBuffers(1, &indexBuffer);
glCreateBuffers(1, &VBO);
...

instead of the glGen... counterparts. 而不是glGen ...对应物。

But now I just wonder whether there is a DSA version of binding the vertex arrays in the update loop. 但是现在我只是想知道在更新循环中是否有绑定顶点数组的DSA版本。 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. 但是,如果我不将glBindVertexArray替换为其他东西,我以后会在代码中遇到一些有趣的问题。 Just as I replaced glBindTexture with glBindTextureUnit 就像我用glBindTexture替换glBindTextureUnit

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. 在更新循环中使用VAO时,应将其绑定。 But when you use DSA you don't need to bind the VAO (nor the VBO nor the index buffer) when you modify them. 但是,当您使用DSA时,您在修改它们时不需要绑定VAO(既不绑定VBO,也不绑定索引缓冲区)。 Therefore there is no alternative glDrawElements that takes VAO id as a parameter like eg glVertexArrayElementBuffer does. 因此,没有像glVertexArrayElementBuffer这样的将VAO id作为参数的glDrawElements

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM