X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffg_geometry.c;h=ccbe5d7e4d6bc54dc1c1c4e46e6d7d8dc26f35c8;hb=816262dfb4e1a332e54c715768798cf76ec1577e;hp=01e76fcef9c5097d9ff1d356df150cf5a50fafaa;hpb=fd08532c4c6d7673aa241238f0afca21ba3f8364;p=freeglut diff --git a/src/fg_geometry.c b/src/fg_geometry.c index 01e76fc..ccbe5d7 100644 --- a/src/fg_geometry.c +++ b/src/fg_geometry.c @@ -33,6 +33,7 @@ */ +#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 @@ -59,25 +60,36 @@ static void fghDrawGeometryWire(GLfloat *vertices, GLfloat *normals, GLsizei num 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... */ @@ -91,7 +103,7 @@ static void fghGenerateGeometryWithIndexArray(int numFaces, int numEdgePerFace, 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; @@ -144,7 +156,7 @@ static void fghGenerateGeometry(int numFaces, int numEdgePerFace, GLfloat *verti /* 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;\ @@ -198,7 +210,7 @@ static GLfloat cube_n[CUBE_NUM_FACES*3] = 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, @@ -639,7 +651,7 @@ static void fghCircleTable(GLfloat **sint, GLfloat **cost, const int n, const GL 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) @@ -676,9 +688,11 @@ static void fghCube( GLfloat dSize, GLboolean useWireMode ) 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 */ @@ -717,19 +731,21 @@ static void fghSierpinskiSponge ( int numLevels, double offset[3], GLfloat scale /* 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 */ @@ -1324,6 +1340,7 @@ void FGAPIENTRY glutSolidTorus( double dInnerRadius, double dOuterRadius, GLint free ( normal ) ; glPopMatrix(); } +#endif /* EGL_VERSION_1_0 */