*/
+#ifndef GL_ES_VERSION_2_0
/* General functions for drawing geometry
* Solids are drawn by glDrawArrays if composed of triangles, or by
* glDrawElements if consisting of squares or pentagons that were
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
-static void fghDrawGeometrySolid(GLfloat *vertices, GLfloat *normals, GLubyte *vertIdxs, GLsizei numVertices, GLsizei numEdgePerFace)
+/**
+ * Draw the geometric shape with filled triangles
+ *
+ * - If the shape is naturally triangulated (numEdgePerFace==3), each
+ * vertex+normal pair is used only once, so no vertex indices.
+ *
+ * - If the shape was triangulated (DECOMPOSE_TO_TRIANGLE), some
+ * vertex+normal pairs are reused, so use vertex indices.
+ */
+static void fghDrawGeometrySolid(GLfloat *vertices, GLfloat *normals, GLubyte *vertIdxs,
+ GLsizei numVertices, GLsizei numVertIdxs)
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glNormalPointer(GL_FLOAT, 0, normals);
- if (numEdgePerFace==3)
+ if (vertIdxs == NULL)
glDrawArrays(GL_TRIANGLES, 0, numVertices);
else
- glDrawElements(GL_TRIANGLES, numVertices, GL_UNSIGNED_BYTE, vertIdxs);
+ glDrawElements(GL_TRIANGLES, numVertIdxs, GL_UNSIGNED_BYTE, vertIdxs);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
/* Shape decomposition to triangles
- * We'll use glDrawElements to draw all shapes that are not triangles, so
- * generate an index vector here, using the below sampling scheme.
+ * We'll use glDrawElements to draw all shapes that are not naturally
+ * composed of triangles, so generate an index vector here, using the
+ * below sampling scheme.
* Be careful to keep winding of all triangles counter-clockwise,
* assuming that input has correct winding...
*/
switch (numEdgePerFace)
{
case 3:
- /* nothing to do here, we'll drawn with glDrawArrays */
+ /* nothing to do here, we'll draw with glDrawArrays */
break;
case 4:
vertSamps = vert4Decomp;
/* Cache of input to glDrawArrays or glDrawElements
* In general, we build arrays with all vertices or normals.
* We cant compress this and use glDrawElements as all combinations of
- * vertex and normals are unique.
+ * vertices and normals are unique.
*/
#define DECLARE_SHAPE_CACHE(name,nameICaps,nameCaps)\
static GLboolean name##Cached = FALSE;\
0.0f, 0.0f,-1.0f
};
-/* Vertex indices */
+/* Vertex indices, as quads, before triangulation */
static GLubyte cube_vi[CUBE_VERT_PER_OBJ] =
{
0,1,2,3,
else\
{\
fghDrawGeometrySolid(name##_verts,name##_norms,vertIdxs,\
- nameCaps##_VERT_PER_OBJ_TRI, nameCaps##_NUM_EDGE_PER_FACE);\
+ nameCaps##_VERT_PER_OBJ, nameCaps##_VERT_PER_OBJ_TRI); \
}\
}
#define DECLARE_INTERNAL_DRAW(name,nameICaps,nameCaps) _DECLARE_INTERNAL_DRAW_DO_DECLARE(name,nameICaps,nameCaps,NULL)
vertices = cube_verts;
if (useWireMode)
- fghDrawGeometryWire (vertices,cube_norms, CUBE_NUM_FACES,CUBE_NUM_EDGE_PER_FACE);
+ fghDrawGeometryWire (vertices, cube_norms,
+ CUBE_NUM_FACES, CUBE_NUM_EDGE_PER_FACE);
else
- fghDrawGeometrySolid(vertices,cube_norms,cube_vertIdxs,CUBE_VERT_PER_OBJ_TRI, CUBE_NUM_EDGE_PER_FACE);
+ fghDrawGeometrySolid(vertices, cube_norms, cube_vertIdxs,
+ CUBE_VERT_PER_OBJ, CUBE_VERT_PER_OBJ_TRI);
if (dSize!=1.f)
/* cleanup allocated memory */
/* Draw and cleanup */
if (useWireMode)
- fghDrawGeometryWire (vertices,normals, numFace,TETRAHEDRON_NUM_EDGE_PER_FACE);
+ fghDrawGeometryWire (vertices,normals,numFace,TETRAHEDRON_NUM_EDGE_PER_FACE);
else
- fghDrawGeometrySolid(vertices,normals,NULL,numVert, TETRAHEDRON_NUM_EDGE_PER_FACE);
+ fghDrawGeometrySolid(vertices,normals,NULL,numVert,numVert);
free(vertices);
free(normals );
}
}
+#endif /* GL_ES_VERSION_2_0 */
/* -- INTERFACE FUNCTIONS ---------------------------------------------- */
+#ifndef EGL_VERSION_1_0
/*
* Draws a solid sphere
*/
free ( normal ) ;
glPopMatrix();
}
+#endif /* EGL_VERSION_1_0 */