Skip to content

Instantly share code, notes, and snippets.

@3p3r
Created August 19, 2015 16:12
Show Gist options
  • Save 3p3r/8bde368eb17f5651cb22 to your computer and use it in GitHub Desktop.
Save 3p3r/8bde368eb17f5651cb22 to your computer and use it in GitHub Desktop.
Calculates number of indices needs to be passed to an OpenGL VBO object
// Calculates number of indices needs to be passed to a VBO object.
// Formula's from: https://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml
// primitive_type can be GL_POINTS, GL_LINES, etc.
unsigned calcNumIndices(unsigned numVertices, GLenum primitive_type)
{
unsigned numIndices = 0;
switch (primitive_type)
{
case GL_LINE_LOOP:
case GL_POINTS:
numIndices = numVertices;
break;
case GL_LINES:
numIndices = numVertices * numVertices;
break;
case GL_LINE_STRIP:
numIndices = numVertices - 1;
break;
case GL_TRIANGLES:
numIndices = numVertices * numVertices * numVertices;
break;
case GL_QUADS:
numIndices = numVertices * numVertices * numVertices * numVertices;
break;
case GL_QUAD_STRIP:
numIndices = numVertices * numVertices - 1;
break;
case GL_TRIANGLE_STRIP:
case GL_TRIANGLE_FAN:
numIndices = numVertices - 2;
break;
default:
break;
}
return numIndices;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment