2D drawing in 3D - Batching drawing with untransformed coords w/ index buffer (C#)

Started by
8 comments, last by dhanji 19 years, 6 months ago
Hi all, A while back I followed a tutorial on 2D in Direct3D ( http://www.gamedev.net/reference/articles/article1972.asp ) Now, I got the basic method in this working just fine. The problem is I'm drawing something like 128 * 96 8x8 Quads every single frame (while in 1x zoom mode). My current method is horribly inefficient and just goes through, transforms for the current tile and then draws it (just the one tile by itself). Obviously this is slow as hell on anything but a freaking supercomputer. That same tutorial has a method of batching using a large vertex and index buffer but it only shows how to do it using transformed vertices. I'm not sure how I'd do the same with untransformed as I'm assuming doing the actual transformation to the world that I am currently doing will only apply at the time of drawing. So how would you draw a ton of same sized, side by side quads in a quick and efficient manner? Thanks
Advertisement
Bump.
I have to say I'm not feeling the love. For the record I'd really like to feel the love, so please share it.
How come you're using user primitives? Is there any particular reason you can't using hardware transforms?
Quote:Original post by Martaver
How come you're using user primitives? Is there any particular reason you can't using hardware transforms?


It's almost like you're speaking a foreign language. Could you elaborate good sir?
I'm not sure what you're exactly doing as the link to the tutorial doesn't work. Could you describe which functions you're actually using?
Tutorial

that link should work...
Am I asking just some really obscure crazy question here?? I would have thought this would be pretty basic.
Use DrawIndexedPrimitives instead of DrawUserPrimitives.
Allocate a vertexBuffer which is not type of Transformed...
Allocate an indexBuffer. Write your scene vertices and indices
once into the created buffers.
Set vertexbuffer and indexbuffer in the device.
Are the quads all changing every frame? If not, if its like a 128x96 (x8x8)map of tiled grass or something, why not render the tiles to larger quad(s) and use them as a starting point to render the units (or whatever) on top?
lets do some quick calculations:

128 * 8 = 1024
96 * 8 = 768

You can just create yourself a 1024x1024 texture at load time, render all your quads once to this texture, then use it as a starting point every frame (scaling it down vertically of course).
You could further optimize it by analyzing tiling boundaries. For instance if one quarter of this giant map is tiled (proly yes because 8x8 all tile) then you can store a 512x512 starting texture and render it 4 times, and this will probably be faster as most cards like smaller textures.
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)

This topic is closed to new replies.

Advertisement