Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Let's assume I want to draw several separated (possibly textured) quads in Direct3D 9, each consisting of two triangles:

several quads

How should I draw these for maximum performance, i.e. which of the following ways is better in terms of speed?

  1. Describe each quad by 4 vertices, use D3DPT_TRIANGLESTRIP and call IDirect3DDevice9::DrawPrimitive for each individual quad, since they are not connected.
  2. Describe each quad by 6 vertices, use D3DPT_TRIANGLELIST and call IDirect3DDevice9::DrawPrimitive just once.

The first method uses less memory, while the second one requires only one draw call.

However, the second way seems to be feasible only if all the quads have the same texture, since otherwise a switch would be required.

share|improve this question
1  
Why not just try both and see what kind of performance you get? –  Vipar Aug 10 '13 at 12:38
    
I hoped that somebody could share his experience. If this isn't the case or if a general answer is not possible, I will do my own tests of course. It's just that every tutorial recommends to use D3DPT_TRIANGLESTRIP instead of D3DPT_TRIANGLELIST, but I don't know if this applies to the case of separated sprites as well. –  ph4nt0m Aug 10 '13 at 12:50
2  
On stackexchange sites it's usually expected that you try your approach and then report in if it doesn't work or doesn't work as you expected it to and need answers. These kind of questions are usually a "try and see" :) –  Vipar Aug 10 '13 at 12:55

1 Answer 1

up vote 1 down vote accepted

Option 2 should be quicker.

Ideally you'd want to combine it with an index buffer and DrawIndexedPrimitive(). That way you'll get one draw call, and only need 4 vertices. The index buffer can be created once on start-up since it'll be exactly the same regardless of what the vertex data is, you just need to tell D3D how much of it to use.

Once you add textures, you'll probably end up with one draw call for each different texture you're using. This can be optimized further with a texture atlas if you really need to do so.

However, unless the quads are tiny, the number of vertices won't have a significant impact on performance, because the per pixel cost will be far higher. For example if there's any transparency in the texture then adding extra polygons so you draw fewer completely transparent pixels will generally make it go faster.

Of course the more optimized it is, the more code you need to write, so don't go overboard optimizing unless you're having performance problems, and a profiler tells you what the causes are.

share|improve this answer
    
+1, That's exactly the kind of answer I hoped for. Your explanation is very clear and does really help me a lot. Thank you! –  ph4nt0m Aug 10 '13 at 22:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.