By now we all know that rendering a few objects with many vertices is faster tahn rendering many objects with a few vertices each. But what about the primitive type? Using tristrips is certainly faster than using triangles, because if it wasn’t then there would be no reason to have such a thing like tristrips.
But how much faster? A few percent? Several times faster?
More concrete: If I am loading a mesh from, say, an Wavefront OBJ file it will have a number of vertices and a number of triangles. Or I am prodecurally creating a TIN terrain with several hundred or thousand trianlges. What I want to ask is if it is worth the effort to search or create an algorithm that tries to combine the single triangles into tristrips. Does anybody by chance already know such an algorithm?
Short answer: don’t bother. Triangle strips were invented for the benefit of graphics hardware that doesn’t have a vertex cache. This includes the original SGI graphics hardware, for instance; and I think it may also include the PS/2 graphics hardware.
However, a vertex cache in the graphics hardware achieves pretty much the same optimization that you would gain from using triangle strips, so any graphics card that uses a vertex cache can render independent triangles almost as fast as it can render triangle strips, especially if the triangles are sent in triangle strip order (that is, triangles with shared vertices should be sent consecutively whenever possible).
As it happens, pretty much any modern PC graphics card includes a vertex cache.
Still, according to NVidia, you can still potentially achieve a small benefit by using triangle strips (though I’ve never actually observed this), so for this reason Panda will automatically generate triangle strips when loading an egg file, when doing so will not otherwise interfere with the batching. (You have to be careful that you don’t increase the number of batches when you generate triangle strips. A big pile of independent triangles can always be sent in one batch, which is optimal. On the other hand, you have to be careful when designing your triangle strips to arrange them so they can be sent as a single batch.)
So, for the academic answer: if you are loading a mesh from an OBJ file, it’s probably best to convert it to egg format first. In fact, this is the way Panda loads any third-party format, even if you load it on-the-fly, and this is exactly why the egg format exists. If you go this route, then Panda will automatically put triangle strips where appropriate.
For real-time generated polygons, if it is easy to make triangle strips (for instance, if you are using a uniform triangulation, with several equal-length strips of triangles), then you might as well do so. But if it’s difficult, don’t bother.
Thank you very much for your answer, David. It helped me a lot in understanding what is going on inside my PC.
What I am doing is generating a TIN terrain using Delaunay triangulation, and creating tristrips on the fly seems to complicated for me, at least at the moment. When generating output my code creates a Panda NodePath and uses the write_bam_file interface.
But it is an offline-tool, so writing an EGG file and converting it later with egg2bam is possible. If I got you right then Panda will optimise this way, when appropriate.
Right. You can use the EggData, EggVertexPool, EggVertex, and EggPolygon classes to write an egg file instead of a bam file. I think there is sufficient documentation of this in the generated API docs, and a few examples here in the forums.