What's faster : 1 quad or 2 triangles ???

Hi !

On geforce 2&3 boards, suppose I’ve got 4 vertices A, B, C, D, lying on the same plane. What’s faster to render : the quad ABCD or the two triangles ABC and ACD ? And is the same true about quad strips and triangle strips ?

Thanks in advance !
Morglum

it depends.

anyway, if you do the same way for triangle and quad, quad would be better i think.

but it exists strip and fan which are special ways to avoid redundant vertices.
So drawing strip/fan triangles would be better than drawing simple quad… you can do strip for quad.
Your quads must be convexe quads.
Triangles are most used than quads (which grow up then).

So, do strip with quad would be same way as doing strip with triangles.
Care, too, of the number of vertices. If your quads models’s got more vertices, it may be less powerful.

Thanks jide ! I’m writing an ASE loader and all quads are converted into triangles in the ASE file. So I wondered whether it would be worth writing some code to detect when two tris are part of one convex quad, and then convert these two tris into one quad.

also bear in mind that by treating all poly’s as triangles you can draw all of them in one go (say vertex arrays) without having to deal with seperate polygon types which will save you a lot of time…

Yes, it’s true, but I planned to split my original vertex array into strips and fans. So I would have many vertex arrays anyway. I hope to improve rendering speed by this, but I might be mistaken… what do you think ?

from Rob The Bloke:
also bear in mind that by treating all poly’s as triangles you can draw all of them in one go (say vertex arrays) without having to deal with seperate polygon types which will save you a lot of time…

i think sometime, quads must be converted into triangles. But you can do as well vertex arrays with triangles, or quads by using glDraw*(); The first parameter is the parameter you give generally to glBegin();

As far, i got an Ase loader (i’ve taken it from an existed program), and i failed on loading all the objects. It only load the bigger object and the last (so i have strange things). I think it’s due to that i didn’t separate the different objects. That make me tired to think again about it. So, i may use another opened, free ASE loader (when i’ll find it).

I can give you mine, if you don’t find anything better, although it’s not finished and it handles memory very unefficiently.

Morglum

Hi !

I think most OpenGL implementation breaks down the quad to two triangles anyway in the end so you would not gain much from it compared to a two triangle strip for example.

Compared to GL_TRIANGLES you would have two less vertices to send down the pipeline which might be worth the trouble.

Mikael

morglum,
let’s see, why not !

mickael, that’s may be possible. Most of graphic cards only do triangles that are most sure to draw than quads which maybe difficult to delimitate, and fill. Then, that’s what i think !

I already pointed this out in another thread not so long ago, but I’ll repeat it here: I would advise against using quads.

Even if sending a quad is faster than sending two triangles (which I’ll believe when I see it), you can get a similar effect by using triangle strips.

By sticking with triangles, you also avoid a lot of potential problems down the road. You may encounter models with concave quads in them, for example, or you may get Z-fighting when doing multipass because the quad’s triangulation changes for some reason.

– Tom

Originally posted by Tom Nuydens:
I would advise against using quads.

