Functionality of glDrawElementsInstancedBaseInstance for OpenGL (ES) 3

  Kiến thức lập trình

I am currently using VAO to draw two objects, using vertices and colors.
To draw multiple of these objects I added another buffer to each VAO to supply matrices for the transformation and use glDrawElementsInstanced.
This works fine so far.

Now I read that it is better to combine all objects into one VAO.
Then I could use the glDrawElements with the appropriate parameters to draw both objects once with one VAO binding and one or two draw calls.
Also fine.

When I want to draw multiple of both objects (using OpenGL 4) I could use glDrawElementsInstancedBaseInstance, then I could use again the buffer for transformations to supply the matrices. This should result in one VAO binding and two draw calls with again appropriate parameters.

But how do I implement this behaviour for OpenGL 3 or OpenGL ES 3?
a) I could update the buffer for the translation matrices for the first object, bind the VAO and run the instanced draw call for the first object. Then I could update the buffer for the translation matrices for the second object, bind the vao again(?) and run the instanced draw call for the second object.

b) Or I could use TBOs. So create two buffers for the transformations and bind them to one textures each. Then I would have to update the two buffers (binded to the textures), bind one VAO (for vertices and colors), bind the first texture and run the instanced draw call for the first object.
After that simply(?) bind the second texture and run the instanced draw call for the second object.

Of course the VS shader must be different for both solution.

Are there any advantages/disadvantages in solution a) or b)?
Or is there a better way of doing this instead of using glDrawElementsInstancedBaseInstance?

LEAVE A COMMENT