Major winding rule updates, especially stacked contour support.
authorGareth Hughes <gareth@valinux.com>
Thu, 4 Nov 1999 04:07:57 +0000 (04:07 +0000)
committerGareth Hughes <gareth@valinux.com>
Thu, 4 Nov 1999 04:07:57 +0000 (04:07 +0000)
Improved debugging output that can be altered with an environment
variable instead of hard coded at compile time.  Fixed bug in vertex
sorting function, so vertices are now indexed correctly (left to right).

src/glu/mesa/tess.c
src/glu/mesa/tess.h

index 48b7a6c4c6d56e69c4da0767ebf120e48bb9915c..7c77395689a21303257e38a4893164c01b9687de 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tess.c,v 1.18 1999/10/14 07:44:41 gareth Exp $ */
+/* $Id: tess.c,v 1.19 1999/11/04 04:07:57 gareth Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -51,11 +51,15 @@ static void init_callbacks( tess_callbacks_t *callbacks );
 static void tess_cleanup( GLUtesselator *tobj );
 static void inspect_current_contour( GLUtesselator *tobj );
 
-static void delete_current_contour( GLUtesselator *tobj );
+void delete_contour( tess_contour_t **contour );
 static void delete_all_contours( GLUtesselator *tobj );
 
 #define TESS_CHECK_ERRORS(t)   if ( (t)->error != GLU_NO_ERROR ) goto cleanup
 
+#ifdef DEBUG
+GLint          tess_dbg_level;
+#endif
+
 
 /*****************************************************************************
  *
@@ -71,7 +75,15 @@ GLUtesselator* GLAPIENTRY gluNewTess( void )
 {
     GLUtesselator *tobj;
 
-    DEBUGP( 15, ( "-> gluNewTess()\n" ) );
+#ifdef DEBUG
+    if ( getenv( "GLU_TESS_DBG_LEVEL" ) ) {
+       tess_dbg_level = atoi( getenv( "GLU_TESS_DBG_LEVEL" ) );
+    } else {
+       tess_dbg_level = DBG_LEVEL_BASE;
+    }
+#endif
+
+    MSG( 15, "-> gluNewTess()\n" );
 
     tobj = malloc( sizeof(GLUtesselator) );
     if ( tobj == NULL ) {
@@ -107,7 +119,7 @@ GLUtesselator* GLAPIENTRY gluNewTess( void )
 
     tobj->error = GLU_NO_ERROR;
 
-    DEBUGP( 15, ( "<- gluNewTess() tobj:%p\n", tobj ) );
+    MSG( 15, "<- gluNewTess() tobj:%p\n", tobj );
     return tobj;
 }
 
@@ -117,12 +129,11 @@ GLUtesselator* GLAPIENTRY gluNewTess( void )
  *****************************************************************************/
 void GLAPIENTRY gluDeleteTess( GLUtesselator *tobj )
 {
-    DEBUGP( 15, ( "-> gluDeleteTess( tobj:%p )\n", tobj ) );
+    MSG( 15, "-> gluDeleteTess( tobj:%p )\n", tobj );
 
-    if ( tobj->error == GLU_NO_ERROR && ( tobj->contour_count > 0 ) )
+    if ( ( tobj->error == GLU_NO_ERROR ) && ( tobj->contour_count > 0 ) )
     {
        /* gluEndPolygon was not called. */
-       DEBUGP( 0, ( "*** error 3 ***\n" ) );
        tess_error_callback( tobj, GLU_TESS_ERROR3 );
     }
 
@@ -130,7 +141,7 @@ void GLAPIENTRY gluDeleteTess( GLUtesselator *tobj )
     tess_cleanup( tobj );
     free( tobj );
 
-    DEBUGP( 15, ( "<- gluDeleteTess()\n" ) );
+    MSG( 15, "<- gluDeleteTess()\n" );
 }
 
 
