Vertex Batching Noob question

Sorry for the noob question.:sweat_smile:

So I am doing refactoring of a very large program which uses a really big amount of vertices.
I am thinking that vertex batching can be the way.

So my questions are:

  • Should I try to put as many vertices as possible in a unique big VBO with a unique VAO and then call once the Draw? and
  • Is it not the same of linking multiple VBOs to the same VAO and then call once the Draw on the VAO?

Any examples and references are super appreciated!
Thank you for your help :slight_smile:

You might give an example of what you’re talking about. Linking multiple VBOs to the same VAO how? As separate vertex attributes? (I’m trying to fit the “call once the Draw” part of your question into this.)

Sorry, I figured out that my question was badly posed.

Lets say that I have a VAO and two VBOs.
I have already done glGenBuffers and glGenVertexArray and filled the VBOs with my correct vertex data.
Now I have the current scenario:

GLuint VAO;
GLuint VBO1;
GLuint VBO2;

//... previous VAO and VBO generation 

glBindBuffer(GL_ARRAY_BUFFER, VBO1);
glBindBuffer(GL_ARRAY_BUFFER, VBO2);

Does the last bind, for VBO2, overwrite the previous bind , i.e. the VBO1, to the VAO?
In this case I can actually have only one VBO linked to the VAO. Is it correct?

Yes, exactly. That’s what happens. The GL_ARRAY_BUFFER context buffer binding point is left pointing to VBO2 at the end of this code.

Also note: you haven’t changed VAO contents here. Binding something to GL_ARRAY_BUFFER is just a stopping off point to latching it to a vertex attribute binding (in the VAO) via glVertexAttribPointer(). And that latter binding is stored in the VAO.

No. See my last paragraph above.

A VAO tracks the:

  1. vertex attribute array state and
  2. index array state

needed to issue a draw call.

With recent hardware, you have at least 16 vertex attribute arrays, and each one can specify a buffer object which contains its values. Also, if you’re using indexed draw calls (e.g. glDrawElements), then the VAO can also track which buffer object contains its index values.

So if your driver supports 16 vertex attributes, then a VAO will track 17 different buffer object bindings.

Of course, while you could set the buffer object bindings for all enabled vertex attributes (and the index list) in a VAO to different buffer objects, the more common case (for static vertex attribute data at least) is to set the buffer object bindings for all enabled vertex attributes to the same buffer object and interleave the vertex attribute data. As far as the index list, it may be stored in the same buffer object which contains the vertex attribute arrays or a different one.

In terms of updating VAO state, vertex attribute buffer bindings are set with glVertexAttribPointer, and index list (aka element array) buffer bindings are set with glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ... ).

For more on all this, see the Vertex Specification page in the wiki.

Thank you for your answer :slight_smile: That clarified me a lot :smiley: