OpenGL glBindBuffer (0) outside of vao?

I am currently doing this to set up my vao:

glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);

...

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBindVertexArray(0);

      

My question is, do I need to bind null buffers so that my vbo and ibo changes are changed after I finished with my vao or when bind null null voo also discarded the current buffers? For example, I would do the following:

glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

      

+3


source to share


1 answer


Typically, you don't have to explicitly disable your buffers. It shouldn't do any harm to keep them tied up. They don't just change spontaneously. If other code also uses buffers, it needs to bind its own buffers before working with them.

Detaching VAO is definitely a waste if you are using modern OpenGL (main profile). Every vertex setting and drawing operation will have to bind a VAO anyway, so there is no need to unbind the previous VAO and then just bind another VAO soon.

But suppose for a moment that you still want to unbind your buffers just to be more reliable against possibly wrong code in your application, and you're willing to pay a performance penalty.



The answer is different from GL_ARRAY_BUFFER

and GL_ELEMENT_ARRAY_BUFFER

. Binding GL_ELEMENT_ARRAY_BUFFER

is part of the VAO state. Therefore, if you unbind VAO, this buffer will automatically unbind as well.

Binding GL_ARRAY_BUFFER

is not part of the VAO. In this case, you will have to explicitly unbind the buffer.

+7


source







All Articles