Drawing many of the same model

Started by
10 comments, last by V-man 14 years, 5 months ago
I have a scene with a simple 3d model that is drawn hundreds of times, in different positions, orientations, and colors each time. What would be the best way to do this quickly? Right now I just have a for loop with:

glPushMatrix();
glTranslate();
glMultMatrix();
glColor();
glDrawArrays();
glPopMatrix();
And it isn't all that fast. Any thoughts / suggestions?
scottrick49
Advertisement
First idea: put the model in a VBO, loop (up to 30k instances)
Second: instancing. Needs shaders. (140,000 instances @ 60fps ^^)
Yeah I could use a VBO for the vertices, but I would still have to push, translate, mult, color and pop for every object though, wouldn't I?
scottrick49
Those are not really bottlenecks. If they were, you'd have long gone into pure GL3.2 with custom maths, buffers, instancing, modern shaders, etc.
Well, I'm working on an android device, so that really isn't an option.

Our scene renders quite nicely until we start drawing these extra objects. Just trying to get some ideas on ways to improve performance.
scottrick49
Should have mentioned "android device" first >_<. Just try to put them in VBOs, if the target devices support it. Or pre-bake all these objects into one larger object.
Quote:Original post by idinev
Should have mentioned "android device" first >_<. Just try to put them in VBOs, if the target devices support it. Or pre-bake all these objects into one larger object.


Wikipedia says Android supports GL ES 1.0 so there is no VBO which doesn't matter anyway. He can just use regular vertex arrays.

Maybe his Android device doesn't have a good GPU or maybe no GPU at all, just a optimized software rasterizer.
http://en.wikipedia.org/wiki/Android_(operating_system)
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
^^ I code for Android; there are VBOs on the devices that matter.
yeah that's what I've been noticing; multi-texturing works on the phone on my desk too.
scottrick49
You can use Geometry Instance... search for "GL_ARB_draw_instanced" into google.

Maybe you can find some information.

If you want multiples instance... with different transformation... the simpler is to use glMultMatrix...

each instance (reference) must have a WorldMatrix that will replace the original one. (Like this you avoid to update/create the world matrix at each render pass).
Use glLoadMatrix to load this initial matrix and for sub-elements... use glMultMatrix...

If you find a better solution... please share it ;-)
--------------------------------------------------------------------------------Aurora Studio - PureLight - Animation & rendering software and API.http://www.polarlights.net

This topic is closed to new replies.

Advertisement