Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Batch rendering

This topic is 5887 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

This is a general question about batches. As stated in several performance documentations you should render your primitives in batches of about 200 triangles. Now, does that mean that using strips is a bad thing? I don''t know what the average strip length of a general mesh is, but I would guess that it''s about 5-6 triangles or even less. Of course, it''s possible to stitch together several strips with "invisible" triangles. But is that something people normally do? As I see it, most people only draw triangle-lists with an index buffer instead, ignoring strips all together. Does anyone have any thoughts on this? (Just ignore me if you think this is just incoherent silliness ;-) / greldik

Share this post

Link to post
Share on other sites
I use index and vertex buffers to render up to the "optimal" number of triangles from multiple meshes that share the same texture. The basic idea is:

1. Find all of the objects which share the same texture data.
2. Enumerate through them adding their indices and vertices to the appropriate buffers until we reach the optimal limit for rendering.
3. Render
4. Go back to 2 if we have more objects with this texture to render, go to 1 for the next texture.

This seems to work well and is very quick. My only issue is that it works fine for static (non-moving objects) with their vertices defined in world coordinates, but I''m not sure how to apply it to moving objects. I guess I''ll have to translate all of the vertices from local in to world coordinates as I add them to the buffers. This seems like it''s going to be slow, though.

Also, currently the buffers aren''t caches. I don''t know if it is possible/desirable to cache them as long as nothing is moving in or out of view (i.e. nothing new to render and nothing to stop rendering).


Share this post

Link to post
Share on other sites
If your strips are coming out as 5-6 polys each, then an indexed list is much better.

However, do be aware that there are 2 things you can do to extend the length and increase the efficiency of the strips you can get:

1) Use degenerate (0 area, 2 vertices the same) triangles to change direction and turn corners. These are apparently often free or nearly free in hardware. This is very commonly done!.

2) Use indexed triangle strips.

But at the end of the day, the thing about maintaining at least 100->200+ where possible per Draw*Primitive is valid. 1 call with 100 is better than 10 calls with 10.

Simon O''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites
I think I was a bit unclear about my question. What I was
getting at was "triangle strips" versus "triangle batches".
Those two concepts seems to be mutually exclusive. Because no
strip is as long as 200 triangles in general.

But perhaps the strip concept is an old one. Nowdays, with
the index buffers, it''s perhaps faster to draw indexed triangle
lists instead of triangle strips?

Anyway...Your approach is interesting. Dynamic objects are always difficult to deal with.

But in your case, isn''t it easier to just render one object at a time? Dynamic objects tends to be pretty complex. So one object is probably enough to fill up to the "optimal render limit"?

Share this post

Link to post
Share on other sites
I think 5-6 triangles in a strip per DrawPrimitive call is pushing it. Never the less DO run some tests. For my terrain rendering engine which used brute force, I had 16x16 patches, each patch using 1 texture. I tried drawing the whole patch (which would be 16*16*2=512 triangles) with one DrawIndexedPrimitive(). This worked fine.
Then I tried drawing it with 16 calls to DrawPrimitive(), and with each drawing one horizontal triangle strip (32 triangles). Surprisingly this was way way faster (at least 3-4 times)

So I guess sometimes you need to run some tests to workout the optimial setup for your particular situation. This is where writing a robust rendering system becomes very important. With a well written rendering pipeline (which is something I really want to figure out), you can change your batchings easily and with minimal code change and wouldn''t need to change your code all over the place.

Hope that helps

Share this post

Link to post
Share on other sites

5-6 triangles is just a guess. Anyway, it''s very unlikely to get
an average strip length of 200 triangles.
But as you say, it''s probably faster to use indexed triangle lists instead in that case....

Share this post

Link to post
Share on other sites
RE: Poya

yeah...actually I havn''t written any code yet. I''m just hanging
around here until I have the perfect solution for a "well
written rendering pipeline" as you put it. ;-)

The perfect solution is probably to use all methods in the same
pipeline, and then choose the most optimal method depending on
the object. Instead of trying to find a general solution for
(forgive me if I''m just pointing out the obvious)

Share this post

Link to post
Share on other sites

  • 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!