PDA

View Full Version : glMultiDrawElements

holyll
01-16-2013, 01:21 AM
Hi everyone,
I just want to ask something about drawing a lot of geometry efficiently.
I read that it would be better to use glMultiDrawElements, however I really don't understand how.
Let's assume we have different objects (3 for instance) , each of them is bound to a VAO.
1/How can we draw all of them at one, or what is the best way to draw them all without having any overload.
Usually we do this :
Bind VAO
glDrawElements
Unbind VAO (or delete it).
But in this case how do we do ?
2/What do **indices stand for ( in this example is it an array of NULL) ??? ( I assume that I don't need any offset in the indices):confused:

I recal : l glMultiDrawElements( GLenum mode,const GLsizei * count,GLenum type,const GLvoid ** indices,GLsizei primcount);

Godlike
01-16-2013, 02:55 AM
I think the rationale behind glMultiDraw is the following. If someone disagrees please correct me

Imagine that you have a single VAO that contains:
- a big VBO with the geometry of your 3 objects and
- a big index VBO with the indices like this: indices-of-object-0, indices-of-object-1, indices-of-object-2.

To draw them with glDrawElements you can do something like this:

bind VAO
glDrawElements(GL_TRIANGLES, object_0_indices_count, GL_UNSIGNED_SHORT, NULL);
glDrawElements(GL_TRIANGLES, object_1_indices_count, GL_UNSIGNED_SHORT, object_0_indices_count * sizeof(GLushort));
glDrawElements(GL_TRIANGLES, object_2_indices_count, GL_UNSIGNED_SHORT, (object_0_indices_count + object_1_indices_count) * sizeof(GLushort));

Now let's assume that in your current frame you see 2 out of 3 objects (1st and 3rd). In that case you can use glMultiDrawElements.

GLsizei count[] = {object_0_indices_count, object_2_indices_count};
GLvoid* indices[] = {NULL, (object_0_indices_count + object_1_indices_count) * sizeof(GLushort)};
glMultiDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, indices, 2);

holyll
01-16-2013, 03:15 AM