0

I have multiple objects, each one of them has its own index buffer, vertex buffer, some have a different shader or texture, and all of them have the same vertex format (x, y, z, u, v, nx, ny, nz). I don't want to batch my objects together, but render them in separate draw calls. Lets say that I want to render 5 different objects (cubes, spheres, etc.), do I have to create a new vao for each one of them, or is there a way to tell OpenGL that I want to render 5 different buffers with the same layout/format?

Dave F.
  • 145
  • 6

1 Answers1

1

You don't need to tell OpenGL this; you simply modify the VAO and change the buffers without changing the vertex format.

Now granted, you can't do that without providing the vertex format parameters to glVertexAttribPointer. So at the very least, you have to remember what those parameters still are.

Fortunately, separate attribute format exists (in GL 4.3+), which allows you to change the buffer bindings (which are still stored in a VAO) separately from the functions that change the vertex format. So you should just be able to call glBindVertexBuffer and glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ...) to change the buffers.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Just to know I understand what do you mean, I need to generate 1 VAO, n buffers, bind the VAO once and then before I render each object, I bind its buffer and link it to that bound VAO via glVertexAttribPointer(). So, if I render 5 objects, I call glVertexAttribPointer() 5 times. Is that what you've meant? – Dave F. Jan 09 '22 at 14:33