root/OpenSceneGraph/trunk/src/osg/glu/libtess/tess.h
@
11829
| Revision 11829, 6.6 kB (checked in by robert, 3 years ago) |
|---|
| Line | |
|---|---|
| 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 <GL/glu.h> |
| 39 | #include <osg/GLU> |
| 40 | |
| 41 | // simply define GLAPIENTRY as nothing so that we can keep function signatures the same as declaration. |
| 42 | #define GLAPIENTRY |
| 43 | |
| 44 | #include <setjmp.h> |
| 45 | #include "mesh.h" |
| 46 | #include "dict.h" |
| 47 | #include "priorityq.h" |
| 48 | |
| 49 | /* The begin/end calls must be properly nested. We keep track of |
| 50 | * the current state to enforce the ordering. |
| 51 | */ |
| 52 | enum TessState { T_DORMANT, T_IN_POLYGON, T_IN_CONTOUR }; |
| 53 | |
| 54 | /* We cache vertex data for single-contour polygons so that we can |
| 55 | * try a quick-and-dirty decomposition first. |
| 56 | */ |
| 57 | #define TESS_MAX_CACHE 100 |
| 58 | |
| 59 | typedef struct CachedVertex { |
| 60 | GLdouble coords[3]; |
| 61 | void *data; |
| 62 | } CachedVertex; |
| 63 | |
| 64 | struct osg::GLUtesselator { |
| 65 | |
| 66 | /*** state needed for collecting the input data ***/ |
| 67 | |
| 68 | enum TessState state; /* what begin/end calls have we seen? */ |
| 69 | |
| 70 | GLUhalfEdge *lastEdge; /* lastEdge->Org is the most recent vertex */ |
| 71 | GLUmesh *mesh; /* stores the input contours, and eventually |
| 72 | the tessellation itself */ |
| 73 | |
| 74 | void (GLAPIENTRY *callError)( GLenum errnum ); |
| 75 | |
| 76 | /*** state needed for projecting onto the sweep plane ***/ |
| 77 | |
| 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) */ |
| 81 | |
| 82 | /*** state needed for the line sweep ***/ |
| 83 | |
| 84 | GLdouble relTolerance; /* tolerance for merging features */ |
| 85 | GLenum windingRule; /* rule for determining polygon interior */ |
| 86 | GLboolean fatalError; /* fatal error: needed combine callback */ |
| 87 | |
| 88 | Dict *dict; /* edge dictionary for sweep line */ |
| 89 | PriorityQ *pq; /* priority queue of vertex events */ |
| 90 | GLUvertex *event; /* current sweep event being processed */ |
| 91 | |
| 92 | void (GLAPIENTRY *callCombine)( GLdouble coords[3], void *data[4], |
| 93 | GLfloat weight[4], void **outData ); |
| 94 | |
| 95 | /*** state needed for rendering callbacks (see render.c) ***/ |
| 96 | |
| 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 */ |
| 101 | |
| 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 ); |
| 107 | |
| 108 | |
| 109 | /*** state needed to cache single-contour polygons for renderCache() */ |
| 110 | |
| 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 */ |
| 114 | |
| 115 | /*** rendering callbacks that also pass polygon data ***/ |
| 116 | void (GLAPIENTRY *callBeginData)( GLenum type, void *polygonData ); |
| 117 | void (GLAPIENTRY *callEdgeFlagData)( GLboolean boundaryEdge, |
| 118 | void *polygonData ); |
| 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, |
| 124 | void *polygonData ); |
| 125 | |
| 126 | jmp_buf env; /* place to jump to when memAllocs fail */ |
| 127 | |
| 128 | void *polygonData; /* client data for current polygon */ |
| 129 | }; |
| 130 | |
| 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, |
| 138 | void *polygonData ); |
| 139 | |
| 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)); |
| 144 | |
| 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)); |
| 149 | |
| 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)); |
| 154 | |
| 155 | #define CALL_END_OR_END_DATA() \ |
| 156 | if (tess->callEndData != &__gl_noEndData) \ |
| 157 | (*tess->callEndData)(tess->polygonData); \ |
| 158 | else (*tess->callEnd)(); |
| 159 | |
| 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)); |
| 164 | |
| 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)); |
| 169 | |
| 170 | // make it easy to introduce the namespace osg for the public functions and typedefs |
| 171 | using osg::GLUtesselator; |
| 172 | using osg::_GLUfuncptr; |
| 173 | |
| 174 | |
| 175 | #endif |
Note: See TracBrowser
for help on using the browser.
