#Actualmhagain

Posted 07 June 2013 - 07:42 AM

One thing worth noting about indexed rendering. As well as saving memory from eliminating duplicate verts (not that important as memory is no longer a scarce resource for many use cases) and as well as saving VS transforms from being able to reuse the results of previous ones for duplicate verts (very important) indices also allow you to concatenate multiple primitives together to a single draw call.

Let's take that particle system example mentioned upthread. In the old days when you had the GL_QUADS primitive type this wasn't a big deal; with GL_QUADS deprecated in recent GL_VERSIONs (or not present at all in ES) a particle system may be exactly where you need indices the most. Represent each particle as a tristrip, and use indices to join them all in a single GL_TRIANGLES call, and you can get much greater efficiency than using degenerate triangles (an index will always be smaller than a vertex, and the 6 indices needed to join strips this way are much smaller than the extra verts needed).

Of course, there are other solutions available to this problem too (e.g. point sprites, instancing, geometry shaders, primitive restart) but they're not always available (particularly if we're thinking ES) and each has their own particular quirks. Using indices is the most robust general-case solution.

With specific relevance to meshes, one case where indices helps is with a mesh composed of multiple strips and fans. Indices are a great way of joining all those strips and fans together and being able to handle the entire mesh in a single draw call; you may not get much vertex reuse, and you may get extra memory usage, but that single draw call versus 10s, 100s or even 1000s of draw calls should more than offset things and give you faster overall performance on balance.

As always - profile and determine which is best for your own use case, but be aware that there is more to indices than just saving memory or reusing duplicate verts - even if neither of those two apply, you may still gain advantages from them.

#1mhagain

Posted 07 June 2013 - 07:41 AM

One thing worth noting about indexed rendering. As well as saving memory from eliminating duplicate verts (not that important as memory is no longer a scarce resource for many use cases) and as well as saving VS transforms from being able to reuse the results of previous ones for duplicate verts (very important) indices also allow you to concatenate multiple primitives together to a single draw call.

In the old days when you had the GL_QUADS primitive type this wasn't a big deal; with GL_QUADS deprecated in recent GL_VERSIONs (or not present at all in ES) a particle system may be exactly where you need indices the most. Represent each particle as a tristrip, and use indices to join them all in a single GL_TRIANGLES call, and you can get much greater efficiency than using degenerate triangles (an index will always be smaller than a vertex, and the 6 indices needed to join strips this way are much smaller than the extra verts needed).

Of course, there are other solutions available to this problem too (e.g. point sprites, instancing, geometry shaders, primitive restart) but they're not always available (particularly if we're thinking ES) and each has their own particular quirks. Using indices is the most robust general-case solution.

With specific relevance to meshes, one case where indices helps is with a mesh composed of multiple strips and fans. Indices are a great way of joining all those strips and fans together and being able to handle the entire mesh in a single draw call; you may not get much vertex reuse, and you may get extra memory usage, but that single draw call versus 10s, 100s or even 1000s of draw calls should more than offset things and give you faster overall performance on balance.

As always - profile and determine which is best for your own use case, but be aware that there is more to indices than just saving memory or reusing duplicate verts - even if neither of those two apply, you may still gain advantages from them.