Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does it make sense to include an index by using DrawIndexedPrimitives, when using linelists performance wise? I could imagine it would be easy for the GPU to generate such indexes anyway.

share|improve this question
I recommend trying it both ways for your data set and see which performs better. – Nate Apr 22 '11 at 4:40
@Nate it's suprising (well, not really) how much you learn with the old TIAS (try-it-and-see) method. – David Lively Apr 22 '11 at 13:44
up vote 4 down vote accepted

Indexing provides two major benefits:

  1. Speed. Vertices are only transformed once. If you have two connected lines (consisting of a total of three vertices), an indexed draw will only call the vertex shader three times. Without indexing, you'll pass in four vertices (even though two of them will have the same coordinates), and the vertex shader will be called four times. Multiple this by a few million primitives...

  2. Memory. In the above example, your vertex buffer will only have to hold three vertices, and your index buffer will have four indices. You're trading the space required to store one of the vertices for the index list. If you're using a large vertex type (VertexPositionNormalTexture, for instance), this makes sense.

If you use a 16-bit index buffer or non-trivial vertex types, your savings with indexing will most likely outweight the memory cost of the extra vertices (ie - a good thing).

Also, there is a small bit of GPU overhead with indexing, but it can be very small compared the running the vertex shader many more times than is necessary.


I thought of an example where you'd need to use non-indexed vertices. If you want to implement something like horizontal window blinds (picture for clarity), you may start with a model that has them closed (ie, all the blind surfaces are coplanar). To open them you'd apply different rotation matrices to each of the faces. Vertices that overlapped when closed would now be separate in world space. (When closed, the bottom edge of one slat will sit on top of the top edge of the next one down, and when open, they don't touch at all).

(Incidentally, that would be a perfect application of instancing [which can be thought of as yet another layer of indexing] if you had many sets of blinds.)

share|improve this answer
1. Vertices are only transformed once - It doesn't have to be always right. Your transformed (and lighted) vertices are stored in post T&L cache. If you have a lot of indeces (millions) and you use the same index at the begining and at the end of the batch, cache doesn't have to be big enough to store all transformed vertices. But in most cases, you will use the same index near to it's other usages. ..... And also - when he draws non-shared vertices (he draws linelist, not linestrip), all vertices will be transformed just once :) – zacharmarz Apr 22 '11 at 8:21
@zacharmarz if you pass in two copies of the "same" vertex, they each get processed separately by the vertex shader (the shader gets called once for each vertex in the buffer), which is necessary since the shader may return different results. This is useful when, say, exploding a face off of a solid. With indexed vertices, since each vertex appears only once in the buffer, it is only passed to the vertex shader once. – David Lively Apr 22 '11 at 12:46
I understand you. I'm just saying: If he has linelist (not linestrip), each line can have unique vertices. So indexed geometry can be useless and can even slow down drawing. If there is a lot of same vertices, indexed geometry is of course better. – zacharmarz Apr 22 '11 at 16:02
I think we're on the same page. – David Lively Apr 22 '11 at 16:13

If you draw a line where the end point of the first line is the start point of the second line then you can use LineStrip to 'automatically' get indices.

If you draw lines where vertices are never shared between lines then indices will get you no benefit at all (might even slow it down).

If some part of your vertices are shared then it can indeed be smart to use an index buffer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.