Exemplo n.º 1
0
void GLU_APIENTRY gluTessVertex(GLUtesselator* tess, GLfloat coords[3], void* data)
{
   int i;
   int tooLarge=FALSE;
   GLfloat x, clamped[3];

   RequireState(tess, T_IN_CONTOUR);

   if (tess->emptyCache)
   {
      if (!EmptyCache(tess))
      {
         CALL_ERROR_OR_ERROR_DATA( GLU_OUT_OF_MEMORY );
         return;
      }
      tess->lastEdge=NULL;
   }

   for (i=0; i<3; ++i)
   {
      x=coords[i];
      if (x<-GLU_TESS_MAX_COORD)
      {
         x=-GLU_TESS_MAX_COORD;
         tooLarge=TRUE;
      }
      if (x>GLU_TESS_MAX_COORD)
      {
         x=GLU_TESS_MAX_COORD;
         tooLarge=TRUE;
      }
      clamped[i]=x;
   }
   if (tooLarge)
   {
      CALL_ERROR_OR_ERROR_DATA(GLU_TESS_COORD_TOO_LARGE);
   }

   if (tess->mesh==NULL)
   {
      if (tess->cacheCount<TESS_MAX_CACHE)
      {
         CacheVertex(tess, clamped, data);
         return;
      }
      if (!EmptyCache(tess))
      {
         CALL_ERROR_OR_ERROR_DATA(GLU_OUT_OF_MEMORY);
         return;
      }
   }

   if (!AddVertex(tess, clamped, data))
   {
      CALL_ERROR_OR_ERROR_DATA(GLU_OUT_OF_MEMORY);
   }
}
Exemplo n.º 2
0
/* Returns tessellator property */
void REGALGLU_CALL
gluGetTessProperty( 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() */
Exemplo n.º 3
0
static void CallCombine( GLUtesselator *tess, GLUvertex *isect,
			 void *data[4], GLfloat weights[4], int needed )
{
  GLdouble coords[3];

  /* Copy coord data in case the callback changes it. */
  coords[0] = isect->coords[0];
  coords[1] = isect->coords[1];
  coords[2] = isect->coords[2];

  isect->data = NULL;
  CALL_COMBINE_OR_COMBINE_DATA( coords, data, weights, &isect->data );
  if( isect->data == NULL ) {
    if( ! needed ) {
      isect->data = data[0];
    } else if( ! tess->fatalError ) {
      /* The only way fatal error is when two edges are found to intersect,
       * but the user has not provided the callback necessary to handle
       * generated intersection points.
       */
      CALL_ERROR_OR_ERROR_DATA( GLU_TESS_NEED_COMBINE_CALLBACK );
      tess->fatalError = TRUE;
    }
  }
}
Exemplo n.º 4
0
void REGALWRATH_GLU_CALL
wrath_gluTessVertex( wrath_GLUtesselator *tess, const double coords[3], void *data )
{
  int i, tooLarge = FALSE;
  double x, clamped[3];

  RequireState( tess, T_IN_CONTOUR );

  if( tess->emptyCache ) {
    if ( !EmptyCache( tess ) ) {
       CALL_ERROR_OR_ERROR_DATA( WRATH_GLU_OUT_OF_MEMORY );
       return;
    }
    tess->lastEdge = NULL;
  }
  for( i = 0; i < 3; ++i ) {
    x = coords[i];
    if( x < - WRATH_GLU_TESS_MAX_COORD ) {
      x = - WRATH_GLU_TESS_MAX_COORD;
      tooLarge = TRUE;
    }
    if( x > WRATH_GLU_TESS_MAX_COORD ) {
      x = WRATH_GLU_TESS_MAX_COORD;
      tooLarge = TRUE;
    }
    clamped[i] = x;
  }
  if( tooLarge ) {
    CALL_ERROR_OR_ERROR_DATA( WRATH_GLU_TESS_COORD_TOO_LARGE );
  }

  if( tess->mesh == NULL ) {
    if( tess->cacheCount < TESS_MAX_CACHE ) {
      CacheVertex( tess, clamped, data );
      return;
    }
    if ( !EmptyCache( tess ) ) {
       CALL_ERROR_OR_ERROR_DATA( WRATH_GLU_OUT_OF_MEMORY );
       return;
    }
  }
  if ( !AddVertex( tess, clamped, data ) ) {
       CALL_ERROR_OR_ERROR_DATA( WRATH_GLU_OUT_OF_MEMORY );
  }
}
Exemplo n.º 5
0
GLU_API void GLU_APIENTRY gluTessProperty(GLUtesselator* tess, GLenum which, GLfloat value)
{
   GLenum windingRule;

   switch (which)
   {
      case GLU_TESS_TOLERANCE:
           if (value<0.0f || value>1.0f)
           {
              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;
           }
           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);
}
Exemplo n.º 6
0
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:
                 break;
         }
      }
      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:
                 break;
         }
      }
   }
}
Exemplo n.º 7
0
void REGALFASTUIDRAW_GLU_CALL
fastuidraw_gluTessVertex( fastuidraw_GLUtesselator *tess, double x, double y, unsigned int data )
{
  int tooLarge = FALSE;

  RequireState( tess, T_IN_CONTOUR );

  if( tess->emptyCache ) {
    if ( !EmptyCache( tess ) ) {
       CALL_ERROR_OR_ERROR_DATA( FASTUIDRAW_GLU_OUT_OF_MEMORY );
       return;
    }
    tess->lastEdge = NULL;
  }

  checkTooLarge(&x, &tooLarge);
  checkTooLarge(&y, &tooLarge);


  if( tooLarge ) {
    CALL_ERROR_OR_ERROR_DATA( FASTUIDRAW_GLU_TESS_COORD_TOO_LARGE );
  }

  if( tess->mesh == NULL ) {
    if( tess->cacheCount < TESS_MAX_CACHE ) {
      CacheVertex( tess, x, y, data );
      return;
    }
    if ( !EmptyCache( tess ) ) {
       CALL_ERROR_OR_ERROR_DATA( FASTUIDRAW_GLU_OUT_OF_MEMORY );
       return;
    }
  }
  if ( !AddVertex( tess, x, y, data ) ) {
       CALL_ERROR_OR_ERROR_DATA( FASTUIDRAW_GLU_OUT_OF_MEMORY );
  }
}
Exemplo n.º 8
0
void REGALGLU_CALL
gluTessEndPolygon( GLUtesselator *tess )
{
  GLUmesh *mesh;

  if (setjmp(tess->env) != 0) { 
     /* come back here if out of memory */
     CALL_ERROR_OR_ERROR_DATA( GLU_OUT_OF_MEMORY );
     return;
  }

  RequireState( tess, T_IN_POLYGON );
  tess->state = T_DORMANT;

  if( tess->mesh == NULL ) {
    if( ! tess->flagBoundary && tess->callMesh == &noMesh ) {

      /* Try some special code to make the easy cases go quickly
       * (eg. convex polygons).  This code does NOT handle multiple contours,
       * intersections, edge flags, and of course it does not generate
       * an explicit mesh either.
       */
      if( __gl_renderCache( tess )) {
	tess->polygonData= NULL;
	return;
      }
    }
    if ( !EmptyCache( tess ) ) longjmp(tess->env,1); /* could've used a label*/
  }

  /* Determine the polygon normal and project vertices onto the plane
   * of the polygon.
   */
  __gl_projectPolygon( tess );

  /* __gl_computeInterior( tess ) computes the planar arrangement specified
   * by the given contours, and further subdivides this arrangement
   * into regions.  Each region is marked "inside" if it belongs
   * to the polygon, according to the rule given by tess->windingRule.
   * Each interior region is guaranteed be monotone.
   */
  if ( !__gl_computeInterior( tess ) ) {
     longjmp(tess->env,1);	/* could've used a label */
  }

  mesh = tess->mesh;
  if( ! tess->fatalError ) {
    int rc = 1;

    /* If the user wants only the boundary contours, we throw away all edges
     * except those which separate the interior from the exterior.
     * Otherwise we tessellate all the regions marked "inside".
     */
    if( tess->boundaryOnly ) {
      rc = __gl_meshSetWindingNumber( mesh, 1, TRUE );
    } else {
      rc = __gl_meshTessellateInterior( mesh );
    }
    if (rc == 0) longjmp(tess->env,1);	/* could've used a label */

    __gl_meshCheckMesh( mesh );

    if( tess->callBegin != &noBegin || tess->callEnd != &noEnd
       || tess->callVertex != &noVertex || tess->callEdgeFlag != &noEdgeFlag
       || tess->callBeginData != &__gl_noBeginData
       || tess->callEndData != &__gl_noEndData
       || tess->callVertexData != &__gl_noVertexData
       || tess->callEdgeFlagData != &__gl_noEdgeFlagData )
    {
      if( tess->boundaryOnly ) {
	__gl_renderBoundary( tess, mesh );  /* output boundary contours */
      } else {
	__gl_renderMesh( tess, mesh );	   /* output strips and fans */
      }
    }
    if( tess->callMesh != &noMesh ) {

      /* Throw away the exterior faces, so that all faces are interior.
       * This way the user doesn't have to check the "inside" flag,
       * and we don't need to even reveal its existence.  It also leaves
       * the freedom for an implementation to not generate the exterior
       * faces in the first place.
       */
      __gl_meshDiscardExterior( mesh );
      (*tess->callMesh)( mesh );		/* user wants the mesh itself */
      tess->mesh = NULL;
      tess->polygonData= NULL;
      return;
    }
  }
  __gl_meshDeleteMesh( mesh );
  tess->polygonData= NULL;
  tess->mesh = NULL;
}
Exemplo n.º 9
0
void REGALGLU_CALL
gluTessCallback( GLUtesselator *tess, GLenum which, _GLUfuncptr fn)
{
  switch( which ) {
  case GLU_TESS_BEGIN:
    tess->callBegin = (fn == NULL) ? &noBegin : (void (REGALGLU_CALL *)(GLenum)) fn;
    return;
  case GLU_TESS_BEGIN_DATA:
    tess->callBeginData = (fn == NULL) ?
	&__gl_noBeginData : (void (REGALGLU_CALL *)(GLenum, void *)) fn;
    return;
  case GLU_TESS_EDGE_FLAG:
    tess->callEdgeFlag = (fn == NULL) ? &noEdgeFlag :
					(void (REGALGLU_CALL *)(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 (REGALGLU_CALL *)(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 (REGALGLU_CALL *)(void *)) fn;
    return;
  case GLU_TESS_VERTEX_DATA:
    tess->callVertexData = (fn == NULL) ?
	&__gl_noVertexData : (void (REGALGLU_CALL *)(void *, void *)) fn;
    return;
  case GLU_TESS_END:
    tess->callEnd = (fn == NULL) ? &noEnd : (void (REGALGLU_CALL *)(void)) fn;
    return;
  case GLU_TESS_END_DATA:
    tess->callEndData = (fn == NULL) ? &__gl_noEndData :
				       (void (REGALGLU_CALL *)(void *)) fn;
    return;
  case GLU_TESS_ERROR:
    tess->callError = (fn == NULL) ? &noError : (void (REGALGLU_CALL *)(GLenum)) fn;
    return;
  case GLU_TESS_ERROR_DATA:
    tess->callErrorData = (fn == NULL) ?
	&__gl_noErrorData : (void (REGALGLU_CALL *)(GLenum, void *)) fn;
    return;
  case GLU_TESS_COMBINE:
    tess->callCombine = (fn == NULL) ? &noCombine :
	(void (REGALGLU_CALL *)(GLdouble [3],void *[4], GLfloat [4], void ** )) fn;
    return;
  case GLU_TESS_COMBINE_DATA:
    tess->callCombineData = (fn == NULL) ? &__gl_noCombineData :
					   (void (REGALGLU_CALL *)(GLdouble [3],
						     void *[4],
						     GLfloat [4],
						     void **,
						     void *)) fn;
    return;
  case GLU_TESS_MESH:
    tess->callMesh = (fn == NULL) ? &noMesh : (void (REGALGLU_CALL *)(GLUmesh *)) fn;
    return;
  default:
    CALL_ERROR_OR_ERROR_DATA( GLU_INVALID_ENUM );
    return;
  }
}
Exemplo n.º 10
0
void REGALFASTUIDRAW_GLU_CALL
fastuidraw_gluTessCallback( fastuidraw_GLUtesselator *tess, FASTUIDRAW_GLUenum which, FASTUIDRAW_GLUfuncptr fn)
{
  switch( which ) {
  case FASTUIDRAW_GLU_TESS_BEGIN:
    tess->callBegin = (fn == NULL) ? &noBegin : (void (REGALFASTUIDRAW_GLU_CALL *)(FASTUIDRAW_GLUenum, int)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_BEGIN_DATA:
    tess->callBeginData = (fn == NULL) ?
        &glu_fastuidraw_gl_noBeginData : (void (REGALFASTUIDRAW_GLU_CALL *)(FASTUIDRAW_GLUenum, int, void *)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_VERTEX:
    tess->callVertex = (fn == NULL) ? &noVertex :
                                      (void (REGALFASTUIDRAW_GLU_CALL *)(unsigned int)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_VERTEX_DATA:
    tess->callVertexData = (fn == NULL) ?
        &glu_fastuidraw_gl_noVertexData : (void (REGALFASTUIDRAW_GLU_CALL *)(unsigned int, void *)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_END:
    tess->callEnd = (fn == NULL) ? &noEnd : (void (REGALFASTUIDRAW_GLU_CALL *)(void)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_END_DATA:
    tess->callEndData = (fn == NULL) ? &glu_fastuidraw_gl_noEndData :
                                       (void (REGALFASTUIDRAW_GLU_CALL *)(void *)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_ERROR:
    tess->callError = (fn == NULL) ? &noError : (void (REGALFASTUIDRAW_GLU_CALL *)(FASTUIDRAW_GLUenum)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_ERROR_DATA:
    tess->callErrorData = (fn == NULL) ?
        &glu_fastuidraw_gl_noErrorData : (void (REGALFASTUIDRAW_GLU_CALL *)(FASTUIDRAW_GLUenum, void *)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_COMBINE:
    tess->callCombine = (fn == NULL) ? &noCombine :
    (void (REGALFASTUIDRAW_GLU_CALL *)(double , double, unsigned int[4], float [4], unsigned int* )) fn;
    return;
  case FASTUIDRAW_GLU_TESS_COMBINE_DATA:
    tess->callCombineData = (fn == NULL) ? &glu_fastuidraw_gl_noCombineData :
                                           (void (REGALFASTUIDRAW_GLU_CALL *)(double,
                                                                             double,
                                                                             unsigned int[4],
                                                                             float [4],
                                                                             unsigned int*,
                                                                             void *)) fn;
    return;
  case FASTUIDRAW_GLU_TESS_MESH:
    tess->callMesh = (fn == NULL) ? &noMesh : (void (REGALFASTUIDRAW_GLU_CALL *)(GLUmesh *)) fn;
    return;

  case FASTUIDRAW_GLU_TESS_WINDING_CALLBACK:
    tess->callWinding=(fn==NULL)? &noWinding: (FASTUIDRAW_GLUboolean (REGALFASTUIDRAW_GLU_CALL *)(int)) fn;
    return;

  case FASTUIDRAW_GLU_TESS_WINDING_CALLBACK_DATA:
    tess->callWindingData=(fn==NULL)? &glu_fastuidraw_gl_noWindingData: (FASTUIDRAW_GLUboolean (REGALFASTUIDRAW_GLU_CALL *)(int, void*)) fn;
    return;

  default:
    CALL_ERROR_OR_ERROR_DATA( FASTUIDRAW_GLU_INVALID_ENUM );
    return;
  }
}