PDA

View Full Version : Is it possible to batch draw calls across VBOs?



Unphased
03-03-2012, 12:01 AM
It is convenient to create a 1-to-1 correspondence between VBO's and rigid objects within the system I have: When an object is created, I initialize its very own VBO (or VBO/IBO pair) to store the geometry needed for rendering it, which will be static. When the object is destroyed or no longer needed, cleanup is simply a matter of deleting the associated buffers.

This is in contrast to representing my geometric data for multiple objects across a single VBO: cleanup for a removed object will be very troublesome.

The reason why I might prefer putting multiple geometries into one VBO is that I can draw everything in a VBO using a single draw call.

Consider the situation in a 2D game engine where there are very many non-identical small objects which are free to move around. I'd like to avoid the overhead of changing the bound VBO for every single object while rendering them.

Is there any mechanism in place to address this "issue"? I'm looking for something like a glMultiDraw but allowing me to specify on which buffers to draw my primitives from.

What do you suggest I do to deal with this? The best solution I have thought of so far is to treat my big meshes separately from my small meshes: The small ones I can transform on the CPU each frame, and assemble a STREAM_DRAW VBO that has all of them. For my larger meshes I manage a VBO for each. After all, I'm just trying to *limit* the number of state changing gl calls rather than minimize them.

The proper way of course is to transform in the vertex shader. I could use a uniform array filled with transformation matrices, and use a vertex attribute indicate which transformation to apply. I'd still want to re-assemble the VBO if I am modifying it, though.

I just think that it could be beneficial in some situations to have a feature that allows drawing from multiple buffers, and I'm wondering if something like that will show up in later versions.

V-man
03-03-2012, 05:48 AM
Putting multiple meshes in the same VBO is not a new concept.
If you are planning to not render some of those meshes, then you have a few options :
-Modify the VBO to get rid of the objects you no longer will be drawing from.
-Do not call glDraw for that object in question and leave the VBO as is.
-Make the object invisible by either using blending or using the ALPHA test function.
-Change the transform matrix of the object so that it no longers gets rendered on screen. Perhaps move the object to the far left using your vertex shader. The advantage of this one is that there won't be any fragments generated. The fragment shaders will be free from doing unecessary work.


I just think that it could be beneficial in some situations to have a feature that allows drawing from multiple buffers, and I'm wondering if something like that will show up in later versions.
I don't know if it will but most of the time, there is already an alternate solution such as the ones I gave above.