⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tess.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice including the dates of first publication and * either this permission notice or a reference to * http://oss.sgi.com/projects/FreeB/ * shall be included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of Silicon Graphics, Inc. * shall not be used in advertising or otherwise to promote the sale, use or * other dealings in this Software without prior written authorization from * Silicon Graphics, Inc. *//*** Author: Eric Veach, July 1994.***/#include "gluos.h"#include <stddef.h>#include <assert.h>#include <setjmp.h>#include "memalloc.h"#include "tess.h"#include "mesh.h"#include "normal.h"#include "sweep.h"#include "tessmono.h"#include "render.h"#define GLU_TESS_DEFAULT_TOLERANCE 0.0#define GLU_TESS_MESH		100112	/* void (*)(GLUmesh *mesh)	    */#define TRUE 1#define FALSE 0/*ARGSUSED*/ static void GLAPIENTRY noBegin( GLenum type ) {}/*ARGSUSED*/ static void GLAPIENTRY noEdgeFlag( GLboolean boundaryEdge ) {}/*ARGSUSED*/ static void GLAPIENTRY noVertex( void *data ) {}/*ARGSUSED*/ static void GLAPIENTRY noEnd( void ) {}/*ARGSUSED*/ static void GLAPIENTRY noError( GLenum errnum ) {}/*ARGSUSED*/ static void GLAPIENTRY noCombine( GLdouble coords[3], void *data[4],				    GLfloat weight[4], void **dataOut ) {}/*ARGSUSED*/ static void GLAPIENTRY noMesh( GLUmesh *mesh ) {}/*ARGSUSED*/ void GLAPIENTRY __gl_noBeginData( GLenum type,					     void *polygonData ) {}/*ARGSUSED*/ void GLAPIENTRY __gl_noEdgeFlagData( GLboolean boundaryEdge,				       void *polygonData ) {}/*ARGSUSED*/ void GLAPIENTRY __gl_noVertexData( void *data,					      void *polygonData ) {}/*ARGSUSED*/ void GLAPIENTRY __gl_noEndData( void *polygonData ) {}/*ARGSUSED*/ void GLAPIENTRY __gl_noErrorData( GLenum errnum,					     void *polygonData ) {}/*ARGSUSED*/ void GLAPIENTRY __gl_noCombineData( GLdouble coords[3],					       void *data[4],					       GLfloat weight[4],					       void **outData,					       void *polygonData ) {}/* Half-edges are allocated in pairs (see mesh.c) */typedef struct { GLUhalfEdge e, eSym; } EdgePair;#undef	MAX#define MAX(a,b)	((a) > (b) ? (a) : (b))#define MAX_FAST_ALLOC	(MAX(sizeof(EdgePair), \                         MAX(sizeof(GLUvertex),sizeof(GLUface))))GLUtesselator * GLAPIENTRYgluNewTess( void ){  GLUtesselator *tess;  /* Only initialize fields which can be changed by the api.  Other fields   * are initialized where they are used.   */  if (memInit( MAX_FAST_ALLOC ) == 0) {     return 0;			/* out of memory */  }  tess = (GLUtesselator *)memAlloc( sizeof( GLUtesselator ));  if (tess == NULL) {     return 0;			/* out of memory */  }  tess->state = T_DORMANT;  tess->normal[0] = 0;  tess->normal[1] = 0;  tess->normal[2] = 0;  tess->relTolerance = GLU_TESS_DEFAULT_TOLERANCE;  tess->windingRule = GLU_TESS_WINDING_ODD;  tess->flagBoundary = FALSE;  tess->boundaryOnly = FALSE;  tess->callBegin = &noBegin;  tess->callEdgeFlag = &noEdgeFlag;  tess->callVertex = &noVertex;  tess->callEnd = &noEnd;  tess->callError = &noError;  tess->callCombine = &noCombine;  tess->callMesh = &noMesh;  tess->callBeginData= &__gl_noBeginData;  tess->callEdgeFlagData= &__gl_noEdgeFlagData;  tess->callVertexData= &__gl_noVertexData;  tess->callEndData= &__gl_noEndData;  tess->callErrorData= &__gl_noErrorData;  tess->callCombineData= &__gl_noCombineData;  tess->polygonData= NULL;  return tess;}static void MakeDormant( GLUtesselator *tess ){  /* Return the tessellator to its original dormant state. */  if( tess->mesh != NULL ) {    __gl_meshDeleteMesh( tess->mesh );  }  tess->state = T_DORMANT;  tess->lastEdge = NULL;  tess->mesh = NULL;}#define RequireState( tess, s )   if( tess->state != s ) GotoState(tess,s)static void GotoState( GLUtesselator *tess, enum TessState newState ){  while( tess->state != newState ) {    /* We change the current state one level at a time, to get to     * the desired state.     */    if( tess->state < newState ) {      switch( tess->state ) {      case T_DORMANT:	CALL_ERROR_OR_ERROR_DATA( GLU_TESS_MISSING_BEGIN_POLYGON );	gluTessBeginPolygon( tess, NULL );	break;      case T_IN_POLYGON:	CALL_ERROR_OR_ERROR_DATA( GLU_TESS_MISSING_BEGIN_CONTOUR );	gluTessBeginContour( tess );	break;      default:	 ;      }    } else {      switch( tess->state ) {      case T_IN_CONTOUR:	CALL_ERROR_OR_ERROR_DATA( GLU_TESS_MISSING_END_CONTOUR );	gluTessEndContour( tess );	break;      case T_IN_POLYGON:	CALL_ERROR_OR_ERROR_DATA( GLU_TESS_MISSING_END_POLYGON );	/* gluTessEndPolygon( tess ) is too much work! */	MakeDormant( tess );	break;      default:	 ;      }    }  }}void GLAPIENTRYgluDeleteTess( GLUtesselator *tess ){  RequireState( tess, T_DORMANT );  memFree( tess );}void GLAPIENTRYgluTessProperty( GLUtesselator *tess, GLenum which, GLdouble value ){  GLenum windingRule;  switch( which ) {  case GLU_TESS_TOLERANCE:    if( value < 0.0 || value > 1.0 ) break;    tess->relTolerance = value;    return;  case GLU_TESS_WINDING_RULE:    windingRule = (GLenum) value;    if( windingRule != value ) break;	/* not an integer */    switch( windingRule ) {    case GLU_TESS_WINDING_ODD:    case GLU_TESS_WINDING_NONZERO:    case GLU_TESS_WINDING_POSITIVE:    case GLU_TESS_WINDING_NEGATIVE:    case GLU_TESS_WINDING_ABS_GEQ_TWO:      tess->windingRule = windingRule;      return;    default:      break;    }  case GLU_TESS_BOUNDARY_ONLY:    tess->boundaryOnly = (value != 0);    return;  default:    CALL_ERROR_OR_ERROR_DATA( GLU_INVALID_ENUM );    return;  }  CALL_ERROR_OR_ERROR_DATA( GLU_INVALID_VALUE );}/* Returns tessellator property */void GLAPIENTRYgluGetTessProperty( GLUtesselator *tess, GLenum which, GLdouble *value ){   switch (which) {   case GLU_TESS_TOLERANCE:      /* tolerance should be in range [0..1] */      assert(0.0 <= tess->relTolerance && tess->relTolerance <= 1.0);      *value= tess->relTolerance;      break;   case GLU_TESS_WINDING_RULE:      assert(tess->windingRule == GLU_TESS_WINDING_ODD ||	     tess->windingRule == GLU_TESS_WINDING_NONZERO ||	     tess->windingRule == GLU_TESS_WINDING_POSITIVE ||	     tess->windingRule == GLU_TESS_WINDING_NEGATIVE ||	     tess->windingRule == GLU_TESS_WINDING_ABS_GEQ_TWO);      *value= tess->windingRule;      break;   case GLU_TESS_BOUNDARY_ONLY:      assert(tess->boundaryOnly == TRUE || tess->boundaryOnly == FALSE);      *value= tess->boundaryOnly;      break;   default:      *value= 0.0;      CALL_ERROR_OR_ERROR_DATA( GLU_INVALID_ENUM );      break;   }} /* gluGetTessProperty() */void GLAPIENTRYgluTessNormal( GLUtesselator *tess, GLdouble x, GLdouble y, GLdouble z ){  tess->normal[0] = x;  tess->normal[1] = y;  tess->normal[2] = z;}void GLAPIENTRYgluTessCallback( GLUtesselator *tess, GLenum which, _GLUfuncptr fn){  switch( which ) {  case GLU_TESS_BEGIN:    tess->callBegin = (fn == NULL) ? &noBegin : (void (GLAPIENTRY *)(GLenum)) fn;    return;  case GLU_TESS_BEGIN_DATA:    tess->callBeginData = (fn == NULL) ?	&__gl_noBeginData : (void (GLAPIENTRY *)(GLenum, void *)) fn;    return;  case GLU_TESS_EDGE_FLAG:    tess->callEdgeFlag = (fn == NULL) ? &noEdgeFlag :					(void (GLAPIENTRY *)(GLboolean)) fn;    /* If the client wants boundary edges to be flagged,     * we render everything as separate triangles (no strips or fans).     */    tess->flagBoundary = (fn != NULL);    return;  case GLU_TESS_EDGE_FLAG_DATA:    tess->callEdgeFlagData= (fn == NULL) ?	&__gl_noEdgeFlagData : (void (GLAPIENTRY *)(GLboolean, void *)) fn;    /* If the client wants boundary edges to be flagged,     * we render everything as separate triangles (no strips or fans).     */    tess->flagBoundary = (fn != NULL);    return;  case GLU_TESS_VERTEX:    tess->callVertex = (fn == NULL) ? &noVertex :				      (void (GLAPIENTRY *)(void *)) fn;    return;  case GLU_TESS_VERTEX_DATA:    tess->callVertexData = (fn == NULL) ?	&__gl_noVertexData : (void (GLAPIENTRY *)(void *, void *)) fn;    return;  case GLU_TESS_END:    tess->callEnd = (fn == NULL) ? &noEnd : (void (GLAPIENTRY *)(void)) fn;    return;  case GLU_TESS_END_DATA:    tess->callEndData = (fn == NULL) ? &__gl_noEndData :				       (void (GLAPIENTRY *)(void *)) fn;    return;  case GLU_TESS_ERROR:    tess->callError = (fn == NULL) ? &noError : (void (GLAPIENTRY *)(GLenum)) fn;    return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -