How to optimize tile rendering

Started by
7 comments, last by Gagyi 17 years ago
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!
Advertisement
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.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
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?
You set texture coords in the vertices, like normal.

You have one vertex buffer per texture.

Any non-trivial questions?
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Quote:Any non-trivial questions?


What are you, twelve? Grow up.
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.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
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.
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.
You can do 20k DrawPrimitives per second (depending on the *CPU*). Thats pretty much. Dont worry about it.
-----------------------------------"After you finish the first 90% of a project, you have to finish the other 90%." - Michael Abrashstickman.hu <=my game (please tell me your opinion about it)

This topic is closed to new replies.

Advertisement