-/* $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
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
+
/*****************************************************************************
*
{
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 ) {
tobj->error = GLU_NO_ERROR;
- DEBUGP( 15, ( "<- gluNewTess() tobj:%p\n", tobj ) );
+ MSG( 15, "<- gluNewTess() tobj:%p\n", tobj );
return tobj;
}
*****************************************************************************/
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 );
}
tess_cleanup( tobj );
free( tobj );
- DEBUGP( 15, ( "<- gluDeleteTess()\n" ) );
+ MSG( 15, "<- gluDeleteTess()\n" );
}
*****************************************************************************/
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 );
}
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 );
}
*****************************************************************************/
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;
}
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;
}
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;
}
}
cleanup:
- DEBUGP( 15, ( " <- gluTessVertex( tobj:%p )\n", tobj ) );
+ MSG( 15, " <- gluTessVertex( tobj:%p )\n", tobj );
return;
}
*****************************************************************************/
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;
}
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;
}
*****************************************************************************/
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;
}
cleanup:
delete_all_contours( tobj );
- DEBUGP( 15, ( "<- gluTessEndPolygon( tobj:%p )\n", tobj ) );
+ MSG( 15, "<- gluTessEndPolygon( tobj:%p )\n", tobj );
}
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;
}
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;
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;
}
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;
}
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;
*****************************************************************************/
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 );
}
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;
}
}
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 );
return;
}
- DEBUGP( 15, ( " <- inspect_current_contour( tobj:%p )\n", tobj ) );
+ MSG( 15, " <- inspect_current_contour( tobj:%p )\n", 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; }
}
if ( vb == va ) {
- DEBUGP( 0, ( "*** error 7 ***\n" ) );
+ /* FIXME: What error is this? */
tess_error_callback( tobj, GLU_TESS_ERROR7 );
}
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;
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; }
current->area = -area;
}
- DEBUGP( 15, ( " <- project_current_contour( tobj:%p )\n", tobj ) );
+ MSG( 15, " <- project_current_contour( tobj:%p )\n", 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;
}
/*****************************************************************************
*****************************************************************************/
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++ )
}
-
-#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
+}