Sign in to follow this  
Keisni

How to optimize tile rendering

Recommended Posts

I am developping a 2D tile-based game with dx9 and get a headache. My map(1024*768) consists of many tiles. If I call drawprimitive for each tile to draw it directly to the backbuffer, a performance penalty will hurt me. So now i create a surface(1024*768) and set it as the render target and call DrawPrimitives to draw every tile to this surface and after this I can draw this surface to the backbuffer with only one drawprimitive. But this needs a lot of video memory. If this game is running on a computer with a graphic card of less than 64M, the surface can`t be created, and some strange effect will be met. So any of U have any suggestion for me. Thanks a lot!

Share this post


Link to post
Share on other sites
What you need to do is not "cache" your map like that, but instead group your terrain tiles into vertex buffers.

What you're doing now, doubtlessly, is drawing each tile with a single quad. What you need to do is create a vertex buffer that contains the entire visible scene (and probably even some of the scene outside the screen), and then draw the entire scene with a single call.

There's lots on this already in the forums; try searching on keywords like "vertex buffer", and you'll get information like sorting your renderings by texture (not position), etc.

Vertex buffers are usually best used for relatively static scene components, and work well, since the entire vertex buffer can be stored on the graphics card, instead of transported there every frame.

Share this post


Link to post
Share on other sites
Thank u for this inspiration. It`s great to have a vertex buffer to contain all the vertex data. But the problem is I use multiple textures to render the scene and how can I set textures and texture coords when drawing with a single buffer?

Share this post


Link to post
Share on other sites
No, was just in a foul mood from some programming issues of my own, and became additionally irked that he hadn't seemed to even consider using the forum search like I suggested.

My bad. This is hardly the place for that crap.

Share this post


Link to post
Share on other sites
Quote:
Original post by Keisni
I am developping a 2D tile-based game with dx9 and get a headache.
My map(1024*768) consists of many tiles. If I call drawprimitive for each tile to draw it directly to the backbuffer, a performance penalty will hurt me. So now i create a surface(1024*768) and set it as the render target and call DrawPrimitives to draw every tile to this surface and after this I can draw this surface to the backbuffer with only one drawprimitive. But this needs a lot of video memory. If this game is running on a computer with a graphic card of less than 64M, the surface can`t be created, and some strange effect will be met.
So any of U have any suggestion for me. Thanks a lot!


You don't call drawprimitive for every tile. That's bad style. Instead you create vertex buffer and all tiles put in one bigger vertex buffer. Then you need just one draw primitive call.
And texture question...in one bigger texture just put lot of smaller textures, and then just play with UV coordinates.

Share this post


Link to post
Share on other sites
Actually, when you're doing tiles and sprites, you can get away with working in immediate mode. You don't really have to worry about it unless your hardware is ancient, or you're drawing tens of thousands of sprites.

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