1*c2c66affSColin Finck /*
2*c2c66affSColin Finck ** License Applicability. Except to the extent portions of this file are
3*c2c66affSColin Finck ** made subject to an alternative license as permitted in the SGI Free
4*c2c66affSColin Finck ** Software License B, Version 1.1 (the "License"), the contents of this
5*c2c66affSColin Finck ** file are subject only to the provisions of the License. You may not use
6*c2c66affSColin Finck ** this file except in compliance with the License. You may obtain a copy
7*c2c66affSColin Finck ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8*c2c66affSColin Finck ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
9*c2c66affSColin Finck **
10*c2c66affSColin Finck ** http://oss.sgi.com/projects/FreeB
11*c2c66affSColin Finck **
12*c2c66affSColin Finck ** Note that, as provided in the License, the Software is distributed on an
13*c2c66affSColin Finck ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14*c2c66affSColin Finck ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15*c2c66affSColin Finck ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16*c2c66affSColin Finck ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
17*c2c66affSColin Finck **
18*c2c66affSColin Finck ** Original Code. The Original Code is: OpenGL Sample Implementation,
19*c2c66affSColin Finck ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20*c2c66affSColin Finck ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21*c2c66affSColin Finck ** Copyright in any portions created by third parties is as indicated
22*c2c66affSColin Finck ** elsewhere herein. All Rights Reserved.
23*c2c66affSColin Finck **
24*c2c66affSColin Finck ** Additional Notice Provisions: The application programming interfaces
25*c2c66affSColin Finck ** established by SGI in conjunction with the Original Code are The
26*c2c66affSColin Finck ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27*c2c66affSColin Finck ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28*c2c66affSColin Finck ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29*c2c66affSColin Finck ** Window System(R) (Version 1.3), released October 19, 1998. This software
30*c2c66affSColin Finck ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31*c2c66affSColin Finck ** published by SGI, but has not been independently verified as being
32*c2c66affSColin Finck ** compliant with the OpenGL(R) version 1.2.1 Specification.
33*c2c66affSColin Finck */
34*c2c66affSColin Finck 
35*c2c66affSColin Finck /*
36*c2c66affSColin Finck  * nurbsinterfac.c++
37*c2c66affSColin Finck  *
38*c2c66affSColin Finck  */
39*c2c66affSColin Finck 
40*c2c66affSColin Finck //#include "glimports.h"
41*c2c66affSColin Finck //#include "mystdio.h"
42*c2c66affSColin Finck //#include "nurbsconsts.h"
43*c2c66affSColin Finck #include "nurbstess.h"
44*c2c66affSColin Finck //#include "bufpool.h"
45*c2c66affSColin Finck #include "quilt.h"
46*c2c66affSColin Finck #include "displaylist.h"
47*c2c66affSColin Finck #include "knotvector.h"
48*c2c66affSColin Finck #include "mapdesc.h"
49*c2c66affSColin Finck 
50*c2c66affSColin Finck #define THREAD( work, arg, cleanup ) \
51*c2c66affSColin Finck 	if( dl ) {\
52*c2c66affSColin Finck 	    arg->save = 1;\
53*c2c66affSColin Finck 	    dl->append( (PFVS)&NurbsTessellator::work, (void *) arg, (PFVS)&NurbsTessellator::cleanup );\
54*c2c66affSColin Finck  	} else {\
55*c2c66affSColin Finck 	    arg->save = 0;\
56*c2c66affSColin Finck 	    work( arg );\
57*c2c66affSColin Finck 	}
58*c2c66affSColin Finck 
59*c2c66affSColin Finck #define THREAD2( work ) \
60*c2c66affSColin Finck 	if( dl ) {\
61*c2c66affSColin Finck 	    dl->append( (PFVS)&NurbsTessellator::work, 0, 0 );\
62*c2c66affSColin Finck  	} else {\
63*c2c66affSColin Finck 	    work( );\
64*c2c66affSColin Finck 	}
65*c2c66affSColin Finck 
NurbsTessellator(BasicCurveEvaluator & c,BasicSurfaceEvaluator & e)66*c2c66affSColin Finck NurbsTessellator::NurbsTessellator( BasicCurveEvaluator &c, BasicSurfaceEvaluator& e)
67*c2c66affSColin Finck 	: maplist( backend ),
68*c2c66affSColin Finck 	  backend( c, e ),
69*c2c66affSColin Finck           subdivider( renderhints, backend ),
70*c2c66affSColin Finck 	  o_pwlcurvePool( sizeof( O_pwlcurve ), 32, "o_pwlcurvePool" ),
71*c2c66affSColin Finck 	  o_nurbscurvePool( sizeof( O_nurbscurve ), 32, "o_nurbscurvePool"),
72*c2c66affSColin Finck 	  o_curvePool( sizeof( O_curve ), 32,  "o_curvePool" ),
73*c2c66affSColin Finck 	  o_trimPool( sizeof( O_trim ), 32,  "o_trimPool" ),
74*c2c66affSColin Finck 	  o_surfacePool( sizeof( O_surface ), 1, "o_surfacePool" ),
75*c2c66affSColin Finck 	  o_nurbssurfacePool( sizeof( O_nurbssurface ), 4, "o_nurbssurfacePool" ),
76*c2c66affSColin Finck 	  propertyPool( sizeof( Property ), 32, "propertyPool" ),
77*c2c66affSColin Finck           quiltPool( sizeof( Quilt  ), 32, "quiltPool" )
78*c2c66affSColin Finck {
79*c2c66affSColin Finck     dl		= 0;
80*c2c66affSColin Finck     inSurface	= 0;
81*c2c66affSColin Finck     inCurve	= 0;
82*c2c66affSColin Finck     inTrim	= 0;
83*c2c66affSColin Finck     playBack	= 0;
84*c2c66affSColin Finck     jumpbuffer  = newJumpbuffer();
85*c2c66affSColin Finck     subdivider.setJumpbuffer( jumpbuffer );
86*c2c66affSColin Finck }
87*c2c66affSColin Finck 
~NurbsTessellator(void)88*c2c66affSColin Finck NurbsTessellator::~NurbsTessellator( void )
89*c2c66affSColin Finck {
90*c2c66affSColin Finck     if( inTrim ) {
91*c2c66affSColin Finck 	do_nurbserror( 12 );
92*c2c66affSColin Finck 	endtrim();
93*c2c66affSColin Finck     }
94*c2c66affSColin Finck 
95*c2c66affSColin Finck     if( inSurface ) {
96*c2c66affSColin Finck         *nextNurbssurface = 0;
97*c2c66affSColin Finck         do_freeall();
98*c2c66affSColin Finck     }
99*c2c66affSColin Finck 
100*c2c66affSColin Finck     if (jumpbuffer) {
101*c2c66affSColin Finck         deleteJumpbuffer(jumpbuffer);
102*c2c66affSColin Finck 	jumpbuffer= 0;
103*c2c66affSColin Finck     }
104*c2c66affSColin Finck }
105*c2c66affSColin Finck 
106*c2c66affSColin Finck /*-----------------------------------------------------------------------------
107*c2c66affSColin Finck  * bgnsurface - allocate and initialize an o_surface structure
108*c2c66affSColin Finck  *
109*c2c66affSColin Finck  * Client: GL user
110*c2c66affSColin Finck  *-----------------------------------------------------------------------------
111*c2c66affSColin Finck  */
112*c2c66affSColin Finck void
bgnsurface(long nuid)113*c2c66affSColin Finck NurbsTessellator::bgnsurface( long nuid )
114*c2c66affSColin Finck {
115*c2c66affSColin Finck     O_surface *o_surface = new(o_surfacePool) O_surface;
116*c2c66affSColin Finck     o_surface->nuid = nuid;
117*c2c66affSColin Finck     THREAD( do_bgnsurface, o_surface, do_freebgnsurface );
118*c2c66affSColin Finck }
119*c2c66affSColin Finck 
120*c2c66affSColin Finck /*-----------------------------------------------------------------------------
121*c2c66affSColin Finck  * bgncurve - allocate an initialize an o_curve structure
122*c2c66affSColin Finck  *
123*c2c66affSColin Finck  * Client: GL user
124*c2c66affSColin Finck  *-----------------------------------------------------------------------------
125*c2c66affSColin Finck  */
126*c2c66affSColin Finck void
bgncurve(long nuid)127*c2c66affSColin Finck NurbsTessellator::bgncurve( long nuid )
128*c2c66affSColin Finck {
129*c2c66affSColin Finck     O_curve *o_curve = new(o_curvePool) O_curve;
130*c2c66affSColin Finck     o_curve->nuid = nuid;
131*c2c66affSColin Finck     THREAD( do_bgncurve, o_curve, do_freebgncurve );
132*c2c66affSColin Finck }
133*c2c66affSColin Finck /*-----------------------------------------------------------------------------
134*c2c66affSColin Finck  * endcurve -
135*c2c66affSColin Finck  *
136*c2c66affSColin Finck  * Client:
137*c2c66affSColin Finck  *-----------------------------------------------------------------------------
138*c2c66affSColin Finck  */
139*c2c66affSColin Finck 
140*c2c66affSColin Finck void
endcurve(void)141*c2c66affSColin Finck NurbsTessellator::endcurve( void )
142*c2c66affSColin Finck {
143*c2c66affSColin Finck     THREAD2( do_endcurve );
144*c2c66affSColin Finck }
145*c2c66affSColin Finck 
146*c2c66affSColin Finck /*-----------------------------------------------------------------------------
147*c2c66affSColin Finck  * endsurface - user level end of surface call
148*c2c66affSColin Finck  *
149*c2c66affSColin Finck  * Client: GL user
150*c2c66affSColin Finck  *-----------------------------------------------------------------------------
151*c2c66affSColin Finck  */
152*c2c66affSColin Finck void
endsurface(void)153*c2c66affSColin Finck NurbsTessellator::endsurface( void )
154*c2c66affSColin Finck {
155*c2c66affSColin Finck     THREAD2( do_endsurface );
156*c2c66affSColin Finck }
157*c2c66affSColin Finck 
158*c2c66affSColin Finck 
159*c2c66affSColin Finck /*-----------------------------------------------------------------------------
160*c2c66affSColin Finck  * bgntrim - allocate and initialize a new trim loop structure (o_trim )
161*c2c66affSColin Finck  *
162*c2c66affSColin Finck  * Client: GL user
163*c2c66affSColin Finck  *-----------------------------------------------------------------------------
164*c2c66affSColin Finck  */
165*c2c66affSColin Finck void
bgntrim(void)166*c2c66affSColin Finck NurbsTessellator::bgntrim( void )
167*c2c66affSColin Finck {
168*c2c66affSColin Finck     O_trim *o_trim = new(o_trimPool) O_trim;
169*c2c66affSColin Finck     THREAD( do_bgntrim, o_trim, do_freebgntrim );
170*c2c66affSColin Finck }
171*c2c66affSColin Finck 
172*c2c66affSColin Finck /*-----------------------------------------------------------------------------
173*c2c66affSColin Finck  * endtrim -
174*c2c66affSColin Finck  *
175*c2c66affSColin Finck  * Client: GL user
176*c2c66affSColin Finck  *-----------------------------------------------------------------------------
177*c2c66affSColin Finck  */
178*c2c66affSColin Finck void
endtrim(void)179*c2c66affSColin Finck NurbsTessellator::endtrim( void )
180*c2c66affSColin Finck {
181*c2c66affSColin Finck     THREAD2( do_endtrim );
182*c2c66affSColin Finck }
183*c2c66affSColin Finck 
184*c2c66affSColin Finck 
185*c2c66affSColin Finck /*-----------------------------------------------------------------------------
186*c2c66affSColin Finck  * pwlcurve -
187*c2c66affSColin Finck  *
188*c2c66affSColin Finck  *      count        - number of points on curve
189*c2c66affSColin Finck  *      array        - array of points on curve
190*c2c66affSColin Finck  *      byte_stride  - distance between points in bytes
191*c2c66affSColin Finck  *      type         - valid data flag
192*c2c66affSColin Finck  *
193*c2c66affSColin Finck  * Client: Gl user
194*c2c66affSColin Finck  *-----------------------------------------------------------------------------
195*c2c66affSColin Finck  */
196*c2c66affSColin Finck void
pwlcurve(long count,INREAL array[],long byte_stride,long type)197*c2c66affSColin Finck NurbsTessellator::pwlcurve( long count, INREAL array[], long byte_stride, long type )
198*c2c66affSColin Finck {
199*c2c66affSColin Finck     Mapdesc *mapdesc = maplist.locate( type );
200*c2c66affSColin Finck 
201*c2c66affSColin Finck     if( mapdesc == 0 ) {
202*c2c66affSColin Finck 	do_nurbserror( 35 );
203*c2c66affSColin Finck 	isDataValid = 0;
204*c2c66affSColin Finck 	return;
205*c2c66affSColin Finck     }
206*c2c66affSColin Finck 
207*c2c66affSColin Finck     if ( (type != N_P2D) && (type != N_P2DR) ) {
208*c2c66affSColin Finck 	do_nurbserror( 22 );
209*c2c66affSColin Finck 	isDataValid = 0;
210*c2c66affSColin Finck 	return;
211*c2c66affSColin Finck     }
212*c2c66affSColin Finck     if( count < 0 ) {
213*c2c66affSColin Finck 	do_nurbserror( 33 );
214*c2c66affSColin Finck 	isDataValid = 0;
215*c2c66affSColin Finck 	return;
216*c2c66affSColin Finck     }
217*c2c66affSColin Finck     if( byte_stride < 0 ) {
218*c2c66affSColin Finck 	do_nurbserror( 34 );
219*c2c66affSColin Finck 	isDataValid = 0;
220*c2c66affSColin Finck 	return;
221*c2c66affSColin Finck     }
222*c2c66affSColin Finck 
223*c2c66affSColin Finck #ifdef NOTDEF
224*c2c66affSColin Finck     if( mapdesc->isRational() ) {
225*c2c66affSColin Finck 	INREAL *p = array;
226*c2c66affSColin Finck 	INREAL x = p[0]; INREAL y = p[1]; INREAL w = p[2];
227*c2c66affSColin Finck 	p = (INREAL *) (((char *) p) + byte_stride);
228*c2c66affSColin Finck 	for( long i = 1; i != count; i++ ) {
229*c2c66affSColin Finck 	    if( p[0] == x && p[1] == y && p[2] == w ) break;
230*c2c66affSColin Finck 	    x = p[0]; y = p[1]; w = p[2];
231*c2c66affSColin Finck 	    p = (INREAL *) (((char *) p) + byte_stride);
232*c2c66affSColin Finck 	}
233*c2c66affSColin Finck 	if( i != count ) {
234*c2c66affSColin Finck 	    do_nurbserror( 37 );
235*c2c66affSColin Finck 	    _glu_dprintf( "point %d (%f,%f)\n", i, x, y );
236*c2c66affSColin Finck 	    isDataValid = 0;
237*c2c66affSColin Finck 	    return;
238*c2c66affSColin Finck 	}
239*c2c66affSColin Finck     } else {
240*c2c66affSColin Finck 	INREAL *p = array;
241*c2c66affSColin Finck 	INREAL x = p[0]; INREAL y = p[1];
242*c2c66affSColin Finck 	p = (INREAL *) (((char *) p) + byte_stride);
243*c2c66affSColin Finck 	for( long i = 1; i != count; i++ ) {
244*c2c66affSColin Finck 	    if( p[0] == x && p[1] == y ) break;
245*c2c66affSColin Finck 	    x = p[0]; y = p[1];
246*c2c66affSColin Finck 	    p = (INREAL *) (((char *) p) + byte_stride);
247*c2c66affSColin Finck 	}
248*c2c66affSColin Finck 	if( i != count ) {
249*c2c66affSColin Finck 	    do_nurbserror( 37 );
250*c2c66affSColin Finck 	    _glu_dprintf( "point %d (%f,%f)\n", i, x, y );
251*c2c66affSColin Finck 	    isDataValid = 0;
252*c2c66affSColin Finck 	    return;
253*c2c66affSColin Finck 	}
254*c2c66affSColin Finck     }
255*c2c66affSColin Finck #endif
256*c2c66affSColin Finck 
257*c2c66affSColin Finck     O_pwlcurve	*o_pwlcurve = new(o_pwlcurvePool) O_pwlcurve( type, count, array, byte_stride, extTrimVertexPool.get((int)count) );
258*c2c66affSColin Finck     THREAD( do_pwlcurve, o_pwlcurve, do_freepwlcurve );
259*c2c66affSColin Finck }
260*c2c66affSColin Finck 
261*c2c66affSColin Finck 
262*c2c66affSColin Finck /*-----------------------------------------------------------------------------
263*c2c66affSColin Finck  * nurbscurve -
264*c2c66affSColin Finck  *
265*c2c66affSColin Finck  * Client: GL user
266*c2c66affSColin Finck  *-----------------------------------------------------------------------------
267*c2c66affSColin Finck  */
268*c2c66affSColin Finck void
nurbscurve(long nknots,INREAL knot[],long byte_stride,INREAL ctlarray[],long order,long type)269*c2c66affSColin Finck NurbsTessellator::nurbscurve(
270*c2c66affSColin Finck     long nknots, 		/* number of p knots */
271*c2c66affSColin Finck     INREAL knot[], 		/* nondecreasing knot values in p */
272*c2c66affSColin Finck     long byte_stride,		/* distance in bytes between control points */
273*c2c66affSColin Finck     INREAL ctlarray[], 		/* pointer to first control point */
274*c2c66affSColin Finck     long order,			/* order of spline */
275*c2c66affSColin Finck     long type )			/* description of range space */
276*c2c66affSColin Finck {
277*c2c66affSColin Finck 
278*c2c66affSColin Finck     Mapdesc *mapdesc = maplist.locate( type );
279*c2c66affSColin Finck 
280*c2c66affSColin Finck     if( mapdesc == 0 ) {
281*c2c66affSColin Finck 	do_nurbserror( 35 );
282*c2c66affSColin Finck 	isDataValid = 0;
283*c2c66affSColin Finck 	return;
284*c2c66affSColin Finck     }
285*c2c66affSColin Finck 
286*c2c66affSColin Finck     if( ctlarray == 0 ) {
287*c2c66affSColin Finck 	do_nurbserror( 36 );
288*c2c66affSColin Finck 	isDataValid = 0;
289*c2c66affSColin Finck 	return;
290*c2c66affSColin Finck     }
291*c2c66affSColin Finck 
292*c2c66affSColin Finck     if( byte_stride < 0 ) {
293*c2c66affSColin Finck 	do_nurbserror( 34 );
294*c2c66affSColin Finck 	isDataValid = 0;
295*c2c66affSColin Finck 	return;
296*c2c66affSColin Finck     }
297*c2c66affSColin Finck 
298*c2c66affSColin Finck     Knotvector knots;
299*c2c66affSColin Finck 
300*c2c66affSColin Finck     knots.init( nknots, byte_stride, order, knot );
301*c2c66affSColin Finck     if( do_check_knots( &knots, "curve" ) ) return;
302*c2c66affSColin Finck 
303*c2c66affSColin Finck     O_nurbscurve *o_nurbscurve = new(o_nurbscurvePool) O_nurbscurve(type);
304*c2c66affSColin Finck     o_nurbscurve->bezier_curves = new(quiltPool) Quilt(mapdesc);
305*c2c66affSColin Finck     o_nurbscurve->bezier_curves->toBezier( knots,ctlarray, mapdesc->getNcoords() );
306*c2c66affSColin Finck 
307*c2c66affSColin Finck     THREAD( do_nurbscurve, o_nurbscurve, do_freenurbscurve );
308*c2c66affSColin Finck }
309*c2c66affSColin Finck 
310*c2c66affSColin Finck 
311*c2c66affSColin Finck /*-----------------------------------------------------------------------------
312*c2c66affSColin Finck  * nurbssurface -
313*c2c66affSColin Finck  *
314*c2c66affSColin Finck  * Client: User routine
315*c2c66affSColin Finck  *-----------------------------------------------------------------------------
316*c2c66affSColin Finck  */
317*c2c66affSColin Finck void
nurbssurface(long sknot_count,INREAL sknot[],long tknot_count,INREAL tknot[],long s_byte_stride,long t_byte_stride,INREAL ctlarray[],long sorder,long torder,long type)318*c2c66affSColin Finck NurbsTessellator::nurbssurface(
319*c2c66affSColin Finck     long sknot_count,		/* number of s knots */
320*c2c66affSColin Finck     INREAL sknot[],		/* nondecreasing knot values in s */
321*c2c66affSColin Finck     long tknot_count, 		/* number of t knots */
322*c2c66affSColin Finck     INREAL tknot[],		/* nondecreasing knot values in t */
323*c2c66affSColin Finck     long s_byte_stride,		/* s step size in memory bytes */
324*c2c66affSColin Finck     long t_byte_stride,		/* t step size in memory bytes */
325*c2c66affSColin Finck     INREAL ctlarray[],		/* pointer to first control point */
326*c2c66affSColin Finck     long sorder,		/* order of the spline in s parameter */
327*c2c66affSColin Finck     long torder,		/* order of the spline in t parameter */
328*c2c66affSColin Finck     long type)			/* description of range space */
329*c2c66affSColin Finck {
330*c2c66affSColin Finck     Mapdesc *mapdesc = maplist.locate( type );
331*c2c66affSColin Finck 
332*c2c66affSColin Finck     if( mapdesc == 0 ) {
333*c2c66affSColin Finck 	do_nurbserror( 35 );
334*c2c66affSColin Finck 	isDataValid = 0;
335*c2c66affSColin Finck 	return;
336*c2c66affSColin Finck     }
337*c2c66affSColin Finck 
338*c2c66affSColin Finck     if( s_byte_stride < 0 ) {
339*c2c66affSColin Finck 	do_nurbserror( 34 );
340*c2c66affSColin Finck 	isDataValid = 0;
341*c2c66affSColin Finck 	return;
342*c2c66affSColin Finck     }
343*c2c66affSColin Finck 
344*c2c66affSColin Finck     if( t_byte_stride < 0 ) {
345*c2c66affSColin Finck 	do_nurbserror( 34 );
346*c2c66affSColin Finck 	isDataValid = 0;
347*c2c66affSColin Finck 	return;
348*c2c66affSColin Finck     }
349*c2c66affSColin Finck 
350*c2c66affSColin Finck     Knotvector sknotvector, tknotvector;
351*c2c66affSColin Finck 
352*c2c66affSColin Finck     sknotvector.init( sknot_count, s_byte_stride, sorder, sknot );
353*c2c66affSColin Finck     if( do_check_knots( &sknotvector, "surface" ) ) return;
354*c2c66affSColin Finck 
355*c2c66affSColin Finck     tknotvector.init( tknot_count, t_byte_stride, torder, tknot );
356*c2c66affSColin Finck     if( do_check_knots( &tknotvector, "surface" ) ) return;
357*c2c66affSColin Finck 
358*c2c66affSColin Finck     O_nurbssurface *o_nurbssurface = new(o_nurbssurfacePool) O_nurbssurface(type);
359*c2c66affSColin Finck     o_nurbssurface->bezier_patches = new(quiltPool) Quilt(mapdesc);
360*c2c66affSColin Finck 
361*c2c66affSColin Finck     o_nurbssurface->bezier_patches->toBezier( sknotvector, tknotvector,
362*c2c66affSColin Finck 	ctlarray, mapdesc->getNcoords() );
363*c2c66affSColin Finck     THREAD( do_nurbssurface, o_nurbssurface, do_freenurbssurface );
364*c2c66affSColin Finck }
365*c2c66affSColin Finck 
366*c2c66affSColin Finck 
367*c2c66affSColin Finck /*-----------------------------------------------------------------------------
368*c2c66affSColin Finck  * setnurbsproperty -
369*c2c66affSColin Finck  *
370*c2c66affSColin Finck  *-----------------------------------------------------------------------------
371*c2c66affSColin Finck  */
372*c2c66affSColin Finck void
setnurbsproperty(long tag,INREAL value)373*c2c66affSColin Finck NurbsTessellator::setnurbsproperty( long tag, INREAL value )
374*c2c66affSColin Finck {
375*c2c66affSColin Finck     if( ! renderhints.isProperty( tag ) ) {
376*c2c66affSColin Finck 	do_nurbserror( 26 );
377*c2c66affSColin Finck     } else {
378*c2c66affSColin Finck 	Property *prop = new(propertyPool) Property( tag, value );
379*c2c66affSColin Finck 	THREAD( do_setnurbsproperty, prop, do_freenurbsproperty );
380*c2c66affSColin Finck     }
381*c2c66affSColin Finck }
382*c2c66affSColin Finck 
383*c2c66affSColin Finck /*-----------------------------------------------------------------------------
384*c2c66affSColin Finck  * setnurbsproperty -
385*c2c66affSColin Finck  *
386*c2c66affSColin Finck  *-----------------------------------------------------------------------------
387*c2c66affSColin Finck  */
388*c2c66affSColin Finck void
setnurbsproperty(long type,long tag,INREAL value)389*c2c66affSColin Finck NurbsTessellator::setnurbsproperty( long type, long tag, INREAL value )
390*c2c66affSColin Finck {
391*c2c66affSColin Finck     Mapdesc *mapdesc = maplist.locate( type );
392*c2c66affSColin Finck 
393*c2c66affSColin Finck     if( mapdesc == 0 ) {
394*c2c66affSColin Finck 	do_nurbserror( 35 );
395*c2c66affSColin Finck 	return;
396*c2c66affSColin Finck     }
397*c2c66affSColin Finck 
398*c2c66affSColin Finck     if( ! mapdesc->isProperty( tag ) ) {
399*c2c66affSColin Finck 	do_nurbserror( 26 );
400*c2c66affSColin Finck 	return;
401*c2c66affSColin Finck     }
402*c2c66affSColin Finck 
403*c2c66affSColin Finck     Property *prop = new(propertyPool) Property( type, tag, value );
404*c2c66affSColin Finck     THREAD( do_setnurbsproperty2, prop, do_freenurbsproperty );
405*c2c66affSColin Finck }
406*c2c66affSColin Finck 
407*c2c66affSColin Finck 
408*c2c66affSColin Finck /*-----------------------------------------------------------------------------
409*c2c66affSColin Finck  * getnurbsproperty -
410*c2c66affSColin Finck  *
411*c2c66affSColin Finck  *-----------------------------------------------------------------------------
412*c2c66affSColin Finck  */
413*c2c66affSColin Finck 
414*c2c66affSColin Finck void
getnurbsproperty(long tag,INREAL * value)415*c2c66affSColin Finck NurbsTessellator::getnurbsproperty( long tag, INREAL *value )
416*c2c66affSColin Finck {
417*c2c66affSColin Finck     if( renderhints.isProperty( tag ) ) {
418*c2c66affSColin Finck 	*value = renderhints.getProperty( tag );
419*c2c66affSColin Finck     } else {
420*c2c66affSColin Finck 	do_nurbserror( 26 );
421*c2c66affSColin Finck     }
422*c2c66affSColin Finck }
423*c2c66affSColin Finck 
424*c2c66affSColin Finck /*-----------------------------------------------------------------------------
425*c2c66affSColin Finck  * getnurbsproperty -
426*c2c66affSColin Finck  *
427*c2c66affSColin Finck  *-----------------------------------------------------------------------------
428*c2c66affSColin Finck  */
429*c2c66affSColin Finck 
430*c2c66affSColin Finck void
getnurbsproperty(long type,long tag,INREAL * value)431*c2c66affSColin Finck NurbsTessellator::getnurbsproperty( long type, long tag, INREAL *value )
432*c2c66affSColin Finck {
433*c2c66affSColin Finck     Mapdesc *mapdesc = maplist.locate( type );
434*c2c66affSColin Finck 
435*c2c66affSColin Finck     if( mapdesc == 0 )
436*c2c66affSColin Finck 	do_nurbserror( 35 );
437*c2c66affSColin Finck 
438*c2c66affSColin Finck     if( mapdesc->isProperty( tag  ) ) {
439*c2c66affSColin Finck 	*value = mapdesc->getProperty( tag );
440*c2c66affSColin Finck     } else {
441*c2c66affSColin Finck 	do_nurbserror( 26 );
442*c2c66affSColin Finck     }
443*c2c66affSColin Finck }
444*c2c66affSColin Finck 
445*c2c66affSColin Finck /*--------------------------------------------------------------------------
446*c2c66affSColin Finck  * setnurbsproperty - accept a user supplied matrix as culling or sampling mat
447*c2c66affSColin Finck  *--------------------------------------------------------------------------
448*c2c66affSColin Finck  */
449*c2c66affSColin Finck 
450*c2c66affSColin Finck void
setnurbsproperty(long type,long purpose,INREAL * mat)451*c2c66affSColin Finck NurbsTessellator::setnurbsproperty( long type, long purpose, INREAL *mat )
452*c2c66affSColin Finck {
453*c2c66affSColin Finck     // XXX - cannot be put in display list
454*c2c66affSColin Finck     Mapdesc *mapdesc = maplist.locate( type );
455*c2c66affSColin Finck 
456*c2c66affSColin Finck     if( mapdesc == 0 ) {
457*c2c66affSColin Finck 	do_nurbserror( 35 );
458*c2c66affSColin Finck 	isDataValid = 0;
459*c2c66affSColin Finck     } else if( purpose == N_BBOXSIZE ) {
460*c2c66affSColin Finck 	mapdesc->setBboxsize( mat );
461*c2c66affSColin Finck     } else {
462*c2c66affSColin Finck #ifndef NDEBUG
463*c2c66affSColin Finck         _glu_dprintf( "ERRORRORRORR!!!\n");
464*c2c66affSColin Finck #endif
465*c2c66affSColin Finck     }
466*c2c66affSColin Finck }
467*c2c66affSColin Finck 
468*c2c66affSColin Finck /*--------------------------------------------------------------------------
469*c2c66affSColin Finck  * setnurbsproperty - accept a user supplied matrix as culling or sampling mat
470*c2c66affSColin Finck  *--------------------------------------------------------------------------
471*c2c66affSColin Finck  */
472*c2c66affSColin Finck 
473*c2c66affSColin Finck void
setnurbsproperty(long type,long purpose,INREAL * mat,long rstride,long cstride)474*c2c66affSColin Finck NurbsTessellator::setnurbsproperty( long type, long purpose, INREAL *mat,
475*c2c66affSColin Finck     long rstride, long cstride )
476*c2c66affSColin Finck {
477*c2c66affSColin Finck     // XXX - cannot be put in display list
478*c2c66affSColin Finck     Mapdesc *mapdesc = maplist.locate( type );
479*c2c66affSColin Finck 
480*c2c66affSColin Finck     if( mapdesc == 0 ) {
481*c2c66affSColin Finck 	do_nurbserror( 35 );
482*c2c66affSColin Finck 	isDataValid = 0;
483*c2c66affSColin Finck     } else if( purpose == N_CULLINGMATRIX ) {
484*c2c66affSColin Finck 	mapdesc->setCmat( mat, rstride, cstride );
485*c2c66affSColin Finck     } else if( purpose == N_SAMPLINGMATRIX ) {
486*c2c66affSColin Finck 	mapdesc->setSmat( mat, rstride, cstride );
487*c2c66affSColin Finck     } else if( purpose == N_BBOXMATRIX ) {
488*c2c66affSColin Finck 	mapdesc->setBmat( mat, rstride, cstride );
489*c2c66affSColin Finck     } else {
490*c2c66affSColin Finck #ifndef NDEBUG
491*c2c66affSColin Finck         _glu_dprintf( "ERRORRORRORR!!!\n");
492*c2c66affSColin Finck #endif
493*c2c66affSColin Finck     }
494*c2c66affSColin Finck }
495*c2c66affSColin Finck 
496*c2c66affSColin Finck void
redefineMaps(void)497*c2c66affSColin Finck NurbsTessellator::redefineMaps( void )
498*c2c66affSColin Finck {
499*c2c66affSColin Finck     maplist.initialize();
500*c2c66affSColin Finck }
501*c2c66affSColin Finck 
502*c2c66affSColin Finck void
defineMap(long type,long rational,long ncoords)503*c2c66affSColin Finck NurbsTessellator::defineMap( long type, long rational, long ncoords )
504*c2c66affSColin Finck {
505*c2c66affSColin Finck     maplist.define( type, (int) rational, (int) ncoords );
506*c2c66affSColin Finck }
507*c2c66affSColin Finck 
508*c2c66affSColin Finck void
discardRecording(void * _dl)509*c2c66affSColin Finck NurbsTessellator::discardRecording( void *_dl )
510*c2c66affSColin Finck {
511*c2c66affSColin Finck     delete (DisplayList *) _dl;
512*c2c66affSColin Finck }
513*c2c66affSColin Finck 
514*c2c66affSColin Finck void *
beginRecording(void)515*c2c66affSColin Finck NurbsTessellator::beginRecording( void )
516*c2c66affSColin Finck {
517*c2c66affSColin Finck     dl = new DisplayList( this );
518*c2c66affSColin Finck     return (void *) dl;
519*c2c66affSColin Finck }
520*c2c66affSColin Finck 
521*c2c66affSColin Finck void
endRecording(void)522*c2c66affSColin Finck NurbsTessellator::endRecording( void )
523*c2c66affSColin Finck {
524*c2c66affSColin Finck     dl->endList();
525*c2c66affSColin Finck     dl = 0;
526*c2c66affSColin Finck }
527*c2c66affSColin Finck 
528*c2c66affSColin Finck void
playRecording(void * _dl)529*c2c66affSColin Finck NurbsTessellator::playRecording( void *_dl )
530*c2c66affSColin Finck {
531*c2c66affSColin Finck     playBack = 1;
532*c2c66affSColin Finck     bgnrender();
533*c2c66affSColin Finck     ((DisplayList *)_dl)->play();
534*c2c66affSColin Finck     endrender();
535*c2c66affSColin Finck     playBack = 0;
536*c2c66affSColin Finck }
537*c2c66affSColin Finck 
538