I've been following a Computer Graphics course for a few weeks with an exam coming up, however I've gotten stuck on the topic of index buffers.
I know that a vertex buffer stores all vertices of a mesh. Now suppose we wish to make a cube. This means there are 8 vertices required to construct it. Each vertex is composed of 3 coordinates (x,y,z), thus the vertex buffer will be taking up 3 x 8 = 24 units of space.
I've read that index-buffers store the indices of vertices. So the indices of the vertices of our cube would be 1 to 8. This means 1 triangle takes up 3 units of space.
A question bothering me is: How many units of space would our index-buffer take?
I reason that a cube has 6 faces. Each face is composed of 2 triangles. This means there are 12 triangles, thus the index-buffer would take 3 x 12 = 36 units of space. (I used this site to reach this conclusion: https://msdn.microsoft.com/en-us/library/windows/desktop/bb147325(v=vs.85).aspx). However, my answer sheet claims it is 32.
Normally I wouldn't bother to post on StackOverflow and just ask my teacher, however he is currently on holiday and won't be back until after the exam. Thus, can anyone explain to me how the size of the index-buffer is regulated? (Assume it is the index-buffer used in OpenGL, if that matters).
However, this method applies if you are using GL_TRIANGLES
, i.e. where each triangle is specified independently of the next.
You can use GL_TRIANGLE_STRIP
and specify each face with 4 indices using 6 draw calls, but this gets you a size of 4 * 6 = 24. This is a wasteful use of draw calls, and 24 != 32. Plus, you'll have to use some index-buffer-offset draw call, which is just silly for drawing a cube.
You can use GL_TRIANGLE_STRIP
and the degenerate triangle strip method to reduce the number of indices you need even further.
But this is not 32. Bummer.
If you really wanted to pack that index buffer down, you could use 2 triangle fans (via GL_TRIANGLE_FAN
) and some fancy draw calls to get it down to 16 indices. Each fan starts on an opposing corner and wraps around its adjacent faces.
Alas, this does not equal 32, either.
So, where does this eldritch 32 come from?
GL_TRIANGLES
for 4 sides and GL_TRIANGLE_STRIP
for 2 sides was an intelligent thing to do.32 just does not make sense.