tess.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
  3. * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice including the dates of first publication and
  13. * either this permission notice or a reference to
  14. * http://oss.sgi.com/projects/FreeB/
  15. * shall be included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  22. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. *
  25. * Except as contained in this notice, the name of Silicon Graphics, Inc.
  26. * shall not be used in advertising or otherwise to promote the sale, use or
  27. * other dealings in this Software without prior written authorization from
  28. * Silicon Graphics, Inc.
  29. */
  30. /*
  31. ** Author: Eric Veach, July 1994.
  32. **
  33. */
  34. #ifndef __tess_h_
  35. #define __tess_h_
  36. #include "../prboom/SDL_opengl.h" // JDC
  37. // JDC #include <GL/glu.h>
  38. #include <setjmp.h>
  39. #include "mesh.h"
  40. #include "dict.h"
  41. #include "priorityq.h"
  42. /* The begin/end calls must be properly nested. We keep track of
  43. * the current state to enforce the ordering.
  44. */
  45. enum TessState { T_DORMANT, T_IN_POLYGON, T_IN_CONTOUR };
  46. /* We cache vertex data for single-contour polygons so that we can
  47. * try a quick-and-dirty decomposition first.
  48. */
  49. #define TESS_MAX_CACHE 100
  50. typedef struct CachedVertex {
  51. GLdouble coords[3];
  52. void *data;
  53. } CachedVertex;
  54. struct GLUtesselator {
  55. /*** state needed for collecting the input data ***/
  56. enum TessState state; /* what begin/end calls have we seen? */
  57. GLUhalfEdge *lastEdge; /* lastEdge->Org is the most recent vertex */
  58. GLUmesh *mesh; /* stores the input contours, and eventually
  59. the tessellation itself */
  60. void (GLAPIENTRY *callError)( GLenum errnum );
  61. /*** state needed for projecting onto the sweep plane ***/
  62. GLdouble normal[3]; /* user-specified normal (if provided) */
  63. GLdouble sUnit[3]; /* unit vector in s-direction (debugging) */
  64. GLdouble tUnit[3]; /* unit vector in t-direction (debugging) */
  65. /*** state needed for the line sweep ***/
  66. GLdouble relTolerance; /* tolerance for merging features */
  67. GLenum windingRule; /* rule for determining polygon interior */
  68. GLboolean fatalError; /* fatal error: needed combine callback */
  69. Dict *dict; /* edge dictionary for sweep line */
  70. PriorityQ *pq; /* priority queue of vertex events */
  71. GLUvertex *event; /* current sweep event being processed */
  72. void (GLAPIENTRY *callCombine)( GLdouble coords[3], void *data[4],
  73. GLfloat weight[4], void **outData );
  74. /*** state needed for rendering callbacks (see render.c) ***/
  75. GLboolean flagBoundary; /* mark boundary edges (use EdgeFlag) */
  76. GLboolean boundaryOnly; /* Extract contours, not triangles */
  77. GLUface *lonelyTriList;
  78. /* list of triangles which could not be rendered as strips or fans */
  79. void (GLAPIENTRY *callBegin)( GLenum type );
  80. void (GLAPIENTRY *callEdgeFlag)( GLboolean boundaryEdge );
  81. void (GLAPIENTRY *callVertex)( void *data );
  82. void (GLAPIENTRY *callEnd)( void );
  83. void (GLAPIENTRY *callMesh)( GLUmesh *mesh );
  84. /*** state needed to cache single-contour polygons for renderCache() */
  85. GLboolean emptyCache; /* empty cache on next vertex() call */
  86. int cacheCount; /* number of cached vertices */
  87. CachedVertex cache[TESS_MAX_CACHE]; /* the vertex data */
  88. /*** rendering callbacks that also pass polygon data ***/
  89. void (GLAPIENTRY *callBeginData)( GLenum type, void *polygonData );
  90. void (GLAPIENTRY *callEdgeFlagData)( GLboolean boundaryEdge,
  91. void *polygonData );
  92. void (GLAPIENTRY *callVertexData)( void *data, void *polygonData );
  93. void (GLAPIENTRY *callEndData)( void *polygonData );
  94. void (GLAPIENTRY *callErrorData)( GLenum errnum, void *polygonData );
  95. void (GLAPIENTRY *callCombineData)( GLdouble coords[3], void *data[4],
  96. GLfloat weight[4], void **outData,
  97. void *polygonData );
  98. jmp_buf env; /* place to jump to when memAllocs fail */
  99. void *polygonData; /* client data for current polygon */
  100. };
  101. void GLAPIENTRY __gl_noBeginData( GLenum type, void *polygonData );
  102. void GLAPIENTRY __gl_noEdgeFlagData( GLboolean boundaryEdge, void *polygonData );
  103. void GLAPIENTRY __gl_noVertexData( void *data, void *polygonData );
  104. void GLAPIENTRY __gl_noEndData( void *polygonData );
  105. void GLAPIENTRY __gl_noErrorData( GLenum errnum, void *polygonData );
  106. void GLAPIENTRY __gl_noCombineData( GLdouble coords[3], void *data[4],
  107. GLfloat weight[4], void **outData,
  108. void *polygonData );
  109. #define CALL_BEGIN_OR_BEGIN_DATA(a) \
  110. if (tess->callBeginData != &__gl_noBeginData) \
  111. (*tess->callBeginData)((a),tess->polygonData); \
  112. else (*tess->callBegin)((a));
  113. #define CALL_VERTEX_OR_VERTEX_DATA(a) \
  114. if (tess->callVertexData != &__gl_noVertexData) \
  115. (*tess->callVertexData)((a),tess->polygonData); \
  116. else (*tess->callVertex)((a));
  117. #define CALL_EDGE_FLAG_OR_EDGE_FLAG_DATA(a) \
  118. if (tess->callEdgeFlagData != &__gl_noEdgeFlagData) \
  119. (*tess->callEdgeFlagData)((a),tess->polygonData); \
  120. else (*tess->callEdgeFlag)((a));
  121. #define CALL_END_OR_END_DATA() \
  122. if (tess->callEndData != &__gl_noEndData) \
  123. (*tess->callEndData)(tess->polygonData); \
  124. else (*tess->callEnd)();
  125. #define CALL_COMBINE_OR_COMBINE_DATA(a,b,c,d) \
  126. if (tess->callCombineData != &__gl_noCombineData) \
  127. (*tess->callCombineData)((a),(b),(c),(d),tess->polygonData); \
  128. else (*tess->callCombine)((a),(b),(c),(d));
  129. #define CALL_ERROR_OR_ERROR_DATA(a) \
  130. if (tess->callErrorData != &__gl_noErrorData) \
  131. (*tess->callErrorData)((a),tess->polygonData); \
  132. else (*tess->callError)((a));
  133. #endif