2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
36 ** Author: Eric Veach, July 1994.
47 #include "priorityq.h"
49 /* The begin/end calls must be properly nested. We keep track of
50 * the current state to enforce the ordering.
52 enum TessState
{ T_DORMANT
, T_IN_POLYGON
, T_IN_CONTOUR
};
54 /* We cache vertex data for single-contour polygons so that we can
55 * try a quick-and-dirty decomposition first.
57 #define TESS_MAX_CACHE 100
59 typedef struct CachedVertex
{
64 struct GLUtesselator
{
66 /*** state needed for collecting the input data ***/
68 enum TessState state
; /* what begin/end calls have we seen? */
70 GLUhalfEdge
*lastEdge
; /* lastEdge->Org is the most recent vertex */
71 GLUmesh
*mesh
; /* stores the input contours, and eventually
72 the tessellation itself */
74 void (GLAPIENTRY
*callError
)( GLenum errnum
);
76 /*** state needed for projecting onto the sweep plane ***/
78 GLdouble normal
[3]; /* user-specified normal (if provided) */
79 GLdouble sUnit
[3]; /* unit vector in s-direction (debugging) */
80 GLdouble tUnit
[3]; /* unit vector in t-direction (debugging) */
82 /*** state needed for the line sweep ***/
84 GLdouble relTolerance
; /* tolerance for merging features */
85 GLenum windingRule
; /* rule for determining polygon interior */
86 GLboolean fatalError
; /* fatal error: needed combine callback */
88 Dict
*dict
; /* edge dictionary for sweep line */
89 PriorityQ
*pq
; /* priority queue of vertex events */
90 GLUvertex
*event
; /* current sweep event being processed */
92 void (GLAPIENTRY
*callCombine
)( GLdouble coords
[3], void *data
[4],
93 GLfloat weight
[4], void **outData
);
95 /*** state needed for rendering callbacks (see render.c) ***/
97 GLboolean flagBoundary
; /* mark boundary edges (use EdgeFlag) */
98 GLboolean boundaryOnly
; /* Extract contours, not triangles */
99 GLUface
*lonelyTriList
;
100 /* list of triangles which could not be rendered as strips or fans */
102 void (GLAPIENTRY
*callBegin
)( GLenum type
);
103 void (GLAPIENTRY
*callEdgeFlag
)( GLboolean boundaryEdge
);
104 void (GLAPIENTRY
*callVertex
)( void *data
);
105 void (GLAPIENTRY
*callEnd
)( void );
106 void (GLAPIENTRY
*callMesh
)( GLUmesh
*mesh
);
109 /*** state needed to cache single-contour polygons for renderCache() */
111 GLboolean emptyCache
; /* empty cache on next vertex() call */
112 int cacheCount
; /* number of cached vertices */
113 CachedVertex cache
[TESS_MAX_CACHE
]; /* the vertex data */
115 /*** rendering callbacks that also pass polygon data ***/
116 void (GLAPIENTRY
*callBeginData
)( GLenum type
, void *polygonData
);
117 void (GLAPIENTRY
*callEdgeFlagData
)( GLboolean boundaryEdge
,
119 void (GLAPIENTRY
*callVertexData
)( void *data
, void *polygonData
);
120 void (GLAPIENTRY
*callEndData
)( void *polygonData
);
121 void (GLAPIENTRY
*callErrorData
)( GLenum errnum
, void *polygonData
);
122 void (GLAPIENTRY
*callCombineData
)( GLdouble coords
[3], void *data
[4],
123 GLfloat weight
[4], void **outData
,
126 jmp_buf env
; /* place to jump to when memAllocs fail */
128 void *polygonData
; /* client data for current polygon */
131 void GLAPIENTRY
__gl_noBeginData( GLenum type
, void *polygonData
);
132 void GLAPIENTRY
__gl_noEdgeFlagData( GLboolean boundaryEdge
, void *polygonData
);
133 void GLAPIENTRY
__gl_noVertexData( void *data
, void *polygonData
);
134 void GLAPIENTRY
__gl_noEndData( void *polygonData
);
135 void GLAPIENTRY
__gl_noErrorData( GLenum errnum
, void *polygonData
);
136 void GLAPIENTRY
__gl_noCombineData( GLdouble coords
[3], void *data
[4],
137 GLfloat weight
[4], void **outData
,
140 #define CALL_BEGIN_OR_BEGIN_DATA(a) \
141 if (tess->callBeginData != &__gl_noBeginData) \
142 (*tess->callBeginData)((a),tess->polygonData); \
143 else (*tess->callBegin)((a));
145 #define CALL_VERTEX_OR_VERTEX_DATA(a) \
146 if (tess->callVertexData != &__gl_noVertexData) \
147 (*tess->callVertexData)((a),tess->polygonData); \
148 else (*tess->callVertex)((a));
150 #define CALL_EDGE_FLAG_OR_EDGE_FLAG_DATA(a) \
151 if (tess->callEdgeFlagData != &__gl_noEdgeFlagData) \
152 (*tess->callEdgeFlagData)((a),tess->polygonData); \
153 else (*tess->callEdgeFlag)((a));
155 #define CALL_END_OR_END_DATA() \
156 if (tess->callEndData != &__gl_noEndData) \
157 (*tess->callEndData)(tess->polygonData); \
158 else (*tess->callEnd)();
160 #define CALL_COMBINE_OR_COMBINE_DATA(a,b,c,d) \
161 if (tess->callCombineData != &__gl_noCombineData) \
162 (*tess->callCombineData)((a),(b),(c),(d),tess->polygonData); \
163 else (*tess->callCombine)((a),(b),(c),(d));
165 #define CALL_ERROR_OR_ERROR_DATA(a) \
166 if (tess->callErrorData != &__gl_noErrorData) \
167 (*tess->callErrorData)((a),tess->polygonData); \
168 else (*tess->callError)((a));