Well, the reasons you give are all pretty sound, but I would finish your statement with “unless you have a very good reason”. In some of the stuff I am working on right now, a large portion of my scene consists of quads (always perfectly flat), but a majority of it is not strippable (either as quads or tris) or results only in several relatively small strips. Given the chioce of 1 big quad list, 1 bigger tri list (50% more verts sent), or many small tri stips (roughly the same # of verts as quad list, but split over many more draw calls), the quad list ends up being the best performance.

However, on this same topic, it was you Tom that helped me out with just such a problem with quad triangulation almost a year ago (http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/002716.html). So your advice/warnings do make sense to me.

Ok, thank you for your advices ! I think that i’ll stick to triangles, following mikael and tom. But this leads to another question : My vertex arrays are already very small (say, 10 triangles each), and they are not convertible into strips. However, I could split them into smaller strippable arrays. Is it worth it ?

Use quads when if each quad doesn’t share any verts with the next, e.g. for billboarded particles. This is more efficient; 4 verts per quad instead of 6. In any context where you can use stripping or fanning, stick to triangles.

Originally posted by Morglum:
Yes, it’s true, but I planned to split my original vertex array into strips and fans. So I would have many vertex arrays anyway. I hope to improve rendering speed by this, but I might be mistaken… what do you think ?

I think you’re getting confused. You can render any number of strips and/or fans from one vertex array, and if the strips or fans border on each other (sharing vertices) you’ll probably be wasting memory & bandwidth if you don’t do this.

HTH
Mike

If you have a flat quad ABCD, then it’s the same as two triangles ABD and DBC. And if you put them in a triangle strip, then you’ll have exactly the same number of vertices to send: 4, and not 6.
Note that if your quad vertices are in the order A,B,C,D counter-clockwise, then the equivalent triangle strip needs to be given vertices in the order A,B,D,C.
I remember one guy from nVIDIA (was it Matt ?) telling us that in the end all was splitted down into triangles anyway, so I would suggest using triangle strips in this case.

I think it’s faster drawing one quad instead of a triangle strip.
If there would be no advantages to use quads instead of triangles, they would not support them I think.
Now, the question I would like someone to answer is : How to build a quad fan?

Rendering a quad is not necessarily faster, but is never slower. Most of OpenGL implementations (&graphics hardware) simply tesselate quads to two triangles. This has the advantage that you pass only 4 vertices to the GL instead of 6, which you would do if you rendered two triangles instead. With this you can spare data transfer through the AGP bus, which can lead to performance gain in case of complex geometry.

There is no possibility to explicitly define a quad strip in GL, but there is no need of that. When you pass a triangle fan(or strip) to the GL you define each vertex only once, which is optimal.

kistompika

LordKronos, you say that your geometry consists mostly of unstrippable flat surfaces – I can relate to that.

However, you should be optimizing your data for the vertex cache anyway. Hence, using a quad will result in four vertices being transformed, whereas using triangles will result in four vertices being transformed and another two being pulled from the cache. In this case, I would expect the performance difference to be rather small? Unless of course it’s the bandwidth required for transferring the extra indices that makes the difference.

Mind you, I’m not saying that quads aren’t faster than triangles, because I honestly wouldn’t know – I’ve never tried! Can you perhaps post some benchmark figures illustrating the speed difference you see between quads and triangles in your app?

– Tom

Originally posted by MikeC:

I think you’re getting confused. You can render any number of strips and/or fans from one vertex array, and if the strips or fans border on each other (sharing vertices) you’ll probably be wasting memory & bandwidth if you don’t do this.

Yes, of course you’re right. So I would only have more than one call to glDrawElements. But there remains my question : does it make sense to build strips having 3 triangles each ?

Yes, in most case, quad is faster than two alone triangles : it’s becauss the pipeline transform 4 vertices, not 6. In other words, for a quad ABCD, first the ABC vertices are transformed, flagged and lit, then is drawen a ABC triangle, and next, only D is send to the pipeline, so you have only 4 T&L operation. If you do that with 2 triangles (ABC and BCD), you’ll have 6 T&L operations : that’s why it’s slower. But if you do that with a tristrip, perf migh been similar than drawing a quad.

Gaby

Originally posted by gaby:
Yes, in most case, quad is faster than two alone triangles : it’s becauss the pipeline transform 4 vertices, not 6.

Originally posted by kistompika:
This has the advantage that you pass only 4 vertices to the GL instead of 6, which you would do if you rendered two triangles instead.

I agree with both of you: using GL_TRIANGLES should be slower than GL_QUADS if you are trying to draw a quad.

But am I the only one seeing that rendering a quad using GL_TRIANGLES is DAMN STUPID ???

If you use GL_TRIANGLE_STRIP instead, you draw triangles and you still send only 4 vertices… and that’s probably what your gfx card does anyway !

Regards.

Eric