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