Jump to content
  • Advertisement
Sign in to follow this  
Keisni

How to optimize tile rendering

This topic is 4109 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 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
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.

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
You set texture coords in the vertices, like normal.

You have one vertex buffer per texture.

Any non-trivial questions?

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
You can do 20k DrawPrimitives per second (depending on the *CPU*). Thats pretty much. Dont worry about it.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!