Indexed GL_TRIANGLES vs. indexed GL_TRIANGLE_STRIP
Asked Answered
T

1

8

There has been quite a buzz about rendering performance between indexed triangles or triangle strips. But I believe there is a case that has not been considered enough.

Indexed triangles are rendered like this in OpenGl:

glDrawElements(GL_TRIANGLES, ...);

But for some reason a lot of people consider rendering strips only in this way:

glDrawArrays(GL_TRIANGLE_STRIP, ...);

Out there there are some very good indexers (Forsyth, Tipsify to name a few) that optimize your mesh to be convenient for the GPU transform cache to be rendered in GL_TRIANGLES mode. Ideally they can achieve like 0.5 rendered vertices per triangle or something like that.

But why not doing this?

glDrawElements(GL_TRIANGLE_STRIP, ...);

I mean, you combine the low index bandwidth of strip rendering with the efficient GPU transform cache usage that the above indexers provide. With few modifications, am I right in saying that a strip indexer that optimizes the strip to be also Tcache-friendly can be a good idea?

Probably it won't reach the 0.5 goal, but at least a 0.6 perhaps? Also, don't forget the massive index bandwidth gain (potentially one third against GL_TRIANGLES).

Twobit answered 5/11, 2013 at 12:17 Comment(3)
Index bandwidth is hardly an issue these days. You can store indices in a static VBO on the GPU for most use cases.You benefit from the post-T&L cache whether it is using primitive modes that share elements (e.g. Fans, Strips) or indices that allow explicit reuse of transformed vertices during primitive assembly. Triangle lists in strip-order are said to be just as efficient as strips on modern GPUs and do not require special primitive restart indices. Vertex transform has not been a bottleneck in most rendering situations for years, though with tessellation you may see renewed interest.Worshipful
@AndonM.Coleman I agree with you on the fact that if the index data is already in the GPU the two drawing modes are equally efficient. But it is definitely NOT the same if the vertex data is in a VBO but the index data is not. If for some reason the user is uploading a bunch of indices to the GPU very often (every frame perhaps) sending 2.5-3 times less indices does have an impact.Twobit
@Twobit Keeping vertex or index data not in VBO is just not wise. You depend on driver to calculate the amount of data to be paged in and forcing it to upload the whole data in most ineffective moment - in drawcall. Driver may also allocate new buffers for each draw which is really, really slow. Also not using VBOs kills indirect drawcalls, etc.Defy
D
-2

glDrawElements needs to pass data from CPU to GPU at the time of the call. Specifically, the last parameter is a pointer to that data.

glDrawArrays does not require passing data to the GPU at the time of the call. This is probably why glDrawElements is not usually considered when you are storing vertex/index data on the card.

Distance answered 22/7, 2014 at 21:22 Comment(5)
There are buffer objects for both cases, so that answer does not make sense.Expectation
The index data can (and typically is) also in a buffer. Anyway, this whole question is based on invalid assumptions, IMHO. Using glDrawElements() with indexed triangle strips is completely standard.Elderly
Yeah, and primitive restart is also very useful in such a scenario.Expectation
If the index data is in a buffer, what is the last argument to glDrawElements for?Distance
@Thomas. If an index buffer (GL_ELEMENT_ARRAY_BUFFER) is bound, the last argument to glDrawElements() is a relative offset (in bytes) into the buffer.Elderly

© 2022 - 2024 — McMap. All rights reserved.