Butterbur: Tesselation support for filling closed paths
[sdk] / deps / libtess / tess.h
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
35 #ifndef __tess_h_
36 #define __tess_h_
37
38 #include <setjmp.h>
39 #include "mesh.h"
40 #include "dict.h"
41 #include "priorityq.h"
42
43 /* The begin/end calls must be properly nested.  We keep track of
44  * the current state to enforce the ordering.
45  */
46 enum TessState { T_DORMANT, T_IN_POLYGON, T_IN_CONTOUR };
47
48 /* We cache vertex data for single-contour polygons so that we can
49  * try a quick-and-dirty decomposition first.
50  */
51 #define TESS_MAX_CACHE  100
52
53 typedef struct CachedVertex {
54   GLdouble      coords[3];
55   void          *data;
56 } CachedVertex;
57
58 struct GLUtesselator {
59
60   /*** state needed for collecting the input data ***/
61
62   enum TessState state;         /* what begin/end calls have we seen? */
63
64   GLUhalfEdge   *lastEdge;      /* lastEdge->Org is the most recent vertex */
65   GLUmesh       *mesh;          /* stores the input contours, and eventually
66                                    the tessellation itself */
67
68   void          (GLAPIENTRY *callError)( GLenum errnum );
69
70   /*** state needed for projecting onto the sweep plane ***/
71
72   GLdouble      normal[3];      /* user-specified normal (if provided) */
73   GLdouble      sUnit[3];       /* unit vector in s-direction (debugging) */
74   GLdouble      tUnit[3];       /* unit vector in t-direction (debugging) */
75
76   /*** state needed for the line sweep ***/
77
78   GLdouble      relTolerance;   /* tolerance for merging features */
79   GLenum        windingRule;    /* rule for determining polygon interior */
80   GLboolean     fatalError;     /* fatal error: needed combine callback */
81
82   Dict          *dict;          /* edge dictionary for sweep line */
83   PriorityQ     *pq;            /* priority queue of vertex events */
84   GLUvertex     *event;         /* current sweep event being processed */
85
86   void          (GLAPIENTRY *callCombine)( GLdouble coords[3], void *data[4],
87                                 GLfloat weight[4], void **outData );
88
89   /*** state needed for rendering callbacks (see render.c) ***/
90
91   GLboolean     flagBoundary;   /* mark boundary edges (use EdgeFlag) */
92   GLboolean     boundaryOnly;   /* Extract contours, not triangles */
93   GLUface       *lonelyTriList;
94     /* list of triangles which could not be rendered as strips or fans */
95
96   void          (GLAPIENTRY *callBegin)( GLenum type );
97   void          (GLAPIENTRY *callEdgeFlag)( GLboolean boundaryEdge );
98   void          (GLAPIENTRY *callVertex)( void *data );
99   void          (GLAPIENTRY *callEnd)( void );
100   void          (GLAPIENTRY *callMesh)( GLUmesh *mesh );
101
102
103   /*** state needed to cache single-contour polygons for renderCache() */
104
105   GLboolean     emptyCache;             /* empty cache on next vertex() call */
106   int           cacheCount;             /* number of cached vertices */
107   CachedVertex  cache[TESS_MAX_CACHE];  /* the vertex data */
108
109   /*** rendering callbacks that also pass polygon data  ***/ 
110   void          (GLAPIENTRY *callBeginData)( GLenum type, void *polygonData );
111   void          (GLAPIENTRY *callEdgeFlagData)( GLboolean boundaryEdge, 
112                                      void *polygonData );
113   void          (GLAPIENTRY *callVertexData)( void *data, void *polygonData );
114   void          (GLAPIENTRY *callEndData)( void *polygonData );
115   void          (GLAPIENTRY *callErrorData)( GLenum errnum, void *polygonData );
116   void          (GLAPIENTRY *callCombineData)( GLdouble coords[3], void *data[4],
117                                     GLfloat weight[4], void **outData,
118                                     void *polygonData );
119
120   jmp_buf env;                  /* place to jump to when memAllocs fail */
121
122   void *polygonData;            /* client data for current polygon */
123 };
124
125 void GLAPIENTRY __gl_noBeginData( GLenum type, void *polygonData );
126 void GLAPIENTRY __gl_noEdgeFlagData( GLboolean boundaryEdge, void *polygonData );
127 void GLAPIENTRY __gl_noVertexData( void *data, void *polygonData );
128 void GLAPIENTRY __gl_noEndData( void *polygonData );
129 void GLAPIENTRY __gl_noErrorData( GLenum errnum, void *polygonData );
130 void GLAPIENTRY __gl_noCombineData( GLdouble coords[3], void *data[4],
131                          GLfloat weight[4], void **outData,
132                          void *polygonData );
133
134 #define CALL_BEGIN_OR_BEGIN_DATA(a) \
135    if (tess->callBeginData != &__gl_noBeginData) \
136       (*tess->callBeginData)((a),tess->polygonData); \
137    else (*tess->callBegin)((a));
138
139 #define CALL_VERTEX_OR_VERTEX_DATA(a) \
140    if (tess->callVertexData != &__gl_noVertexData) \
141       (*tess->callVertexData)((a),tess->polygonData); \
142    else (*tess->callVertex)((a));
143
144 #define CALL_EDGE_FLAG_OR_EDGE_FLAG_DATA(a) \
145    if (tess->callEdgeFlagData != &__gl_noEdgeFlagData) \
146       (*tess->callEdgeFlagData)((a),tess->polygonData); \
147    else (*tess->callEdgeFlag)((a));
148
149 #define CALL_END_OR_END_DATA() \
150    if (tess->callEndData != &__gl_noEndData) \
151       (*tess->callEndData)(tess->polygonData); \
152    else (*tess->callEnd)();
153
154 #define CALL_COMBINE_OR_COMBINE_DATA(a,b,c,d) \
155    if (tess->callCombineData != &__gl_noCombineData) \
156       (*tess->callCombineData)((a),(b),(c),(d),tess->polygonData); \
157    else (*tess->callCombine)((a),(b),(c),(d));
158
159 #define CALL_ERROR_OR_ERROR_DATA(a) \
160    if (tess->callErrorData != &__gl_noErrorData) \
161       (*tess->callErrorData)((a),tess->polygonData); \
162    else (*tess->callError)((a));
163
164 #endif