Sign in to follow this  

what would be the best way to render tiles in d3d for my game?

This topic is 4813 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 plan on developing a small 2d isometric game that will have a similar visual style similar to XCom. That is, theres going to be lots of tall walls around my tiles because the map will be in an urban environment. my question is about the best way to render the tiles in d3d9. Currently I just have one Quad vertex buffer that I render over and over again all over the screen in a loop, changing the position of the tile with a translation matrix before each drawprimitive. doing it this way Im getting about 150fps on a P4 1.8ghz with a geforce3 ti500, while rendering 300 tiles, and never even changing textures. So Im worried that once I start changing the textures and adding rendering even more things like walls and characters and objects, this might not be fast enough. The only other way I can see doing it is to load up all the tiles into a large vertex buffer, and then using only one call to Drawprimitive. The problem with this is that I plan on using very large maps and so it might be problematic to load the entire map into one vertex buffer. also, I'm not sure if this would really speed things up. So what would be the best approach in this sutuation?

Share this post


Link to post
Share on other sites
Well, you could at least create a vertex buffer big enough to hold the visible part of your map. Then setup that buffer with your currently visible tiles. This way you wouldn't need to translate one quad arround all the time.

Fill a memory buffer with all visible vertices and copy that to the vertex buffer. Maybe this kind of batching will speed up things a little.

Share this post


Link to post
Share on other sites
Ok, I've tried your suggestion. I used a large vertex buffer big enough to hold all the quads you could see on screen, then only used one call to drawprimitive.

It did improved speed, even when locking and editing the whole buffer every frame. It went from 244 fps to 250 when rendering about 300 tiles, and from 195 to 260 fps when rendering about 1000 tiles on the screen.

So I suppose I could lock and edit this vertex buffer every frame, and also use one texture for all the tile graphics, and just edit the texture coordinates of the tiles vertices to get the desired graphic?

I would like to hear how others have solved this issue. Am I missing anything here?


Share this post


Link to post
Share on other sites
Check your DirectX SDK Docs, you'll find an excellent guide on how to best render lots of small amounts of vertices using a dynamic vertex buffer: DirectX Graphics \ Programming Guide \ Programming Tips \ Performance Optimization

In addition to what you've already done, they suggest to lock the vertex buffer incrementally, eg. for the first frame use elements 0-8191, for the second frame 8192-16383 and so on until the end of the vertex buffer is reached.


For my own programs, I set up a cache for vertices which only locks and renders the vertex buffer each 4096 vertices as well as a cache for textures, which places small textures onto very large ones to reduce the number of texture switches and increase the number of vertices that can be rendered per DrawPrimitive() call. I've even started a small guide, including working example source code (in C#) which displays about 5.000 sprites at more then 600 fps on my system. If you want to check it out,

http://www.lunaticsystems.com/index.php?module=xlink&base=articles&id=direct2d

(the example code is linked at the end of that guide)

-Markus-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks Cygon, keep working on that guide, I'd like to read it when its finished.

Share this post


Link to post
Share on other sites

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

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