Jump to content
  • Advertisement
Sign in to follow this  
imnotbncre8ive

Drawing 2D textured quads: should use triangle lists or triangle strips?

This topic is 4141 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 coding a 2D graphics engine using DirectX 9.0c and C++. I am using vertex buffers to draw quads, and would ideally like to draw as many quads as possible in a certain DrawPrimitive call. I was wondering whether I should use Triangle Lists or Triangle Strips? If I use TriangleLists, I will need 3 vertices per triangle, making that 6 vertices per quad (2 redundant vertices). On the other hand, I am not sure how triangle strips are handled. I am thinking four would be for the first quad, and then what? Wouldn't the fifth vertex lead out from the previous two vertices, creating graphical artifacts? I am unsure how to work around it, even though it seems like a very simple problem.

Share this post


Link to post
Share on other sites
Advertisement
On the other hand, am I wrong in thinking that fewer DrawPrimitive calls are better? Should I just call DrawPrimitive once for each quad, instructing it to draw a TriangleStrip of four vertices? That seems like it would be a bad idea...

Share this post


Link to post
Share on other sites
As few DrawPrimitiveCalls as possible. If you batch, you're probably better off using triangle lists.

With triangle strips you need to make a call for every quad. Unless your quads reuse vertices (which means also reusing texture coordinates).

Share this post


Link to post
Share on other sites
Hmm, nevermind, I found the answer to my question. For anyone else who might be wondering, it is better to use TriangleStrips b/c D3D is optimized for this(?) and it does not anchor all the triangles to the first vertex like TriangleFans.

How do we draw multiple quads that are disconnected? For It takes four vertices to define our first quad (two triangles), using a TriangleStrip. Each next vertex will use the previous two vertices to form a new triangle. Now, our first triangle uses V0, V1, V2. Our second triangle uses V1, V2, V3. Together, these two triangles are textured and appear as whatever sprite we choose. Now, we add a fifth vertex V4 that has the exact same position as V3. This way, our third triangle will be formed by V2, V3, V4. Since V3 and V4's positions are identical, this third triangle will have zero-area (degenerate triangle), and will not be rendered by the device. Likewise, if we add a sixth vertex V5 (where we want to begin drawing our second textured quad), the fourth triangle formed will be V3, V4, and V5. Again, V3 == V4 so this sixth triangle is also zero-area and unrendered. We must create V6 to be same position as V5, so that our next two triangles (fifth and sixth triangles) are also degenerate. Now, we can finally begin adding V7, V8, and V9 to form our second textured quad. That was more work than I expected.

http://everything2.com/index.pl?node_id=1470544

How is that better than Triangle Lists? I'm not sure. In the context of drawing disconnected quads for a 2D game, the space-savings using Strips would be about two vertices.. regardless of the number of quads drawn. If we only draw one quad, we only need four vertices using Strips, whereas Lists would need 6. After that, we need 6 more vertices per quad for Strips (two vertices to make four degenerate triangles). It is also 6 more per quad for Lists. However, as mentioned in the link above: "it is also speed-efficient... when rendering a strip, if the previous two vertices are cached, then after the first triangle has been drawn, the next only requires one extra vertex calculation". I'm not sure how big a difference this would make.

And now I just noticed that Endurion left a reply, so I think I'll go with lists for now. Since I'm not rendering meshes, only seperated quads, I think the cost of calculating four degenerate triangles may be greater than simply using Lists. I guess now is a good time for me to learn to use Index Buffers too.

Share this post


Link to post
Share on other sites
I have always heard that triangle LISTS are better, and that's what I've been using in my 2D sprite engines... lists are indifferent to whether your sprites are disjoint (which they almost always are), and if you use an index buffer alongside you only need 4 vertices (6 indices). If your sprites are changing position every frame, be sure you're using a dynamic vertex buffer.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!