@@ -139,16 +150,14 @@ void GLAPIENTRY gluDeleteTess( GLUtesselator *tobj )
  *****************************************************************************/
 void GLAPIENTRY gluTessBeginPolygon( GLUtesselator *tobj, void *polygon_data )
 {
-    DEBUGP( 15, ( "-> gluTessBeginPolygon( tobj:%p data:%p )\n", tobj, polygon_data ) );
+    MSG( 15, "-> gluTessBeginPolygon( tobj:%p data:%p )\n", tobj, polygon_data );
 
     tobj->error = GLU_NO_ERROR;
 
     if ( tobj->current_contour != NULL )
     {
        /* gluEndPolygon was not called. */
-       DEBUGP( 0, ( "*** error 3 ***\n" ) );
        tess_error_callback( tobj, GLU_TESS_ERROR3 );
-
        tess_cleanup( tobj );
     }
 
@@ -157,7 +166,7 @@ void GLAPIENTRY gluTessBeginPolygon( GLUtesselator *tobj, void *polygon_data )
     tobj->edge_flag = GL_FALSE;
     tobj->label = 0;
 
-    DEBUGP( 15, ( "<- gluTessBeginPolygon( tobj:%p data:%p )\n", tobj, polygon_data ) );
+    MSG( 15, "<- gluTessBeginPolygon( tobj:%p data:%p )\n", tobj, polygon_data );
 }
 
 
@@ -166,13 +175,12 @@ void GLAPIENTRY gluTessBeginPolygon( GLUtesselator *tobj, void *polygon_data )
  *****************************************************************************/
 void GLAPIENTRY gluTessBeginContour( GLUtesselator *tobj )
 {
-    DEBUGP( 15, ( "  -> gluTessBeginContour( tobj:%p )\n", tobj ) );
+    MSG( 15, "  -> gluTessBeginContour( tobj:%p )\n", tobj );
     TESS_CHECK_ERRORS( tobj );
 
     if ( tobj->current_contour != NULL )
     {
        /* gluTessEndContour was not called. */
-       DEBUGP( 0, ( "*** error 4 ***\n" ) );
        tess_error_callback( tobj, GLU_TESS_ERROR4 );
        return;
     }
@@ -205,7 +213,7 @@ void GLAPIENTRY gluTessBeginContour( GLUtesselator *tobj )
     tobj->current_contour->cross_vertices = hashtable_init( HT_DEFAULT_SIZE );
 
  cleanup:
-    DEBUGP( 15, ( "  <- gluTessBeginContour( tobj:%p )\n", tobj ) );
+    MSG( 15, "  <- gluTessBeginContour( tobj:%p )\n", tobj );
     return;
 }
 
@@ -219,13 +227,12 @@ void GLAPIENTRY gluTessVertex( GLUtesselator *tobj, GLdouble coords[3],
     tess_contour_t             *current = tobj->current_contour;
     tess_vertex_t              *last_vertex;
 
-    DEBUGP( 15, ( "    -> gluTessVertex( tobj:%p coords:(%.2f,%.2f,%.2f) )\n", tobj, coords[0], coords[1], coords[2] ) );
+    MSG( 15, "    -> gluTessVertex( tobj:%p coords:(%.2f,%.2f,%.2f) )\n", tobj, coords[0], coords[1], coords[2] );
     TESS_CHECK_ERRORS( tobj );
 
     if ( current == NULL )
     {
        /* gluTessBeginContour was not called. */
-       DEBUGP( 0, ( "*** error 2 ***\n" ) );
        tess_error_callback( tobj, GLU_TESS_ERROR2 );
        return;
     }
@@ -292,7 +299,7 @@ void GLAPIENTRY gluTessVertex( GLUtesselator *tobj, GLdouble coords[3],
     }
 
  cleanup:
-    DEBUGP( 15, ( "    <- gluTessVertex( tobj:%p )\n", tobj ) );
+    MSG( 15, "    <- gluTessVertex( tobj:%p )\n", tobj );
     return;
 }
 
@@ -302,13 +309,12 @@ void GLAPIENTRY gluTessVertex( GLUtesselator *tobj, GLdouble coords[3],
  *****************************************************************************/
 void GLAPIENTRY gluTessEndContour( GLUtesselator *tobj )
 {
-    DEBUGP( 15, ( "  -> gluTessEndContour( tobj:%p )\n", tobj ) );
+    MSG( 15, "  -> gluTessEndContour( tobj:%p )\n", tobj );
     TESS_CHECK_ERRORS( tobj );
 
     if ( tobj->current_contour == NULL )
     {
        /* gluTessBeginContour was not called. */
-       DEBUGP( 0, ( "*** error 2 ***\n" ) );
        tess_error_callback( tobj, GLU_TESS_ERROR2 );
        return;
     }
@@ -316,11 +322,11 @@ void GLAPIENTRY gluTessEndContour( GLUtesselator *tobj )
     if ( tobj->current_contour->vertex_count > 0 ) {
        inspect_current_contour( tobj );
     } else {
-       delete_current_contour( tobj );
+       delete_contour( &tobj->current_contour );
     }
 
  cleanup:
-    DEBUGP( 15, ( "  <- gluTessEndContour( tobj:%p )\n", tobj ) );
+    MSG( 15, "  <- gluTessEndContour( tobj:%p )\n", tobj );
     return;
 }
 
@@ -330,13 +336,12 @@ void GLAPIENTRY gluTessEndContour( GLUtesselator *tobj )
  *****************************************************************************/
 void GLAPIENTRY gluTessEndPolygon( GLUtesselator *tobj )
 {
-    DEBUGP( 15, ( "-> gluTessEndPolygon( tobj:%p )\n", tobj ) );
+    MSG( 15, "-> gluTessEndPolygon( tobj:%p )\n", tobj );
     TESS_CHECK_ERRORS( tobj );
 
     if ( tobj->current_contour != NULL )
     {
        /* gluTessBeginPolygon was not called. */
-       DEBUGP( 0, ( "*** error 1 ***\n" ) );
        tess_error_callback( tobj, GLU_TESS_ERROR1 );
        return;
     }
@@ -375,7 +380,7 @@ void GLAPIENTRY gluTessEndPolygon( GLUtesselator *tobj )
 
  cleanup:
     delete_all_contours( tobj );
-    DEBUGP( 15, ( "<- gluTessEndPolygon( tobj:%p )\n", tobj ) );
+    MSG( 15, "<- gluTessEndPolygon( tobj:%p )\n", tobj );
 }
 
 
@@ -441,7 +446,7 @@ void GLAPIENTRY gluTessCallback( GLUtesselator *tobj, GLenum which,
        break;
 
     default:
-       DEBUGP( 0, ( "  gluTessCallback( tobj:%p which:%d ) invalid enum\n", tobj, which ) );
+       MSG( 1, "  gluTessCallback( tobj:%p which:%d ) invalid enum\n", tobj, which );
        tobj->error = GLU_INVALID_ENUM;
        break;
     }
@@ -463,7 +468,7 @@ void GLAPIENTRY gluTessProperty( GLUtesselator *tobj, GLenum which,
        break;
 
     case GLU_TESS_TOLERANCE:
-       DEBUGP( 15, ( "   gluTessProperty( tobj:%p ) tolerance: %0.9f\n", tobj, value ) );
+       MSG( 15, "   gluTessProperty( tobj:%p ) tolerance: %0.9f\n", tobj, value );
        tobj->tolerance = value;
        break;
 
@@ -472,7 +477,7 @@ void GLAPIENTRY gluTessProperty( GLUtesselator *tobj, GLenum which,
        break;
 
     default:
-       DEBUGP( 0, ( "   gluTessProperty( tobj:%p which:%d ) invalid enum\n", tobj, which ) );
+       MSG( 1, "   gluTessProperty( tobj:%p which:%d ) invalid enum\n", tobj, which );
        tobj->error = GLU_INVALID_ENUM;
        break;
     }
@@ -502,7 +507,7 @@ void GLAPIENTRY gluGetTessProperty( GLUtesselator *tobj, GLenum which,
        break;
 
     default:
-       DEBUGP( 0, ( "   gluGetTessProperty( tobj:%p which:%d ) invalid enum\n", tobj, which ) );
+       MSG( 1, "   gluGetTessProperty( tobj:%p which:%d ) invalid enum\n", tobj, which );
        tobj->error = GLU_INVALID_ENUM;
        break;
     }
@@ -517,7 +522,7 @@ void GLAPIENTRY gluGetTessProperty( GLUtesselator *tobj, GLenum which,
 void GLAPIENTRY gluTessNormal( GLUtesselator *tobj, GLdouble x,
                               GLdouble y, GLdouble z )
 {
-    DEBUGP( 15, ( "   gluTessNormal( tobj:%p n:(%.2f,%.2f,%.2f) )\n", tobj, x, y, z ) );
+    MSG( 15, "   gluTessNormal( tobj:%p n:(%.2f,%.2f,%.2f) )\n", tobj, x, y, z );
 
     tobj->plane.normal[X] = x;
     tobj->plane.normal[Y] = y;
@@ -615,16 +620,16 @@ static void init_callbacks( tess_callbacks_t *callbacks )
  *****************************************************************************/
 static void tess_cleanup( GLUtesselator *tobj )
 {
-    DEBUGP( 15, ( "  -> tess_cleanup( tobj:%p )\n", tobj ) );
+    MSG( 15, "  -> tess_cleanup( tobj:%p )\n", tobj );
 
     if ( tobj->current_contour != NULL ) {
-       delete_current_contour( tobj );
+       delete_contour( &tobj->current_contour );
     }
     if ( tobj->contours != NULL ) {
        delete_all_contours( tobj );
     }
 
-    DEBUGP( 15, ( "  <- tess_cleanup( tobj:%p )\n", tobj ) );
+    MSG( 15, "  <- tess_cleanup( tobj:%p )\n", tobj );
 }
 
 
@@ -640,12 +645,12 @@ static void inspect_current_contour( GLUtesselator *tobj )
     tess_contour_t *current = tobj->current_contour;
     GLdouble origin[3] = { 0.0, 0.0, 0.0 };
 
-    DEBUGP( 15, ( "    -> inspect_current_contour( tobj:%p )\n", tobj ) );
+    MSG( 15, "    -> inspect_current_contour( tobj:%p )\n", tobj );
 
     if ( current->vertex_count < 3 )
     {
-       DEBUGP( 15, ( "         count %d < 3, deleting\n", current->vertex_count ) );
-       delete_current_contour( tobj );
+       MSG( 15, "         count %d < 3, deleting\n", current->vertex_count );
+       delete_contour( &tobj->current_contour );
        return;
     }
 
@@ -664,7 +669,7 @@ static void inspect_current_contour( GLUtesselator *tobj )
     }
     else
     {
-       DEBUGP( 15, ( "         normal: (%.2f,%.2f,%.2f)\n", tobj->plane.normal[X], tobj->plane.normal[Y], tobj->plane.normal[Z] ) );
+       MSG( 15, "         normal: (%.2f,%.2f,%.2f)\n", tobj->plane.normal[X], tobj->plane.normal[Y], tobj->plane.normal[Z] );
     }
 
     project_current_contour( tobj );
@@ -673,7 +678,7 @@ static void inspect_current_contour( GLUtesselator *tobj )
        return;
     }
 
-    DEBUGP( 15, ( "    <- inspect_current_contour( tobj:%p )\n", tobj ) );
+    MSG( 15, "    <- inspect_current_contour( tobj:%p )\n", tobj );
 }
 
 /*****************************************************************************
@@ -685,7 +690,7 @@ static GLenum find_normal( GLUtesselator *tobj )
     tess_vertex_t      *va, *vb, *vc;
     GLdouble           a[3], b[3], c[3];
 
-    DEBUGP( 15, ( "      -> find_normal( tobj:%p )\n", tobj ) );
+    MSG( 15, "      -> find_normal( tobj:%p )\n", tobj );
 
     if ( contour == NULL ) { return GLU_ERROR; }
 
@@ -699,7 +704,7 @@ static GLenum find_normal( GLUtesselator *tobj )
     }
 
     if ( vb == va ) {
-       DEBUGP( 0, ( "*** error 7 ***\n" ) );
+       /* FIXME: What error is this? */
        tess_error_callback( tobj, GLU_TESS_ERROR7 );
     }
 
@@ -720,11 +725,11 @@ static GLenum find_normal( GLUtesselator *tobj )
 
            contour->plane.dist = - DOT3( contour->plane.normal, va->coords );
 
-           DEBUGP( 15, ( "      <- find_normal( tobj:%p ) n: (%.2f,%.2f,%.2f)\n", tobj, contour->plane.normal[X], contour->plane.normal[Y], contour->plane.normal[Z] ) );
+           MSG( 15, "      <- find_normal( tobj:%p ) n: (%.2f,%.2f,%.2f)\n", tobj, contour->plane.normal[X], contour->plane.normal[Y], contour->plane.normal[Z] );
            return GLU_NO_ERROR;
        }
     }
-    DEBUGP( 0, ( "*** error 7 ***\n" ) );
+    /* FIXME: What error is this? */
     tess_error_callback( tobj, GLU_TESS_ERROR7 );
 
     return GLU_ERROR;
@@ -745,7 +750,7 @@ static void project_current_contour( GLUtesselator *tobj )
     GLdouble           dot, rotx, roty;
     GLuint             i;
 
-    DEBUGP( 15, ( "      -> project_current_contour( tobj:%p )\n", tobj ) );
+    MSG( 15, "      -> project_current_contour( tobj:%p )\n", tobj );
 
     if ( current == NULL ) { return; }
 
