A bit of clarification on how EBOs work (Element array buffers)

Started by pdid, February 14, 2017, 01:11:40

Previous topic - Next topic

pdid

I understand that a EBO can be bound to a VAO, unlike the other OpenGL buffer objects. I also know that if no VAO is bound at the time of binding the EBO, the EBO is bound to the OpenGL context or the global state. My question is when you bind a EBO to a VAO, then unbind the VAO, and bind the EBO again, is the EBO bound to the VAO, the global state, or both? Thanks in advance for any help.

Kai

QuoteI understand that a EBO can be bound to a VAO, unlike the other OpenGL buffer objects.
You mean: "...can be bound to a VAO, just like the other OpenGL buffer objects".
And more precisely, you bind the sources of vertex attributes to a VAO, which can be a buffer object, in which case we call it a vertex buffer object (VBO).

As for the question of what state is affected by binding an element array buffer: Which element array buffer is bound only depends on the VAO currently being bound. An element array buffer can be bound to as many VAOs at the same time as you like. Consequently, when you bind an element array buffer to any VAO (also the default VAO 0), it remains bound to that VAO until you either delete the buffer object via glDeleteBuffers(), rebind another buffer via glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...) or delete the whole VAO via glDeleteVertexArrays() (if not the default VAO 0).
So, when you bind an element array buffer to VAO 0, and then bind a newly created VAO 1, you can also bind the same element array buffer to that VAO 1, too.
Since only one element array buffer can be effective/active at any given time due to being in the context of the VAO, it is of course possible.

You can also test which element array buffer is currently bound, by using GL11.glGetInteger(GL15.GL_ELEMENT_ARRAY_BUFFER_BINDING), which returns the integer handle of the buffer object bound to the element array buffer binding in the context of the currently bound VAO.