Using the ARB_multi_draw_indirect command


Has anyone used the “ARB_multi_draw_indirect” command? Apparently it is supposed to make drawing much faster depending on the situation but I don’t know how to use it.

My drawing code is currently a loop where I bind each item I want to draw with a VAO, send my MVP/Normal Matrix via glUniformMatrix* functions, send a UBO object with my materials/colors, and then do my glDrawElements(*) function.

But apparently using ARB_multi_draw_indirect is much faster.

Anyone have an example of it’s use and how to use it correctly?

Thank you for your time.

The point of “indirect” is that the draw arguments come from a buffer object.

This is useful if your content is generated on the GPU, i.e. via transform feedback, or compute shaders.

A simple example is to move frustum culling to the GPU. For a world containing N objects:
a) draw N containers (spheres or AABB) with “culling shader”
b) culling shader tests containers against frustum and outputs either zero, or real number of vertices to draw for that object, into buffer
c) draw N objects, with vertex counts from the buffer (zero-vertex objects become no-op draws.)

More complex examples would be procedural object generation, or some screen space effects (bokeh bloom…) that create varying number of vertices.
The “indirect” draw allows the CPU to simply say “draw stuff, and then draw however many vertices that produces”, without any intervening synchronization between CPU and GPU.

If your draw arguments already come from the CPU, then draw indirect won’t help you at all.