0
votes

I am having a hard time understanding what exactly is meant by state. I have read about vertex array objects (VAOs) and vertex buffer objects (VBOs) and as well as context creation. So far i have understood that context is the state of everything associated with the instance of OpenGL that you have created.

I have also understood that a VAO is a reference to the names you created which OpenGL allocated and VBO is the data of those VAOs. However, in the OpenGL red book it says that when you create a VBO that OpenGL allocates a state to the VBO which you obviously have to bind to the VAO.

What I don't understand is relationship between the objects and the context. If the context is supposed to be the state of the OpenGL instance, why does it create additional states which it allocates to the vertex buffer object? Whenever you call some function that changes that state of the context, it actually changes the VBO and not the actual default state of the context.

Have I understood this correctly or am I confusing something here?

1
i have found a defintion in uderstanding the relationship between these objects and state, best definition to date(IN PARTS) : The Vertex Array Object (a.k.a VAO) is a special type of object that encapsulates all the data that is associated with the vertex processor. Instead of containing the actual data, it holds references to the vertex buffers, the index buffer and the layout specification of the vertex itself. - thingybingytie
The advantage is that once you set up the VAO for a mesh you can bring in the entire mesh state by simply binding the VAO. After that you can render the mesh object and you don't need to worry about all of its state. The VAO remembers it for you. If your application needs to deal with meshes whose vertex layout slightly differs from one another the VAO takes care of it also. Just make sure to set up the correct layout when you create the VAO and forget about it. From now on it "sticks" to the VAO and becomes active whenever that VAO is used. - thingybingytie
When used correctly, VAOs can also represent an optimization opportunity for the driver of the GPU. If the VAO is set up once and used multiple times the driver can take advantage of knowing the mapping between the index buffer and the vertex buffers as well as the vertex layout in the buffers. Obviously, this depends on the specific driver that you are using and it is not guaranteed that all drivers will behave the same. At any rate, keep in mind that it is best to set up the VAO once and then reuse it over and over. - thingybingytie

1 Answers

0
votes

The OpenGL context contains all state within your OpenGL instance. The VBOs and VAOs are sub-states within that 'global' state. They cannot exist outside of the GL context (although you could potentially share them with other contexts). When you perform operations on either a VBO or VAO, you are modifying the state of the VBO/VAO, which is a part of the GL context, thus you are modifying it as well.