2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
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 );\
66 NurbsTessellator::NurbsTessellator( BasicCurveEvaluator
&c
, BasicSurfaceEvaluator
& e
)
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
);
106 /*-----------------------------------------------------------------------------
107 * bgnsurface - allocate and initialize an o_surface structure
110 *-----------------------------------------------------------------------------
113 NurbsTessellator::bgnsurface( long nuid
)
115 O_surface
*o_surface
= new(o_surfacePool
) O_surface
;
116 o_surface
->nuid
= nuid
;
117 THREAD( do_bgnsurface
, o_surface
, do_freebgnsurface
);
120 /*-----------------------------------------------------------------------------
121 * bgncurve - allocate an initialize an o_curve structure
124 *-----------------------------------------------------------------------------
127 NurbsTessellator::bgncurve( long nuid
)
129 O_curve
*o_curve
= new(o_curvePool
) O_curve
;
130 o_curve
->nuid
= nuid
;
131 THREAD( do_bgncurve
, o_curve
, do_freebgncurve
);
133 /*-----------------------------------------------------------------------------
137 *-----------------------------------------------------------------------------
141 NurbsTessellator::endcurve( void )
143 THREAD2( do_endcurve
);
146 /*-----------------------------------------------------------------------------
147 * endsurface - user level end of surface call
150 *-----------------------------------------------------------------------------
153 NurbsTessellator::endsurface( void )
155 THREAD2( do_endsurface
);
159 /*-----------------------------------------------------------------------------
160 * bgntrim - allocate and initialize a new trim loop structure (o_trim )
163 *-----------------------------------------------------------------------------
166 NurbsTessellator::bgntrim( void )
168 O_trim
*o_trim
= new(o_trimPool
) O_trim
;
169 THREAD( do_bgntrim
, o_trim
, do_freebgntrim
);
172 /*-----------------------------------------------------------------------------
176 *-----------------------------------------------------------------------------
179 NurbsTessellator::endtrim( void )
181 THREAD2( do_endtrim
);
185 /*-----------------------------------------------------------------------------
188 * count - number of points on curve
189 * array - array of points on curve
190 * byte_stride - distance between points in bytes
191 * type - valid data flag
194 *-----------------------------------------------------------------------------
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
);
262 /*-----------------------------------------------------------------------------
266 *-----------------------------------------------------------------------------
269 NurbsTessellator::nurbscurve(
270 long nknots
, /* number of p knots */
271 INREAL knot
[], /* nondecreasing knot values in p */
272 long byte_stride
, /* distance in bytes between control points */
273 INREAL ctlarray
[], /* pointer to first control point */
274 long order
, /* order of spline */
275 long type
) /* description of range space */
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;
303 O_nurbscurve
*o_nurbscurve
= new(o_nurbscurvePool
) O_nurbscurve(type
);
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
);
311 /*-----------------------------------------------------------------------------
314 * Client: User routine
315 *-----------------------------------------------------------------------------
318 NurbsTessellator::nurbssurface(
319 long sknot_count
, /* number of s knots */
320 INREAL sknot
[], /* nondecreasing knot values in s */
321 long tknot_count
, /* number of t knots */
322 INREAL tknot
[], /* nondecreasing knot values in t */
323 long s_byte_stride
, /* s step size in memory bytes */
324 long t_byte_stride
, /* t step size in memory bytes */
325 INREAL ctlarray
[], /* pointer to first control point */
326 long sorder
, /* order of the spline in s parameter */
327 long torder
, /* order of the spline in t parameter */
328 long type
) /* description of range space */
330 Mapdesc
*mapdesc
= maplist
.locate( type
);
338 if( s_byte_stride
< 0 ) {
344 if( t_byte_stride
< 0 ) {
350 Knotvector sknotvector
, tknotvector
;
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;
358 O_nurbssurface
*o_nurbssurface
= new(o_nurbssurfacePool
) O_nurbssurface(type
);
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
);
367 /*-----------------------------------------------------------------------------
370 *-----------------------------------------------------------------------------
373 NurbsTessellator::setnurbsproperty( long tag
, INREAL value
)
375 if( ! renderhints
.isProperty( tag
) ) {
378 Property
*prop
= new(propertyPool
) Property( tag
, value
);
379 THREAD( do_setnurbsproperty
, prop
, do_freenurbsproperty
);
383 /*-----------------------------------------------------------------------------
386 *-----------------------------------------------------------------------------
389 NurbsTessellator::setnurbsproperty( long type
, long tag
, INREAL value
)
391 Mapdesc
*mapdesc
= maplist
.locate( type
);
398 if( ! mapdesc
->isProperty( tag
) ) {
403 Property
*prop
= new(propertyPool
) Property( type
, tag
, value
);
404 THREAD( do_setnurbsproperty2
, prop
, do_freenurbsproperty
);
408 /*-----------------------------------------------------------------------------
411 *-----------------------------------------------------------------------------
415 NurbsTessellator::getnurbsproperty( long tag
, INREAL
*value
)
417 if( renderhints
.isProperty( tag
) ) {
418 *value
= renderhints
.getProperty( tag
);
424 /*-----------------------------------------------------------------------------
427 *-----------------------------------------------------------------------------
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
);
445 /*--------------------------------------------------------------------------
446 * setnurbsproperty - accept a user supplied matrix as culling or sampling mat
447 *--------------------------------------------------------------------------
451 NurbsTessellator::setnurbsproperty( long type
, long purpose
, INREAL
*mat
)
453 // XXX - cannot be put in display list
454 Mapdesc
*mapdesc
= maplist
.locate( type
);
459 } else if( purpose
== N_BBOXSIZE
) {
460 mapdesc
->setBboxsize( mat
);
463 _glu_dprintf( "ERRORRORRORR!!!\n");
468 /*--------------------------------------------------------------------------
469 * setnurbsproperty - accept a user supplied matrix as culling or sampling mat
470 *--------------------------------------------------------------------------
474 NurbsTessellator::setnurbsproperty( long type
, long purpose
, INREAL
*mat
,
475 long rstride
, long cstride
)
477 // XXX - cannot be put in display list
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
)
511 delete (DisplayList
*) _dl
;
515 NurbsTessellator::beginRecording( void )
517 dl
= new DisplayList( this );
522 NurbsTessellator::endRecording( void )
529 NurbsTessellator::playRecording( void *_dl
)
533 ((DisplayList
*)_dl
)->play();