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

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

本文介绍了是否在DSA代码的更新循环中使用glBindVertexArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些opengl代码转换为DSA的过程,其编写的所有内容都不绑定顶点数组,因为它是在DSA中继承的.所以我用

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);
...

而不是glGen ...的对应对象.

instead of the glGen... counterparts.

但是现在我只是想知道在更新循环中是否有绑定顶点数组的DSA版本.现在我有

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);
   }

可以正常工作.但是,如果不将glBindVertexArray替换为其他内容,我以后会在代码中遇到一些有趣的问题.就像我将glBindTexture替换为glBindTextureUnit

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

推荐答案

总结起来,按照问题所示的示例编写更新循环是完全正确的.在更新循环中使用VAO时,应将其绑定.但是,当您使用DSA时,您在修改它们时不需要绑定VAO(既不绑定VBO,也不绑定索引缓冲区).因此,没有其他选择glDrawElements将VAO id作为参数,例如glVertexArrayElementBuffer做到了.

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.

这篇关于是否在DSA代码的更新循环中使用glBindVertexArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:02