Sign in to follow this  
Stormherz

octree render optimization

Recommended Posts

Stormherz    100
I finished octree recursive render function, now it looks something like:
glBegin(GL_TRIANGLES);
  octree_rec_render(); // <- this is were immediate glVertex, glNormal called recursively for octree nodes
glEnd();

will it be faster if I collect just indices of the visible triangles in octree_rec_render(), and render afterwards? just like:
glBegin(GL_TRIANGLES);
  octree_rec_render(); // <- collect triangle indices in visible node
glEnd();

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, visible_vertices);
glDrawElements(GL_TRIANGLES, visible_triangle_num*3, GL_UNSIGNED_INT, visible_triangles);
glDisableClientState(GL_VERTEX_ARRAY);

Share this post


Link to post
Share on other sites
Lord_Evil    680
Most certainly, yes it will be more efficient. The reason is that immediate mode will result in more API calls than using vertex and index buffers.

Also, if the vertices are static you only transfer that data over the bus once and only transfer index data each frame (if necessary). With immediate mode you'd transfer all the vertex data every frame.

And btw, immediate mode is already deprecated in OpenGL 3.1 so you might want to drop that altogether.

Note though that the code you posted misses the normals array [smile].
Ans you should check if you can use unsigned short indices (i.e. 16-bit) for even better performance.

Another note: as with every algorithm/optimization you should profile first and compare the solutions. However in this case there's almost always a performance benefit.

Share this post


Link to post
Share on other sites
Stormherz    100
Quote:
Original post by Lord_Evil
Most certainly, yes it will be more efficient. The reason is that immediate mode will result in more API calls than using vertex and index buffers.

Also, if the vertices are static you only transfer that data over the bus once and only transfer index data each frame (if necessary). With immediate mode you'd transfer all the vertex data every frame.

And btw, immediate mode is already deprecated in OpenGL 3.1 so you might want to drop that altogether.

So as I thought, thank you.

Quote:

Note though that the code you posted misses the normals array [smile].
Ans you should check if you can use unsigned short indices (i.e. 16-bit) for even better performance.

Yeah, I was just simplifying the question, in the real code it is all there =)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this