source: trunk/src/opengl/glu/nurbs/internals/nurbstess.cpp

Last change on this file was 2689, checked in by jeroen, 26 years ago

* empty log message *

File size: 16.6 KB
Line 
1/* $Id: nurbstess.cpp,v 1.1 2000-02-09 08:50:26 jeroen Exp $ */
2/*
3** License Applicability. Except to the extent portions of this file are
4** made subject to an alternative license as permitted in the SGI Free
5** Software License B, Version 1.0 (the "License"), the contents of this
6** file are subject only to the provisions of the License. You may not use
7** this file except in compliance with the License. You may obtain a copy
8** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10**
11** http://oss.sgi.com/projects/FreeB
12**
13** Note that, as provided in the License, the Software is distributed on an
14** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18**
19** Original Code. The Original Code is: OpenGL Sample Implementation,
20** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22** Copyright in any portions created by third parties is as indicated
23** elsewhere herein. All Rights Reserved.
24**
25** Additional Notice Provisions: The application programming interfaces
26** established by SGI in conjunction with the Original Code are The
27** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30** Window System(R) (Version 1.3), released October 19, 1998. This software
31** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32** published by SGI, but has not been independently verified as being
33** compliant with the OpenGL(R) version 1.2.1 Specification.
34*/
35
36/*
37 * nurbstess.c++
38 *
39 * $Date: 2000-02-09 08:50:26 $ $Revision: 1.1 $
40 * $Header: /home/ktk/tmp/odin/2007/netlabs.cvs/odin32/src/opengl/glu/nurbs/internals/nurbstess.cpp,v 1.1 2000-02-09 08:50:26 jeroen Exp $
41 */
42
43#include "glimports.h"
44#include "myassert.h"
45#include "mysetjmp.h"
46#include "mystdio.h"
47#include "nurbsconsts.h"
48#include "nurbstess.h"
49#include "bufpool.h"
50#include "quilt.h"
51#include "knotvector.h"
52#include "mapdesc.h"
53#include "maplist.h"
54
55void
56NurbsTessellator::set_domain_distance_u_rate(REAL u_rate)
57{
58 subdivider.set_domain_distance_u_rate(u_rate);
59}
60
61void
62NurbsTessellator::set_domain_distance_v_rate(REAL v_rate)
63{
64 subdivider.set_domain_distance_v_rate(v_rate);
65}
66
67void
68NurbsTessellator::set_is_domain_distance_sampling(int flag)
69{
70 subdivider.set_is_domain_distance_sampling(flag);
71}
72
73void
74NurbsTessellator::resetObjects( void )
75{
76 subdivider.clear();
77}
78
79void
80NurbsTessellator::makeobj( int )
81{
82#ifndef NDEBUG
83 dprintf( "makeobj\n" );
84#endif
85}
86
87void
88NurbsTessellator::closeobj( void )
89{
90#ifndef NDEBUG
91 dprintf( "closeobj\n" );
92#endif
93}
94
95void
96NurbsTessellator::bgnrender( void )
97{
98#ifndef NDEBUG
99 dprintf( "bgnrender\n" );
100#endif
101}
102
103void
104NurbsTessellator::endrender( void )
105{
106#ifndef NDEBUG
107 dprintf( "endrender\n" );
108#endif
109}
110
111/*-----------------------------------------------------------------------------
112 * do_freebgnsurface - free o_surface structure
113 *
114 * Client: do_freeall(), bgnsurface()
115 *-----------------------------------------------------------------------------
116 */
117void
118NurbsTessellator::do_freebgnsurface( O_surface *o_surface )
119{
120 o_surface->deleteMe( o_surfacePool );
121}
122
123
124/*-----------------------------------------------------------------------------
125 * do_bgnsurface - begin the display of a surface
126 *
127 * Client: bgnsurface()
128 *-----------------------------------------------------------------------------
129 */
130void
131NurbsTessellator::do_bgnsurface( O_surface *o_surface )
132{
133 if( inSurface ) {
134 do_nurbserror( 27 );
135 endsurface();
136 }
137 inSurface = 1;
138
139 if( ! playBack ) bgnrender();
140
141 isTrimModified = 0;
142 isSurfaceModified = 0;
143 isDataValid = 1;
144 numTrims = 0;
145 currentSurface = o_surface;
146 nextTrim = &( currentSurface->o_trim );
147 nextNurbssurface = &( currentSurface->o_nurbssurface );
148}
149
150/*-----------------------------------------------------------------------------
151 * do_bgncurve - begin the display of a curve
152 *
153 * Client: bgncurve()
154 *-----------------------------------------------------------------------------
155 */
156void
157NurbsTessellator::do_bgncurve( O_curve *o_curve )
158{
159 if ( inCurve ) {
160 do_nurbserror( 6 );
161 endcurve();
162 }
163
164 inCurve = 1;
165 currentCurve = o_curve;
166 currentCurve->curvetype = ct_none;
167
168 if( inTrim ) {
169 if( *nextCurve != o_curve ) {
170 isCurveModified = 1;
171 *nextCurve = o_curve;
172 }
173 } else {
174 if( ! playBack ) bgnrender();
175 isDataValid = 1;
176 }
177 nextCurve = &(o_curve->next);
178 nextPwlcurve = &(o_curve->curve.o_pwlcurve);
179 nextNurbscurve = &(o_curve->curve.o_nurbscurve);
180}
181
182/*-----------------------------------------------------------------------------
183 * do_endcurve -
184 *
185 * Client: endcurve()
186 *-----------------------------------------------------------------------------
187 */
188
189void
190NurbsTessellator::do_endcurve( void )
191{
192 if( ! inCurve ) {
193 do_nurbserror( 7 );
194 return;
195 }
196 inCurve = 0;
197
198 *nextCurve = 0;
199 if (currentCurve->curvetype == ct_nurbscurve)
200 *nextNurbscurve = 0;
201 else
202 *nextPwlcurve = 0;
203
204 if ( ! inTrim ) {
205 if( ! isDataValid ) {
206 do_freecurveall( currentCurve );
207 return;
208 }
209
210 int errval;
211 errval = ::mysetjmp( jumpbuffer );
212 if( errval == 0 ) {
213 if( currentCurve->curvetype == ct_nurbscurve ) {
214 subdivider.beginQuilts();
215 for( O_nurbscurve *n = currentCurve->curve.o_nurbscurve; n != 0; n = n->next )
216 subdivider.addQuilt( n->bezier_curves );
217 subdivider.endQuilts();
218 subdivider.drawCurves();
219 if( ! playBack ) endrender();
220 } else {
221 /* XXX */
222 if( ! playBack ) endrender();
223 /*do_draw_pwlcurve( currentCurve->curve.o_pwlcurve ) */;
224 do_nurbserror( 9 );
225 }
226 } else {
227 if( ! playBack ) endrender();
228 do_nurbserror( errval );
229 }
230 do_freecurveall( currentCurve );
231 resetObjects();
232 }
233}
234
235/*-----------------------------------------------------------------------------
236 * do_endsurface - mark end of surface, display surface, free immediate data
237 *
238 * Client:
239 *-----------------------------------------------------------------------------
240 */
241void
242NurbsTessellator::do_endsurface( void )
243{
244 if( inTrim ) {
245 do_nurbserror( 12 );
246 endtrim();
247 }
248
249 if( ! inSurface ) {
250 do_nurbserror( 13 );
251 return;
252 }
253 inSurface = 0;
254
255 *nextNurbssurface = 0;
256
257 if( ! isDataValid ) {
258 do_freeall( );
259 return;
260 }
261
262 if( *nextTrim != 0 ) {
263 isTrimModified = 1;
264 *nextTrim = 0;
265 }
266
267 int errval;
268
269 errval = ::mysetjmp( jumpbuffer );
270 if( errval == 0 ) {
271 if( numTrims > 0 ) {
272
273 subdivider.beginTrims();
274 for( O_trim *trim = currentSurface->o_trim; trim; trim = trim->next ) {
275 subdivider.beginLoop();
276 for( O_curve *curve = trim->o_curve; curve; curve = curve->next ) {
277 curve->used = 0;
278 assert( curve->curvetype != ct_none );
279 if (curve->curvetype == ct_pwlcurve) {
280 O_pwlcurve *c = curve->curve.o_pwlcurve;
281 subdivider.addArc( c->npts, c->pts, curve->nuid );
282 } else {
283 Quilt *quilt = curve->curve.o_nurbscurve->bezier_curves;
284 Quiltspec *qspec = quilt->qspec;
285 REAL *cpts = quilt->cpts + qspec->offset;
286 REAL *cptsend = cpts + (qspec->width * qspec->order * qspec->stride);
287 for( ; cpts != cptsend; cpts += qspec->order*qspec->stride )
288 subdivider.addArc( cpts, quilt, curve->nuid );
289 }
290 }
291 subdivider.endLoop();
292 }
293 subdivider.endTrims();
294 }
295
296 subdivider.beginQuilts();
297 for( O_nurbssurface *n = currentSurface->o_nurbssurface; n; n = n->next )
298 subdivider.addQuilt( n->bezier_patches );
299 subdivider.endQuilts();
300 subdivider.drawSurfaces( currentSurface->nuid );
301 if( ! playBack ) endrender();
302 } else {
303 if( ! playBack ) endrender();
304 do_nurbserror( errval );
305 }
306
307 do_freeall( );
308 resetObjects();
309}
310
311/*-----------------------------------------------------------------------------
312 * do_freeall - free all data allocated in immediate mode
313 *
314 * Client:
315 *-----------------------------------------------------------------------------
316 */
317void
318NurbsTessellator::do_freeall( void )
319{
320 for( O_trim *o_trim = currentSurface->o_trim; o_trim; ) {
321 O_trim *next_o_trim = o_trim->next;
322 for( O_curve *curve = o_trim->o_curve; curve; ) {
323 O_curve *next_o_curve = curve->next;
324 do_freecurveall( curve );
325 curve = next_o_curve;
326 }
327 if( o_trim->save == 0 ) do_freebgntrim( o_trim );
328 o_trim = next_o_trim;
329 }
330
331 O_nurbssurface *nurbss, *next_nurbss;
332 for( nurbss= currentSurface->o_nurbssurface; nurbss; nurbss = next_nurbss) {
333 next_nurbss = nurbss->next;
334 if( nurbss->save == 0 )
335 do_freenurbssurface( nurbss );
336 else
337 nurbss->used = 0;
338 }
339
340 if( currentSurface->save == 0 ) do_freebgnsurface( currentSurface );
341}
342
343void
344NurbsTessellator::do_freecurveall( O_curve *curve )
345{
346 assert( curve->curvetype != ct_none );
347
348 if( curve->curvetype == ct_nurbscurve ) {
349 O_nurbscurve *ncurve, *next_ncurve;
350 for( ncurve=curve->curve.o_nurbscurve; ncurve; ncurve=next_ncurve ) {
351 next_ncurve = ncurve->next;
352 if( ncurve->save == 0 )
353 do_freenurbscurve( ncurve );
354 else
355 ncurve->used = 0;
356 }
357 } else {
358 O_pwlcurve *pcurve, *next_pcurve;
359 for( pcurve=curve->curve.o_pwlcurve; pcurve; pcurve=next_pcurve ) {
360 next_pcurve = pcurve->next;
361 if( pcurve->save == 0 )
362 do_freepwlcurve( pcurve );
363 else
364 pcurve->used = 0;
365 }
366 }
367 if( curve->save == 0 )
368 do_freebgncurve( curve );
369}
370
371
372/*-----------------------------------------------------------------------------
373 * do_freebgntrim - free the space allocated for a trim loop
374 *
375 * Client:
376 *-----------------------------------------------------------------------------
377 */
378void
379NurbsTessellator::do_freebgntrim( O_trim *o_trim )
380{
381 o_trim->deleteMe( o_trimPool );
382}
383
384
385/*-----------------------------------------------------------------------------
386 * do_bgntrim - link in a trim loop to the current trimmed surface description
387 *
388 * Client: bgntrim()
389 *-----------------------------------------------------------------------------
390 */
391void
392NurbsTessellator::do_bgntrim( O_trim *o_trim )
393{
394
395 if( ! inSurface ) {
396 do_nurbserror( 15 );
397 bgnsurface( 0 );
398 inSurface = 2;
399 }
400
401 if( inTrim ) {
402 do_nurbserror( 16 );
403 endtrim();
404 }
405 inTrim = 1;
406
407 if( *nextTrim != o_trim ) {
408 isTrimModified = 1;
409 *nextTrim = o_trim;
410 }
411
412 currentTrim = o_trim;
413 nextTrim = &(o_trim->next);
414 nextCurve = &(o_trim->o_curve);
415}
416
417
418/*-----------------------------------------------------------------------------
419 * do_endtrim - mark the end of the current trim loop
420 *
421 * Client: endtrim()
422 *-----------------------------------------------------------------------------
423 */
424void
425NurbsTessellator::do_endtrim( void )
426{
427 if( ! inTrim ) {
428 do_nurbserror( 17 );
429 return;
430 }
431 inTrim = 0;
432
433 if( currentTrim->o_curve == 0 ) {
434 do_nurbserror( 18 );
435 isDataValid = 0;
436 }
437
438 numTrims++;
439
440 if( *nextCurve != 0 ) {
441 isTrimModified = 1;
442 *nextCurve = 0;
443 }
444}
445
446/*-----------------------------------------------------------------------------
447 * do_freepwlcurve -
448 *
449 * Client:
450 *-----------------------------------------------------------------------------
451 */
452void
453NurbsTessellator::do_freepwlcurve( O_pwlcurve *o_pwlcurve )
454{
455 o_pwlcurve->deleteMe( o_pwlcurvePool );
456}
457
458void
459NurbsTessellator::do_freebgncurve( O_curve *o_curve )
460{
461 o_curve->deleteMe( o_curvePool );
462}
463
464/*-----------------------------------------------------------------------------
465 * do_pwlcurve - link in pwl trim loop to the current surface description
466 *
467 * Client: pwlcurve()
468 *-----------------------------------------------------------------------------
469 */
470void
471NurbsTessellator::do_pwlcurve( O_pwlcurve *o_pwlcurve )
472{
473 if( ! inTrim ) {
474 do_nurbserror( 19 );
475 if( o_pwlcurve->save == 0 )
476 do_freepwlcurve(o_pwlcurve );
477 return;
478 }
479
480 if( ! inCurve ) {
481 bgncurve( 0 );
482 inCurve = 2;
483 }
484
485 if( o_pwlcurve->used ) {
486 do_nurbserror( 20 );
487 isDataValid = 0;
488 return;
489 } else
490 o_pwlcurve->used = 1;
491
492 if( currentCurve->curvetype == ct_none ) {
493 currentCurve->curvetype = ct_pwlcurve;
494 } else if( currentCurve->curvetype != ct_pwlcurve ) {
495 do_nurbserror( 21 );
496 isDataValid = 0;
497 return;
498 }
499
500 if( *nextPwlcurve != o_pwlcurve ) {
501 isCurveModified = 1;
502 *nextPwlcurve = o_pwlcurve;
503 }
504 nextPwlcurve = &(o_pwlcurve->next);
505
506 if( o_pwlcurve->owner != currentCurve ) {
507 isCurveModified = 1;
508 o_pwlcurve->owner = currentCurve;
509 }
510
511 if( (inCurve == 2) )
512 endcurve();
513}
514
515
516/*-----------------------------------------------------------------------------
517 * do_freenurbscurve -
518 *
519 * Client:
520 *-----------------------------------------------------------------------------
521 */
522void
523NurbsTessellator::do_freenurbscurve( O_nurbscurve *o_nurbscurve )
524{
525 o_nurbscurve->bezier_curves->deleteMe( quiltPool );
526 o_nurbscurve->deleteMe( o_nurbscurvePool );
527}
528
529
530/*-----------------------------------------------------------------------------
531 * do_nurbscurve -
532 *
533 * Client: nurbscurve()
534 *-----------------------------------------------------------------------------
535 */
536void
537NurbsTessellator::do_nurbscurve( O_nurbscurve *o_nurbscurve )
538{
539 if ( ! inCurve ) {
540 bgncurve( 0 );
541 inCurve = 2;
542 }
543
544 if( o_nurbscurve->used ) {
545 /* error - curve was already called in current surface */
546 do_nurbserror( 23 );
547 isDataValid = 0;
548 return;
549 } else
550 o_nurbscurve->used = 1;
551
552 if( currentCurve->curvetype == ct_none ) {
553 currentCurve->curvetype = ct_nurbscurve;
554 } else if( currentCurve->curvetype != ct_nurbscurve ) {
555 do_nurbserror( 24 );
556 isDataValid = 0;
557 return;
558 }
559
560 if( *nextNurbscurve != o_nurbscurve ) {
561 isCurveModified = 1;
562 *nextNurbscurve = o_nurbscurve;
563 }
564
565 nextNurbscurve = &(o_nurbscurve->next);
566
567 if( o_nurbscurve->owner != currentCurve ) {
568 isCurveModified = 1;
569 o_nurbscurve->owner = currentCurve;
570 }
571
572 if( o_nurbscurve->owner == 0 )
573 isCurveModified = 1;
574
575 if( inCurve == 2 )
576 endcurve();
577}
578
579
580/*-----------------------------------------------------------------------------
581 * do_freenurbssurface -
582 *
583 * Client:
584 *-----------------------------------------------------------------------------
585 */
586
587void
588NurbsTessellator::do_freenurbssurface( O_nurbssurface *o_nurbssurface )
589{
590 o_nurbssurface->bezier_patches->deleteMe( quiltPool );
591 o_nurbssurface->deleteMe( o_nurbssurfacePool );
592}
593
594/*-----------------------------------------------------------------------------
595 * do_nurbssurface -
596 *
597 * Client: nurbssurface()
598 *-----------------------------------------------------------------------------
599 */
600void
601NurbsTessellator::do_nurbssurface( O_nurbssurface *o_nurbssurface )
602{
603 if( ! inSurface ) {
604 bgnsurface( 0 );
605 inSurface = 2;
606 }
607
608 if( o_nurbssurface->used ) {
609 /* error - surface was already called in current block */
610 do_nurbserror( 25 );
611 isDataValid = 0;
612 return;
613 } else
614 o_nurbssurface->used = 1;
615
616 if( *nextNurbssurface != o_nurbssurface ) {
617 isSurfaceModified = 1;
618 *nextNurbssurface = o_nurbssurface;
619 }
620
621 if( o_nurbssurface->owner != currentSurface ) {
622 isSurfaceModified = 1;
623 o_nurbssurface->owner = currentSurface;
624 }
625 nextNurbssurface = &(o_nurbssurface->next);
626
627 if( inSurface == 2 )
628 endsurface();
629}
630
631
632/*-----------------------------------------------------------------------------
633 * do_freenurbsproperty
634 *
635 *-----------------------------------------------------------------------------
636 */
637
638void
639NurbsTessellator::do_freenurbsproperty( Property *prop )
640{
641 prop->deleteMe( propertyPool );
642}
643
644
645/*-----------------------------------------------------------------------------
646 * do_setnurbsproperty -
647 *
648 *-----------------------------------------------------------------------------
649 */
650
651void
652NurbsTessellator::do_setnurbsproperty( Property *prop )
653{
654 renderhints.setProperty( prop->tag, prop->value );
655 if( prop->save == 0 )
656 do_freenurbsproperty( prop );
657}
658
659void
660NurbsTessellator::do_setnurbsproperty2( Property *prop )
661{
662 Mapdesc *mapdesc = maplist.find( prop->type );
663
664 mapdesc->setProperty( prop->tag, prop->value );
665 if( prop->save == 0 )
666 do_freenurbsproperty( prop );
667}
668
669void
670NurbsTessellator::errorHandler( int )
671{
672}
673
674void
675NurbsTessellator::do_nurbserror( int msg )
676{
677 errorHandler( msg );
678}
679
680int
681NurbsTessellator::do_check_knots( Knotvector *knots, char *msg )
682{
683 int status = knots->validate();
684 if( status ) {
685 do_nurbserror( status );
686 if( renderhints.errorchecking != N_NOMSG ) knots->show( msg );
687 }
688 return status;
689}
690
691
692
693
694
Note: See TracBrowser for help on using the repository browser.