Jump to content
  • Advertisement
Sign in to follow this  
Ed Welch

OpenGL reducing draw calls by batching

This topic is 583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got to the stage of my game where I have hundreds of small meshes in a scene, so I wrote a batching class to reduce the draw calls.

For each frame this class takes any mesh below a certain size in the current camera frustum, transforms the vertex data and joins them all together into one big mesh. The algorithm has to run each frame, because the camera frustum is changing each frame and stuff is moving around as well.

Reducing draw calls decreases the amount of work that the CPU has to do, increasing frame rate, but on the other hand transforming the vertex data each frame increases CPU load. So, there is an optimal level, which I found to be around 100 vertices fro mesh size. In other words, I only batch meshes that have less than 100 vertices and that gives optimal performance.

Is anyone doing something similiar to this? Any tips would be appreciated.

Unfortunately I have to use OpenGL ES 2.0. I know there's probably some cool function in 3.1 that makes this a lot easier, but I don't have access to that.

Edited by Ed Welch

Share this post


Link to post
Share on other sites
Advertisement

It's normal to use a zone manager for this, so only when a player enters the zone do you check the LODs and batches. Maybe look into Unity's batching and see how it works. There is a lot about Unity that I don't like but it does have one of the best batch managers that I have ever seen.

Share this post


Link to post
Share on other sites

It's normal to use a zone manager for this, so only when a player enters the zone do you check the LODs and batches. Maybe look into Unity's batching and see how it works. There is a lot about Unity that I don't like but it does have one of the best batch managers that I have ever seen.

Yeah, what I have implemented seems to be the same as Unity's "dynamic batching". I'm not sure what Unity "static batching" is though.

Well, that's good to know anyway. Thanks for the answer.

Edited by Ed Welch

Share this post


Link to post
Share on other sites

I don't know about opengl es 2.0 but see if it is capable of mergeinstancing.  That and are your models you're batching the same size? (# of triangles)

 

edit - not the exact same size but similar number of triangles... the closer they are to each other the more efficient merge instancing is.

Edited by Infinisearch

Share this post


Link to post
Share on other sites

 I'm not sure what Unity "static batching" is though.

 

Static batching is an offline (or load time) process that transforms the vertices of 3d object instances into world space and stores all vertices into a single vertex and index buffer, so you can draw multiple objects at different places with only one draw call. Of course that only makes sense if the objects can't move at all and can be drawn with the same material. It's pretty much as if you do instancing on the CPU and store all resulting vertex positions in a new vertex buffer. This can easily explode memory requirements though, because a single mesh instanced 100 times in a static batch takes 100 times the memory.

Share this post


Link to post
Share on other sites

You don't have to regenerate your vertex data as the camera moves around; only the index data has to dynamically respond to the culling results.

That's a very clever idea. Thanks, Hodgman!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!