Rendering large meshes in OpenGl

Started by
3 comments, last by codingJoe 9 years, 7 months ago

Hello,

I am rendering large meshes in a very simple and straightforward way (i.e. using VBOs), but as soon as meshes start having more than 0.5 mio triangles, rendering gets slower and scene manipulation is not fluid anymore.

When I look at some other applications (i.e. visualization applications), they can handle the same imported meshes in a much faster and more fluid manner. So my question is: how do they do it?

I am not using any shaders, but the speed difference between my application and the others is too large that it could only be a matter of shaders. My code basically resumes to:


vertexBuffer->bind();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,0);

normalBuffer->bind();
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT,0,0);

glDrawArrays(GL_TRIANGLES,0,verticesCnt);

glDisableClientState(GL_NORMAL_ARRAY);
normalBuffer->release();

glDisableClientState(GL_VERTEX_ARRAY);
vertexBuffer->release();

Am I missing an important part of the puzzle?

Thanks

Advertisement

Some possibilities:

1.) Are the update rates of the vertex positions array and the normals array different? If not then put both into the same VBO and store them interleaved.

2.) Use an index buffer.

3.) Try invoking glVertexPointer as the last of all attribute set-ups. Even better, try to use a VAO if possible.

4.) Are the buffers allocated with GL_STATIC_DRAW (if applicable)?

Also note that you are not meant to do draw calls of just about any size (though in my opinion, half a million vertices should work perfectly fine on every card, that's certainly big but then again not that big), in particular when using an index buffer as suggested by haegarr, mind what the spec has to say about that:

Implementations denote recommended maximum amounts of vertex and index data, which may be queried by calling GetIntegerv with the symbolic constants MAX_ELEMENTS_VERTICES and MAX_ELEMENTS_INDICES. If end-start+1 is greater than the value of MAX_ELEMENTS_VERTICES, or if count is greater thanthe value of MAX_ELEMENTS_INDICES, then the call may operate at reduced performance.

Maybe the driver is reluctant to pushing such a big chunk of memory onto the card in one go (even if the card can most probably handle that, half a million vertices isn't that much!) and has to do a DMA transfer in the middle, or such a thing. Who knows...

Also depends on how big the object is on screen. If you render a million triangles that are drawing to 1/50th of the screen, tons of pixels will be drawn too and will incur very bad performance.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

In addition to everything mentioned above, there is no reason to glEnableClientState(GL_VERTEX_ARRAY); and glDisableClientState(GL_VERTEX_ARRAY);.

Vertices are always required in a draw call.

Enable it once and leave it enabled.

It also wastes time enabling and disabling GL_NORMAL_ARRAY needlessly between draw calls. That is, if you draw 2 objects in a row that both have GL_NORMAL_ARRAY enabled, don’t disable and re-enable it, just leave it enabled.

You should always reduce/eliminate redundant API calls.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Thank you for your good replies, you have been very helpful. I could already slightly increase the rendering speed!

This topic is closed to new replies.

Advertisement