40 #include "glimports.h"
42 #include "nurbsconsts.h"
43 #include "nurbstess.h"
46 #include "displaylist.h"
47 #include "knotvector.h"
50 #define THREAD( work, arg, cleanup ) \
53 dl->append( (PFVS)&NurbsTessellator::work, (void *) arg, (PFVS)&NurbsTessellator::cleanup );\
59 #define THREAD2( work ) \
61 dl->append( (PFVS)&NurbsTessellator::work, 0, 0 );\
69 subdivider( renderhints, backend ),
70 o_pwlcurvePool( sizeof(
O_pwlcurve ), 32,
"o_pwlcurvePool" ),
71 o_nurbscurvePool( sizeof(
O_nurbscurve ), 32,
"o_nurbscurvePool"),
72 o_curvePool( sizeof(
O_curve ), 32,
"o_curvePool" ),
73 o_trimPool( sizeof(
O_trim ), 32,
"o_trimPool" ),
74 o_surfacePool( sizeof(
O_surface ), 1,
"o_surfacePool" ),
75 o_nurbssurfacePool( sizeof(
O_nurbssurface ), 4,
"o_nurbssurfacePool" ),
76 propertyPool( sizeof(
Property ), 32,
"propertyPool" ),
77 quiltPool( sizeof(
Quilt ), 32,
"quiltPool" )
84 jumpbuffer = newJumpbuffer();
85 subdivider.setJumpbuffer( jumpbuffer );
88 NurbsTessellator::~NurbsTessellator(
void )
96 *nextNurbssurface = 0;
101 deleteJumpbuffer(jumpbuffer);
113 NurbsTessellator::bgnsurface(
long nuid )
116 o_surface->nuid = nuid;
117 THREAD( do_bgnsurface, o_surface, do_freebgnsurface );
127 NurbsTessellator::bgncurve(
long nuid )
130 o_curve->nuid = nuid;
131 THREAD( do_bgncurve, o_curve, do_freebgncurve );
141 NurbsTessellator::endcurve(
void )
143 THREAD2( do_endcurve );
153 NurbsTessellator::endsurface(
void )
155 THREAD2( do_endsurface );
166 NurbsTessellator::bgntrim(
void )
169 THREAD( do_bgntrim, o_trim, do_freebgntrim );
179 NurbsTessellator::endtrim(
void )
181 THREAD2( do_endtrim );
197 NurbsTessellator::pwlcurve(
long count, INREAL array[],
long byte_stride,
long type )
199 Mapdesc *mapdesc = maplist.locate( type );
207 if ( (type != N_P2D) && (type != N_P2DR) ) {
217 if( byte_stride < 0 ) {
224 if( mapdesc->isRational() ) {
226 INREAL x = p[0]; INREAL y = p[1]; INREAL w = p[2];
227 p = (INREAL *) (((
char *) p) + byte_stride);
228 for(
long i = 1; i != count; i++ ) {
229 if( p[0] == x && p[1] == y && p[2] == w )
break;
230 x = p[0]; y = p[1]; w = p[2];
231 p = (INREAL *) (((
char *) p) + byte_stride);
235 _glu_dprintf(
"point %d (%f,%f)\n", i, x, y );
241 INREAL x = p[0]; INREAL y = p[1];
242 p = (INREAL *) (((
char *) p) + byte_stride);
243 for(
long i = 1; i != count; i++ ) {
244 if( p[0] == x && p[1] == y )
break;
246 p = (INREAL *) (((
char *) p) + byte_stride);
250 _glu_dprintf(
"point %d (%f,%f)\n", i, x, y );
257 O_pwlcurve *o_pwlcurve =
new(o_pwlcurvePool)
O_pwlcurve( type, count, array, byte_stride, extTrimVertexPool.get((
int)count) );
258 THREAD( do_pwlcurve, o_pwlcurve, do_freepwlcurve );
269 NurbsTessellator::nurbscurve(
278 Mapdesc *mapdesc = maplist.locate( type );
286 if( ctlarray == 0 ) {
292 if( byte_stride < 0 ) {
300 knots.init( nknots, byte_stride, order, knot );
301 if( do_check_knots( &knots,
"curve" ) )
return;
304 o_nurbscurve->bezier_curves =
new(quiltPool)
Quilt(mapdesc);
305 o_nurbscurve->bezier_curves->toBezier( knots,ctlarray, mapdesc->getNcoords() );
307 THREAD( do_nurbscurve, o_nurbscurve, do_freenurbscurve );
318 NurbsTessellator::nurbssurface(
330 Mapdesc *mapdesc = maplist.locate( type );
338 if( s_byte_stride < 0 ) {
344 if( t_byte_stride < 0 ) {
352 sknotvector.init( sknot_count, s_byte_stride, sorder, sknot );
353 if( do_check_knots( &sknotvector,
"surface" ) )
return;
355 tknotvector.init( tknot_count, t_byte_stride, torder, tknot );
356 if( do_check_knots( &tknotvector,
"surface" ) )
return;
359 o_nurbssurface->bezier_patches =
new(quiltPool)
Quilt(mapdesc);
361 o_nurbssurface->bezier_patches->toBezier( sknotvector, tknotvector,
362 ctlarray, mapdesc->getNcoords() );
363 THREAD( do_nurbssurface, o_nurbssurface, do_freenurbssurface );
373 NurbsTessellator::setnurbsproperty(
long tag, INREAL value )
375 if( ! renderhints.isProperty( tag ) ) {
379 THREAD( do_setnurbsproperty, prop, do_freenurbsproperty );
389 NurbsTessellator::setnurbsproperty(
long type,
long tag, INREAL value )
391 Mapdesc *mapdesc = maplist.locate( type );
398 if( ! mapdesc->isProperty( tag ) ) {
404 THREAD( do_setnurbsproperty2, prop, do_freenurbsproperty );
415 NurbsTessellator::getnurbsproperty(
long tag, INREAL *value )
417 if( renderhints.isProperty( tag ) ) {
418 *value = renderhints.getProperty( tag );
431 NurbsTessellator::getnurbsproperty(
long type,
long tag, INREAL *value )
433 Mapdesc *mapdesc = maplist.locate( type );
438 if( mapdesc->isProperty( tag ) ) {
439 *value = mapdesc->getProperty( tag );
451 NurbsTessellator::setnurbsproperty(
long type,
long purpose, INREAL *mat )
454 Mapdesc *mapdesc = maplist.locate( type );
459 }
else if( purpose == N_BBOXSIZE ) {
460 mapdesc->setBboxsize( mat );
463 _glu_dprintf(
"ERRORRORRORR!!!\n");
474 NurbsTessellator::setnurbsproperty(
long type,
long purpose, INREAL *mat,
475 long rstride,
long cstride )
478 Mapdesc *mapdesc = maplist.locate( type );
483 }
else if( purpose == N_CULLINGMATRIX ) {
484 mapdesc->setCmat( mat, rstride, cstride );
485 }
else if( purpose == N_SAMPLINGMATRIX ) {
486 mapdesc->setSmat( mat, rstride, cstride );
487 }
else if( purpose == N_BBOXMATRIX ) {
488 mapdesc->setBmat( mat, rstride, cstride );
491 _glu_dprintf(
"ERRORRORRORR!!!\n");
497 NurbsTessellator::redefineMaps(
void )
499 maplist.initialize();
503 NurbsTessellator::defineMap(
long type,
long rational,
long ncoords )
505 maplist.define( type, (
int) rational, (
int) ncoords );
509 NurbsTessellator::discardRecording(
void *_dl )
515 NurbsTessellator::beginRecording(
void )
522 NurbsTessellator::endRecording(
void )
529 NurbsTessellator::playRecording(
void *_dl )