Real title: Best efficient way to render geometry mesh of 3,4,5+ vertices per faces?
Hi OpenGL community!
I’m working on a way to render geometry objects in the most efficient way (some are very big). I’ve found some ways.
I deal with VBOs (GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER)
Notice that geometry indices are stored “by face”. I need to go through each face to find his indices (like many 3d modeler actually).
glMultiDrawElements
The first one was using glMultiDrawElements. I made an array of indices (with repeated indices as it is stored by face) and a array of “cout” (4,4,4,4,3,5,4,4…etc).
But after some investigates, I had discover that using glMultiDrawElements was like to do a CPU loop of glDrawElements, which is most easy to write actually (is that true? glMultiDrawElements is not done in hardware?)
Example: http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=296001&page=1 and http://www.opengl.org/registry/specs/EXT/multi_draw_arrays.txt we can read:
It has the “same effect” as:
for(i=0; i<primcount; i++) {
if (*(count+i)>0) DrawElements(mode, *(count+i), type, *(indices+i));
}
By “same effect” this mean “in the GPU”? Or really in the CPU code execution? I don’t understand actually…
This seems logical as the array of index array is never put in the GPU but why create/use a glFunction to do what CPU can do easely? This is the point I don’t understand…
Three time render
So I’d start to draw my geometry in three time:
Three arrays (each containing indices of his type):
[ul][li] indexTriArray (3 indices each)[] indexQuadArray (4 indices each)[] indexPolyArray with his countPolyArray (indices are stored in countPolyArray)[/ul][/li]Then two glDrawElements and one glMultiDrawElements:
[ul][li] glDrawElements to render all GL_TRIANGLES (indexTriArray)[] glDrawElements to render all GL_QUAD (indexQuadArray)[] glMultiDrawElements to render the GL_POLYGONS (indexPolyArray and countPolyArray)[/ul][/li]Is this way is more efficient that the first one?
glPrimitiveRestartIndex
The last way seems to be glPrimitiveRestartIndex but I’m not sure this is adapted to in my specific case because I have very changing indices number per primitive.
What do you think?
Maybe I’ve missed something and there is a more efficient way to do that.
I’m sure anyone that know OpenGL enough already had to deal with that.
Any idea?
Thanks in advance and have a good day!