0

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

Hans Micheelsen
  • 19
  • 1
  • 2
  • 10
  • Writing `glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES ...); glBindVertexArray(0);`, is perfectly fine, it does not matter if the VAO was created using the `Gen` or `Create` function. Do you want to know if there exists a `glDrawElements` that does not require a `glBindVertexArray` to be called before, but passes the VAO id directly to the draw function? – t.niese Jan 09 '19 at 20:24
  • Well, now that I think of it. Yes, it is what I mean. – Hans Micheelsen Jan 09 '19 at 20:26
  • Or just a sanity check of my code – Hans Micheelsen Jan 09 '19 at 20:32
  • The idea of DSA is that you don't need to bind the objects to modify them, and that you only bind them for the case when you use them. The usage case is more time critical as the modifying part, and as of that you want to have full control over that part, to optimally use the capabilities of the GPU for rendering/computation. – t.niese Jan 09 '19 at 20:37
  • Ok, that makes sense. Its perfectly fine to bind the objects for the update loop, as I do not modify them. I only instruct the GPU to use them. And therefore there is no need to search for other ways to do it in the update loop. Thank you very much t.niese! – Hans Micheelsen Jan 09 '19 at 20:49
  • Being a new user I just have to ask this. Should I use the Answer Your Question button and wrap up the answer I got from t.niese in order to close this question? – Hans Micheelsen Jan 10 '19 at 19:21
  • Yes you should. At the time I wrote the comments I was not sure if this actually answers your question. And up till and including now I don't have time to write a clean answer. If no one answers the question, then you are always welcome to answer it yourself based on the comments are your findings. Even if you get answers and you think you can answer your own question more precisely then you are free to create your own answer. And if you feel really really bad about using what others have written to create an answer you could check the `community wiki` checkbox. – t.niese Jan 10 '19 at 20:27
  • I cannot find the `community wiki` checkbox. Maybe I don't have enough reputation – Hans Micheelsen Jan 11 '19 at 21:42

1 Answers1

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.

Hans Micheelsen
  • 19
  • 1
  • 2
  • 10