@@ -807,7 +812,7 @@ static void project_current_contour( GLUtesselator *tobj )
        current->area = -area;
     }
 
-    DEBUGP( 15, ( "      <- project_current_contour( tobj:%p )\n", tobj ) );
+    MSG( 15, "      <- project_current_contour( tobj:%p )\n", tobj );
 }
 
 /*****************************************************************************
@@ -881,25 +886,28 @@ static GLenum save_current_contour( GLUtesselator *tobj )
 }
 
 /*****************************************************************************
- * delete_current_contour
+ * delete_contour
+ *
+ * Delete the given contour and set the pointer to NULL.
  *****************************************************************************/
-static void delete_current_contour( GLUtesselator *tobj )
+void delete_contour( tess_contour_t **contour )
 {
-    tess_contour_t     *current = tobj->current_contour;
     tess_vertex_t      *vertex, *next;
     GLuint             i;
 
-    if ( current == NULL ) { return; }
+    if ( *contour == NULL ) { return; }
+
+    vertex = (*contour)->vertices;
 
-    for ( vertex = current->vertices, i = 0; i < current->vertex_count; i++)
+    for ( i = 0 ; i < (*contour)->vertex_count ; i++ )
     {
        next = vertex->next;
        free( vertex );
        vertex = next;
     }
 
-    free( current );
-    tobj->current_contour = NULL;
+    free( *contour );
+    *contour = NULL;
 }
 
 /*****************************************************************************
@@ -907,11 +915,11 @@ static void delete_current_contour( GLUtesselator *tobj )
  *****************************************************************************/
 static void delete_all_contours( GLUtesselator *tobj )
 {
-    tess_contour_t     *current = tobj->current_contour, *next_contour;
+    tess_contour_t     *current, *next_contour;
     GLuint             i;
 
-    if ( current != NULL ) {
-       delete_current_contour( tobj );
+    if ( tobj->current_contour != NULL ) {
+       delete_contour( &tobj->current_contour );
     }
 
     for ( current = tobj->contours, i = 0 ; i < tobj->contour_count ; i++ )
@@ -941,22 +949,21 @@ static void delete_all_contours( GLUtesselator *tobj )
 }
 
 
-
-#ifdef DEBUG
-
 /*****************************************************************************
- * Debugging output
+ * tess_msg
  *****************************************************************************/
-int    tess_debug_level = 1;
-
-int vdebugstr( char *format_str, ... )
+INLINE void tess_msg( int level, char *format, ... )
 {
+#ifdef DEBUG
     va_list ap;
-    va_start( ap, format_str );
+    va_start( ap, format );
 
-    vfprintf( DEBUG_STREAM, format_str, ap );
-    va_end( ap );
-    return 0;
-}
+    if ( level <= tess_dbg_level ) {
+       /*fprintf( DBG_STREAM, "%9.9s:%d:\t ", __FILE__, __LINE__ );*/
+       vfprintf( DBG_STREAM, format, ap );
+       fflush( DBG_STREAM );
+    }
 
+    va_end( ap );
 #endif
+}
index 9b221908a57f27ad5ed6e859752a67fb4cdb66b2..f28923e34f6d372601db7f3cb8c4346a3a50aa9a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: tess.h,v 1.13 1999/10/13 19:12:47 gareth Exp $ */
+/* $Id: tess.h,v 1.14 1999/11/04 04:07:57 gareth Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -39,6 +39,7 @@
 #include "gluP.h"
 
 #include "tess_typedefs.h"
+#include "tess_macros.h"
 #include "tess_hash.h"
 #include "tess_heap.h"
 #if 0
@@ -84,36 +85,37 @@ extern void tess_error_callback( GLUtesselator *, GLenum );
 
 
 /*****************************************************************************
- * Debugging output:  (to be removed...)
+ * Debugging output:
  *****************************************************************************/
 #ifdef DEBUG
