Triangle, check. Now I want to draw lots of 2D quads efficiently. How?

Started by
1 comment, last by Defend 15 years, 3 months ago
When creating a game with tile based 2D graphics, I know there's a particular way to define a strip of quads so that every 2 new vertices defines a new quad. Sounds efficient, but 1, I can't remember how to do this, and 2, saving vertices isn't the priority is it? So my question is, what is the recommended way to build my set of tiles for different 2D layers, with the fastest drawing time? I remember that reducing the number of calls to the rendering function is the way to keep it fast, so if I have 10 layers of background, is it possible to render these with only 10 DrawPrimitive() ? Cheers [Edited by - Defend on January 18, 2009 1:17:54 PM]
Advertisement
Assuming the number of tiles is small (hundreds, low thousands), then the number of vertices and quads would indeed matter less than the number of draw calls. The other thing that can slow you down is anything that changes in your geometry, but if your background layers are fixed for the level, then that won't be a problem. Also remember that you can stick all your static stuff in one vertex buffer, so less buffer switching this way.

I think that 10 calls should certainly work. You could potentially it even with less, but that could be tricky, and I'm not sure it's necessary. So just create a vertex buffer with the vertices of all your quads, and see how it works for you.
So (going off bad memory here), I could render in a way that reads 4 vertices as 1 quad, the next 2 vertices as another quad, the next 2 as another, and so on... until I have rendered an entire *row* of tiles. Then switch to the next row and render again in the same way.

OR

I could render in a way that reads the first 4 vertices as 1 quad, the next 4 vertices as the next quad, the next 4 as another, and so on... until I have rendered an entire *layer* of tiles.

The latter has double the amount of vertex points and isn't using any trick (TRIANGLELIST - is this the thing I'm talking about?) to economise on memory for the geometry, but has many times less calls to DrawPrimitive().

Does this sound like I'm going up the right alley? It's been years, and I remember that I used to use something like the first method I described.

This topic is closed to new replies.

Advertisement