PDA

View Full Version : glMultiDrawArrays​ vs glDrawArrays​



SaeedGH
11-01-2016, 07:19 PM
Hi,

I am trying to understand what is difference between multidraw and draw command?
According to this page, https://www.opengl.org/wiki/Vertex_Rendering#Multi-Draw, "Multi-draw is useful for circumstances where you know that you are going to draw a lot of separate primitives of the same kind that all use the same shader". So if we change the shader we need to do another draw command.

But what if we try to render 2 triangles that uses same shader? why can't we put all the vertices in a VBO and use glDrawArray rather than glMultiDrawArray?
Is it illegal to combine the 2 triangle vertices? if not, do we gain any performance by using Multidraw rather than the single draw?

Thanks,

GClements
11-01-2016, 08:03 PM
glMultiDrawArrays() allows you to draw multiple disjoint ranges rather than a single range.

This allows you to enable and disable portions of the geometry without having to either rebuild the attribute arrays or use multiple calls.

SaeedGH
11-01-2016, 08:59 PM
glMultiDrawArrays() allows you to draw multiple disjoint ranges rather than a single range.

This allows you to enable and disable portions of the geometry without having to either rebuild the attribute arrays or use multiple calls.

So if it is disjoint I cannot use a single draw command?
And what is performance drawback of using draw command. I mean if we want to bind different VBOs what happens in the hardware? do we need to fetch anything from CPU memory or ...?

Thanks

Silence
11-02-2016, 12:03 AM
You can, you just have to define your indices. See this (http://programming4.us/multimedia/8302.aspx) for example.

I'm not sure about what you want to ask for your second part. Binding has generally a non negligible cost. What you need to do will depend on your VBOs. Are there data static or do you stream them constantly ?

GClements
11-02-2016, 10:49 AM
So if it is disjoint I cannot use a single draw command?
glDrawArrays() uses a contiguous set of vertices. You can use an arbitrary set of vertices by using glDrawElements(). But if you want to change the set of vertices, you'd need to re-build the index array (which requires less work than changing the attribute arrays, but still more work than using glMultiDrawArrays() or glMultiDrawElements()).


And what is performance drawback of using draw command. I mean if we want to bind different VBOs what happens in the hardware?
Multiple draw commands are more expensive than a single draw command. Multiple draw commands with state changes between them are likely to be more expensive still. As to how much more expensive, you just have to measure it.