# What does glMultiDraw* do?

I'm having trouble understanding exactly what glMultiDraw* does, and when it should be used.

Is it to be used if I have one VBO with multiple objects in it or do I use it with many VBO's?

It would be great if someone could give a real example of how to use this is a VAO/VBO as all the stuff I've found on google just explain what the function does rather that how to use it practically.

• I've done some minor editing to try to make the question clearer and easier for others to find in a search. If you disagree with the edit, please revert it. :) – Trevor Powell Sep 6 '14 at 0:35

As per the documentation for glMultiDrawArrays and its sister glMultiDrawElements, these functions behave exactly the same as their glDraw* counterparts, except that they can specify more than one object. This means you bind all the same objects and use all the same state as with a glDraw* command.

The practical upshot of this is that yes, you can have one VBO with multiple objects in it, and render all of them with one API call.

I will direct you to this page for a more thorough discussion.

See also pages 34 (3.3) and 349 (4.5) of the OpenGL standards.

• What do you mean by "bind all the same objects" you mean bind many (vertex)buffer objects? Because if that's the case then it's not possible. – Soapy Sep 5 '14 at 16:07
• No, glMultiDraw* commands both require a bound VAO and VBO (and index buffer for -Elements), just like their glDraw* counterparts. with glMultiDraw* commands you can pack multiple objects into one VBO and render them all at once. – Aidan Medcalf Sep 5 '14 at 16:09
• For example, let's say you have a cube, a triangle, and a sphere. With glDrawArrays you might create a VBO for each and have some loop where you bind the right VBO and issue the draw command. With glMultiDrawArrays you can shove them into one VBO and issue one command and the driver will happily do the rest of the magic for you. – Aidan Medcalf Sep 5 '14 at 16:18

Take this code:

for (int i = 0; i < numarrays; i++)
glDrawArrays (GL_TRIANGLE_FAN, arrayfirsts[i], arraycounts[i]);


Multi-draw allows this to be executed with a single draw call:

glMultiDrawArrays (GL_TRIANGLE_FAN, arrayfirsts, arraycounts, numarrays);


In theory this can give you better performance: by having only a single draw call, the driver need (again, in theory) only perform setup and validation once rather than once per draw call.

It's actually got nothing to do with VBOs explicitly, because it dates to GL 1.4; i.e before VBOs were added to OpenGL. Instead it provides you with a method of batching multiple draw calls to a single draw call, which is something that all GPU vendors recommend.

I made a point of emphasising "in theory" above, because in practice it's performance is going to depend on how the driver implements it. Some drivers may implement it entirely in software, and just treat it as a loop of individual glDrawArrays calls. Others may be able to take a faster path with it. OpenGL makes no promises either way.