-extern int     tess_debug_level;
-int vdebugstr( char *format_str, ... );
+extern int     tess_dbg_level;
+
+#define DBG_LEVEL_BASE         1
+#define DBG_LEVEL_VERBOSE      10
+#define DBG_LEVEL_ENTEREXIT    20
 
-#pragma message( "tess: using DEBUGP for debugging output" )
 #ifdef _WIN32
-#define DEBUG_STREAM   stdout
+#define DBG_STREAM     stdout
 #else
-#define DEBUG_STREAM   stderr
+#define DBG_STREAM     stderr
 #endif
-#define DEBUGP( level, body )                                          \
-    do {                                                               \
-       if ( tess_debug_level >= level ) {                              \
-           vdebugstr( "%11.11s:%-5d ", __FILE__, __LINE__, level );    \
-           vdebugstr body;                                             \
-           fflush( DEBUG_STREAM );                                     \
-       }                                                               \
-    } while ( 0 )
-#define DEBUGIF( level )       do { if ( tess_debug_level >= level ) {
-#define DEBUGENDIF             } } while ( 0 )
 
+#ifdef __GNUC__
+#define MSG( level, format, args... )                                  \
+    if ( level <= tess_dbg_level ) {                                   \
+       fprintf( DBG_STREAM, "%9.9s:%d:\t ", __FILE__, __LINE__ );      \
+       fprintf( DBG_STREAM, format, ## args );                         \
+       fflush( DBG_STREAM );                                           \
+    }
 #else
+#define MSG            tess_msg
+#endif /* __GNUC__ */
 
-#define DEBUGP( level, body )
-#define DEBUGIF( level )       while(0) {
-#define DEBUGENDIF             }
+#else
+#define MSG            tess_msg
+#endif /* DEBUG */
 
-#endif
+extern INLINE void tess_msg( int level, char *format, ... );
 
 #ifdef __cplusplus
 }