# joining triangle strips with degenerate triangles

This topic is 4885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I know this has prob been posted before a million times, theres even an article on Game Dev explaining it, I've also read this thread: http://www.gamedev.net/community/forums/topic.asp?topic_id=342450 and yet I still can't get it to work, everything seems to say that you repeat the last vertex of your current row, and the first vertex of the next ones, hence for the test i'm trying to get working:
//   6      7      8
//     *----*----*
//     |    |    |
//   3 |    |4   |  5
//     *----*----*
//     |    |    |
//     |    |    |
//     *----*----*
//     0     1    2

should have an index buffer of 0,3,1,4,2,5, 5,5, 5,8,4,7,3,6 with 5,5 being the middle degenerate triangle, instead this code just draws the bottom two quads. any help would be great as I can't seem to find any other info on google

##### Share on other sites
The problem is that the winding order of the triangles on the top row is backwards. To fix it, start the row with 8-5-7 or 3-6-4 (or you can remove one of the 5's).

##### Share on other sites
This should work for a triangle strip using your vertex layout.

0, 3, 1, 4, 2, 5, 8, 7, 4, 3, 6

Triangles:
0 3 1
3 1 4
1 4 2
4 2 5
2 5 8 (degenerate)
5 8 7
8 7 4
7 4 3
4 3 6

You'll have 9 primitives(8 + 1 degenerate).

Your index list would cause a total of 4 degenerate triangles (2 5 5, 5 5 5, 5 5 5, 5 5 8). You'd have to tell DrawPrimitive that you have 12 primitives with your list to get the whole thing.

##### Share on other sites
Reltham, your triangle (2 5 8) is not degenerate unless all 3 vertices are colinear. It works well in 2D space though.

##### Share on other sites
I just want to mention that I have gone through the trouble of benchmarking this : strips do not produce any perfomance benefit compared to cache frendly triangle indices. (that is on any hw after the GF1, I have not benchmarked this for previous hw). They can even hurt performance, because long strips bring the current triangle far from the ones in post VS cache.
Then again, you might have another specific reason to want strips.

Here's something I noticed though : drivers usually store VB and IB in AGP memory since vertex throughtput is rarely the limit. You will therefore be AGP bound if you try to test vertex speed limits.
Janos

##### Share on other sites
Is the speed difference negligible, even for say large terrains? My terrain is currently made up of triangle strips with degenerate triangles, but I would prefer to use indexed triangle lists if possible, because strip generation code is a royal pain in the arse, and I think my terrain code would be a lot easier to understand and maintain, if it were made up of indexed triangles.

The design of my renderer isn't quite as efficient as it could be, and therefore I'm worried about doing anything that could possibly have an impact on the framerate. (Yes I will fix my renderer when I find time, but I'm currently unemployed, and the main focus of my demo at the moment is getting a programming job, and getting off the dole)

##### Share on other sites
Quote:
 Original post by JohnBoltonThe problem is that the winding order of the triangles on the top row is backwards. To fix it, start the row with 8-5-7 or 3-6-4 (or you can remove one of the 5's).

I'm still somewhat confused, I thought you might be suggesting that I was joining the strips correctly but i had to change the order in which I specified the vertices for the top row to:

0,3,1,4,2,5, 5,5, 8,5,7,4,6,3

but it didn't work, I'm sure I'm missing something totally obvious but I can't see it?

thanks to everyone whos tried to help me so far :)

Quote:
 Then again, you might have another specific reason to want strips.

I was just experimenting them with a mind to use them for drawing the heightmap in my demo, i have read in some places that tri lists can be faster but I just wanted to give it a go myself(I currently use tri lists)

edit - also how would I go about making sure my tri lists are cache friendly?

##### Share on other sites
Quote:
 Original post by StarcideI'm still somewhat confused, I thought you might be suggesting that I was joining the strips correctly but i had to change the order in which I specified the vertices for the top row to:

You're making the same mistake that I made the first time I tried to create a terrain with triangle strips. The triangles in one row are having their vertices specified in a clockwise order, whereas the triangles in the next row will have their vertices specified in an anti-clockwise order.

This will cause trouble when you turn on backface culling, half of your terrain triangles will disappear.

##### Share on other sites
->Oxyacetylene
The speed difference is not better with strips, not even by a percent.
You still need to run a cache preserving reordering of your triangles to optimize post VS cache usage.
If you are running a card later than a 9800Pro for example, you should be able to yield more than 25~30 Million triangles per second with a rather simple VShader.
If you are running at 10~12MTris/s and that triangle trhoughput is your bottleneck, the go ahead and optimize that.
If you yield significantly lower triangle throughputs, then VS and vertex cache are not your bottleneck, so you'll have to look elsewhere for memory thrashing, high batch count, video memory leaks, etc...

##### Share on other sites
Ooops, you are right my index list is wrong because I was only thinking in 2D.

However, all that is needed is an additional 5 in the list which will form two degenerate triangles that follow the edge properly.

Of course, as has been stated by others, a cache friendly ordered triangle list performs similarly to a strip, and is easier to work with. That is what I use in my engine (and it's also what D3DXMesh uses).

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634136
• Total Posts
3015757
×