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