Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygennurbstess.cc
Go to the documentation of this file.
00001 /* 00002 ** License Applicability. Except to the extent portions of this file are 00003 ** made subject to an alternative license as permitted in the SGI Free 00004 ** Software License B, Version 1.1 (the "License"), the contents of this 00005 ** file are subject only to the provisions of the License. You may not use 00006 ** this file except in compliance with the License. You may obtain a copy 00007 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 00008 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 00009 ** 00010 ** http://oss.sgi.com/projects/FreeB 00011 ** 00012 ** Note that, as provided in the License, the Software is distributed on an 00013 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 00014 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 00015 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 00016 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 00017 ** 00018 ** Original Code. The Original Code is: OpenGL Sample Implementation, 00019 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 00020 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 00021 ** Copyright in any portions created by third parties is as indicated 00022 ** elsewhere herein. All Rights Reserved. 00023 ** 00024 ** Additional Notice Provisions: The application programming interfaces 00025 ** established by SGI in conjunction with the Original Code are The 00026 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released 00027 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version 00028 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X 00029 ** Window System(R) (Version 1.3), released October 19, 1998. This software 00030 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation 00031 ** published by SGI, but has not been independently verified as being 00032 ** compliant with the OpenGL(R) version 1.2.1 Specification. 00033 */ 00034 00035 /* 00036 * nurbstess.c++ 00037 * 00038 * $Date: 2009-08-30 15:53:16 +0000 (Sun, 30 Aug 2009) $ $Revision: 1.1 $ 00039 * $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/internals/nurbstess.cc,v 1.1 2004/02/02 16:39:12 navaraf Exp $ 00040 */ 00041 00042 #include "glimports.h" 00043 #include "myassert.h" 00044 #include "mysetjmp.h" 00045 #include "mystdio.h" 00046 #include "nurbsconsts.h" 00047 #include "nurbstess.h" 00048 #include "bufpool.h" 00049 #include "quilt.h" 00050 #include "knotvector.h" 00051 #include "mapdesc.h" 00052 #include "maplist.h" 00053 00054 void 00055 NurbsTessellator::set_domain_distance_u_rate(REAL u_rate) 00056 { 00057 subdivider.set_domain_distance_u_rate(u_rate); 00058 } 00059 00060 void 00061 NurbsTessellator::set_domain_distance_v_rate(REAL v_rate) 00062 { 00063 subdivider.set_domain_distance_v_rate(v_rate); 00064 } 00065 00066 void 00067 NurbsTessellator::set_is_domain_distance_sampling(int flag) 00068 { 00069 subdivider.set_is_domain_distance_sampling(flag); 00070 } 00071 00072 void 00073 NurbsTessellator::resetObjects( void ) 00074 { 00075 subdivider.clear(); 00076 } 00077 00078 void 00079 NurbsTessellator::makeobj( int ) 00080 { 00081 #ifndef NDEBUG 00082 dprintf( "makeobj\n" ); 00083 #endif 00084 } 00085 00086 void 00087 NurbsTessellator::closeobj( void ) 00088 { 00089 #ifndef NDEBUG 00090 dprintf( "closeobj\n" ); 00091 #endif 00092 } 00093 00094 void 00095 NurbsTessellator::bgnrender( void ) 00096 { 00097 #ifndef NDEBUG 00098 dprintf( "bgnrender\n" ); 00099 #endif 00100 } 00101 00102 void 00103 NurbsTessellator::endrender( void ) 00104 { 00105 #ifndef NDEBUG 00106 dprintf( "endrender\n" ); 00107 #endif 00108 } 00109 00110 /*----------------------------------------------------------------------------- 00111 * do_freebgnsurface - free o_surface structure 00112 * 00113 * Client: do_freeall(), bgnsurface() 00114 *----------------------------------------------------------------------------- 00115 */ 00116 void 00117 NurbsTessellator::do_freebgnsurface( O_surface *o_surface ) 00118 { 00119 o_surface->deleteMe( o_surfacePool ); 00120 } 00121 00122 00123 /*----------------------------------------------------------------------------- 00124 * do_bgnsurface - begin the display of a surface 00125 * 00126 * Client: bgnsurface() 00127 *----------------------------------------------------------------------------- 00128 */ 00129 void 00130 NurbsTessellator::do_bgnsurface( O_surface *o_surface ) 00131 { 00132 if( inSurface ) { 00133 do_nurbserror( 27 ); 00134 endsurface(); 00135 } 00136 inSurface = 1; 00137 00138 if( ! playBack ) bgnrender(); 00139 00140 isTrimModified = 0; 00141 isSurfaceModified = 0; 00142 isDataValid = 1; 00143 numTrims = 0; 00144 currentSurface = o_surface; 00145 nextTrim = &( currentSurface->o_trim ); 00146 nextNurbssurface = &( currentSurface->o_nurbssurface ); 00147 } 00148 00149 /*----------------------------------------------------------------------------- 00150 * do_bgncurve - begin the display of a curve 00151 * 00152 * Client: bgncurve() 00153 *----------------------------------------------------------------------------- 00154 */ 00155 void 00156 NurbsTessellator::do_bgncurve( O_curve *o_curve ) 00157 { 00158 if ( inCurve ) { 00159 do_nurbserror( 6 ); 00160 endcurve(); 00161 } 00162 00163 inCurve = 1; 00164 currentCurve = o_curve; 00165 currentCurve->curvetype = ct_none; 00166 00167 if( inTrim ) { 00168 if( *nextCurve != o_curve ) { 00169 isCurveModified = 1; 00170 *nextCurve = o_curve; 00171 } 00172 } else { 00173 if( ! playBack ) bgnrender(); 00174 isDataValid = 1; 00175 } 00176 nextCurve = &(o_curve->next); 00177 nextPwlcurve = &(o_curve->curve.o_pwlcurve); 00178 nextNurbscurve = &(o_curve->curve.o_nurbscurve); 00179 } 00180 00181 /*----------------------------------------------------------------------------- 00182 * do_endcurve - 00183 * 00184 * Client: endcurve() 00185 *----------------------------------------------------------------------------- 00186 */ 00187 00188 void 00189 NurbsTessellator::do_endcurve( void ) 00190 { 00191 if( ! inCurve ) { 00192 do_nurbserror( 7 ); 00193 return; 00194 } 00195 inCurve = 0; 00196 00197 *nextCurve = 0; 00198 if (currentCurve->curvetype == ct_nurbscurve) 00199 *nextNurbscurve = 0; 00200 else 00201 *nextPwlcurve = 0; 00202 00203 if ( ! inTrim ) { 00204 if( ! isDataValid ) { 00205 do_freecurveall( currentCurve ); 00206 return; 00207 } 00208 00209 int errval; 00210 errval = ::mysetjmp( jumpbuffer ); 00211 if( errval == 0 ) { 00212 if( currentCurve->curvetype == ct_nurbscurve ) { 00213 subdivider.beginQuilts(); 00214 for( O_nurbscurve *n = currentCurve->curve.o_nurbscurve; n != 0; n = n->next ) 00215 subdivider.addQuilt( n->bezier_curves ); 00216 subdivider.endQuilts(); 00217 subdivider.drawCurves(); 00218 if( ! playBack ) endrender(); 00219 } else { 00220 /* XXX */ 00221 if( ! playBack ) endrender(); 00222 /*do_draw_pwlcurve( currentCurve->curve.o_pwlcurve ) */; 00223 do_nurbserror( 9 ); 00224 } 00225 } else { 00226 if( ! playBack ) endrender(); 00227 do_nurbserror( errval ); 00228 } 00229 do_freecurveall( currentCurve ); 00230 resetObjects(); 00231 } 00232 } 00233 00234 /*----------------------------------------------------------------------------- 00235 * do_endsurface - mark end of surface, display surface, free immediate data 00236 * 00237 * Client: 00238 *----------------------------------------------------------------------------- 00239 */ 00240 void 00241 NurbsTessellator::do_endsurface( void ) 00242 { 00243 if( inTrim ) { 00244 do_nurbserror( 12 ); 00245 endtrim(); 00246 } 00247 00248 if( ! inSurface ) { 00249 do_nurbserror( 13 ); 00250 return; 00251 } 00252 inSurface = 0; 00253 00254 *nextNurbssurface = 0; 00255 00256 if( ! isDataValid ) { 00257 do_freeall( ); 00258 return; 00259 } 00260 00261 if( *nextTrim != 0 ) { 00262 isTrimModified = 1; 00263 *nextTrim = 0; 00264 } 00265 00266 int errval; 00267 00268 errval = ::mysetjmp( jumpbuffer ); 00269 if( errval == 0 ) { 00270 if( numTrims > 0 ) { 00271 00272 subdivider.beginTrims(); 00273 for( O_trim *trim = currentSurface->o_trim; trim; trim = trim->next ) { 00274 subdivider.beginLoop(); 00275 for( O_curve *curve = trim->o_curve; curve; curve = curve->next ) { 00276 curve->used = 0; 00277 assert( curve->curvetype != ct_none ); 00278 if (curve->curvetype == ct_pwlcurve) { 00279 O_pwlcurve *c = curve->curve.o_pwlcurve; 00280 subdivider.addArc( c->npts, c->pts, curve->nuid ); 00281 } else { 00282 Quilt *quilt = curve->curve.o_nurbscurve->bezier_curves; 00283 Quiltspec *qspec = quilt->qspec; 00284 REAL *cpts = quilt->cpts + qspec->offset; 00285 REAL *cptsend = cpts + (qspec->width * qspec->order * qspec->stride); 00286 for( ; cpts != cptsend; cpts += qspec->order*qspec->stride ) 00287 subdivider.addArc( cpts, quilt, curve->nuid ); 00288 } 00289 } 00290 subdivider.endLoop(); 00291 } 00292 subdivider.endTrims(); 00293 } 00294 00295 subdivider.beginQuilts(); 00296 for( O_nurbssurface *n = currentSurface->o_nurbssurface; n; n = n->next ) 00297 subdivider.addQuilt( n->bezier_patches ); 00298 subdivider.endQuilts(); 00299 subdivider.drawSurfaces( currentSurface->nuid ); 00300 if( ! playBack ) endrender(); 00301 } else { 00302 if( ! playBack ) endrender(); 00303 do_nurbserror( errval ); 00304 } 00305 00306 do_freeall( ); 00307 resetObjects(); 00308 } 00309 00310 /*----------------------------------------------------------------------------- 00311 * do_freeall - free all data allocated in immediate mode 00312 * 00313 * Client: 00314 *----------------------------------------------------------------------------- 00315 */ 00316 void 00317 NurbsTessellator::do_freeall( void ) 00318 { 00319 for( O_trim *o_trim = currentSurface->o_trim; o_trim; ) { 00320 O_trim *next_o_trim = o_trim->next; 00321 for( O_curve *curve = o_trim->o_curve; curve; ) { 00322 O_curve *next_o_curve = curve->next; 00323 do_freecurveall( curve ); 00324 curve = next_o_curve; 00325 } 00326 if( o_trim->save == 0 ) do_freebgntrim( o_trim ); 00327 o_trim = next_o_trim; 00328 } 00329 00330 O_nurbssurface *nurbss, *next_nurbss; 00331 for( nurbss= currentSurface->o_nurbssurface; nurbss; nurbss = next_nurbss) { 00332 next_nurbss = nurbss->next; 00333 if( nurbss->save == 0 ) 00334 do_freenurbssurface( nurbss ); 00335 else 00336 nurbss->used = 0; 00337 } 00338 00339 if( currentSurface->save == 0 ) do_freebgnsurface( currentSurface ); 00340 } 00341 00342 void 00343 NurbsTessellator::do_freecurveall( O_curve *curve ) 00344 { 00345 assert( curve->curvetype != ct_none ); 00346 00347 if( curve->curvetype == ct_nurbscurve ) { 00348 O_nurbscurve *ncurve, *next_ncurve; 00349 for( ncurve=curve->curve.o_nurbscurve; ncurve; ncurve=next_ncurve ) { 00350 next_ncurve = ncurve->next; 00351 if( ncurve->save == 0 ) 00352 do_freenurbscurve( ncurve ); 00353 else 00354 ncurve->used = 0; 00355 } 00356 } else { 00357 O_pwlcurve *pcurve, *next_pcurve; 00358 for( pcurve=curve->curve.o_pwlcurve; pcurve; pcurve=next_pcurve ) { 00359 next_pcurve = pcurve->next; 00360 if( pcurve->save == 0 ) 00361 do_freepwlcurve( pcurve ); 00362 else 00363 pcurve->used = 0; 00364 } 00365 } 00366 if( curve->save == 0 ) 00367 do_freebgncurve( curve ); 00368 } 00369 00370 00371 /*----------------------------------------------------------------------------- 00372 * do_freebgntrim - free the space allocated for a trim loop 00373 * 00374 * Client: 00375 *----------------------------------------------------------------------------- 00376 */ 00377 void 00378 NurbsTessellator::do_freebgntrim( O_trim *o_trim ) 00379 { 00380 o_trim->deleteMe( o_trimPool ); 00381 } 00382 00383 00384 /*----------------------------------------------------------------------------- 00385 * do_bgntrim - link in a trim loop to the current trimmed surface description 00386 * 00387 * Client: bgntrim() 00388 *----------------------------------------------------------------------------- 00389 */ 00390 void 00391 NurbsTessellator::do_bgntrim( O_trim *o_trim ) 00392 { 00393 00394 if( ! inSurface ) { 00395 do_nurbserror( 15 ); 00396 bgnsurface( 0 ); 00397 inSurface = 2; 00398 } 00399 00400 if( inTrim ) { 00401 do_nurbserror( 16 ); 00402 endtrim(); 00403 } 00404 inTrim = 1; 00405 00406 if( *nextTrim != o_trim ) { 00407 isTrimModified = 1; 00408 *nextTrim = o_trim; 00409 } 00410 00411 currentTrim = o_trim; 00412 nextTrim = &(o_trim->next); 00413 nextCurve = &(o_trim->o_curve); 00414 } 00415 00416 00417 /*----------------------------------------------------------------------------- 00418 * do_endtrim - mark the end of the current trim loop 00419 * 00420 * Client: endtrim() 00421 *----------------------------------------------------------------------------- 00422 */ 00423 void 00424 NurbsTessellator::do_endtrim( void ) 00425 { 00426 if( ! inTrim ) { 00427 do_nurbserror( 17 ); 00428 return; 00429 } 00430 inTrim = 0; 00431 00432 if( currentTrim->o_curve == 0 ) { 00433 do_nurbserror( 18 ); 00434 isDataValid = 0; 00435 } 00436 00437 numTrims++; 00438 00439 if( *nextCurve != 0 ) { 00440 isTrimModified = 1; 00441 *nextCurve = 0; 00442 } 00443 } 00444 00445 /*----------------------------------------------------------------------------- 00446 * do_freepwlcurve - 00447 * 00448 * Client: 00449 *----------------------------------------------------------------------------- 00450 */ 00451 void 00452 NurbsTessellator::do_freepwlcurve( O_pwlcurve *o_pwlcurve ) 00453 { 00454 o_pwlcurve->deleteMe( o_pwlcurvePool ); 00455 } 00456 00457 void 00458 NurbsTessellator::do_freebgncurve( O_curve *o_curve ) 00459 { 00460 o_curve->deleteMe( o_curvePool ); 00461 } 00462 00463 /*----------------------------------------------------------------------------- 00464 * do_pwlcurve - link in pwl trim loop to the current surface description 00465 * 00466 * Client: pwlcurve() 00467 *----------------------------------------------------------------------------- 00468 */ 00469 void 00470 NurbsTessellator::do_pwlcurve( O_pwlcurve *o_pwlcurve ) 00471 { 00472 if( ! inTrim ) { 00473 do_nurbserror( 19 ); 00474 if( o_pwlcurve->save == 0 ) 00475 do_freepwlcurve(o_pwlcurve ); 00476 return; 00477 } 00478 00479 if( ! inCurve ) { 00480 bgncurve( 0 ); 00481 inCurve = 2; 00482 } 00483 00484 if( o_pwlcurve->used ) { 00485 do_nurbserror( 20 ); 00486 isDataValid = 0; 00487 return; 00488 } else 00489 o_pwlcurve->used = 1; 00490 00491 if( currentCurve->curvetype == ct_none ) { 00492 currentCurve->curvetype = ct_pwlcurve; 00493 } else if( currentCurve->curvetype != ct_pwlcurve ) { 00494 do_nurbserror( 21 ); 00495 isDataValid = 0; 00496 return; 00497 } 00498 00499 if( *nextPwlcurve != o_pwlcurve ) { 00500 isCurveModified = 1; 00501 *nextPwlcurve = o_pwlcurve; 00502 } 00503 nextPwlcurve = &(o_pwlcurve->next); 00504 00505 if( o_pwlcurve->owner != currentCurve ) { 00506 isCurveModified = 1; 00507 o_pwlcurve->owner = currentCurve; 00508 } 00509 00510 if( (inCurve == 2) ) 00511 endcurve(); 00512 } 00513 00514 00515 /*----------------------------------------------------------------------------- 00516 * do_freenurbscurve - 00517 * 00518 * Client: 00519 *----------------------------------------------------------------------------- 00520 */ 00521 void 00522 NurbsTessellator::do_freenurbscurve( O_nurbscurve *o_nurbscurve ) 00523 { 00524 o_nurbscurve->bezier_curves->deleteMe( quiltPool ); 00525 o_nurbscurve->deleteMe( o_nurbscurvePool ); 00526 } 00527 00528 00529 /*----------------------------------------------------------------------------- 00530 * do_nurbscurve - 00531 * 00532 * Client: nurbscurve() 00533 *----------------------------------------------------------------------------- 00534 */ 00535 void 00536 NurbsTessellator::do_nurbscurve( O_nurbscurve *o_nurbscurve ) 00537 { 00538 if ( ! inCurve ) { 00539 bgncurve( 0 ); 00540 inCurve = 2; 00541 } 00542 00543 if( o_nurbscurve->used ) { 00544 /* error - curve was already called in current surface */ 00545 do_nurbserror( 23 ); 00546 isDataValid = 0; 00547 return; 00548 } else 00549 o_nurbscurve->used = 1; 00550 00551 if( currentCurve->curvetype == ct_none ) { 00552 currentCurve->curvetype = ct_nurbscurve; 00553 } else if( currentCurve->curvetype != ct_nurbscurve ) { 00554 do_nurbserror( 24 ); 00555 isDataValid = 0; 00556 return; 00557 } 00558 00559 if( *nextNurbscurve != o_nurbscurve ) { 00560 isCurveModified = 1; 00561 *nextNurbscurve = o_nurbscurve; 00562 } 00563 00564 nextNurbscurve = &(o_nurbscurve->next); 00565 00566 if( o_nurbscurve->owner != currentCurve ) { 00567 isCurveModified = 1; 00568 o_nurbscurve->owner = currentCurve; 00569 } 00570 00571 if( o_nurbscurve->owner == 0 ) 00572 isCurveModified = 1; 00573 00574 if( inCurve == 2 ) 00575 endcurve(); 00576 } 00577 00578 00579 /*----------------------------------------------------------------------------- 00580 * do_freenurbssurface - 00581 * 00582 * Client: 00583 *----------------------------------------------------------------------------- 00584 */ 00585 00586 void 00587 NurbsTessellator::do_freenurbssurface( O_nurbssurface *o_nurbssurface ) 00588 { 00589 o_nurbssurface->bezier_patches->deleteMe( quiltPool ); 00590 o_nurbssurface->deleteMe( o_nurbssurfacePool ); 00591 } 00592 00593 /*----------------------------------------------------------------------------- 00594 * do_nurbssurface - 00595 * 00596 * Client: nurbssurface() 00597 *----------------------------------------------------------------------------- 00598 */ 00599 void 00600 NurbsTessellator::do_nurbssurface( O_nurbssurface *o_nurbssurface ) 00601 { 00602 if( ! inSurface ) { 00603 bgnsurface( 0 ); 00604 inSurface = 2; 00605 } 00606 00607 if( o_nurbssurface->used ) { 00608 /* error - surface was already called in current block */ 00609 do_nurbserror( 25 ); 00610 isDataValid = 0; 00611 return; 00612 } else 00613 o_nurbssurface->used = 1; 00614 00615 if( *nextNurbssurface != o_nurbssurface ) { 00616 isSurfaceModified = 1; 00617 *nextNurbssurface = o_nurbssurface; 00618 } 00619 00620 if( o_nurbssurface->owner != currentSurface ) { 00621 isSurfaceModified = 1; 00622 o_nurbssurface->owner = currentSurface; 00623 } 00624 nextNurbssurface = &(o_nurbssurface->next); 00625 00626 if( inSurface == 2 ) 00627 endsurface(); 00628 } 00629 00630 00631 /*----------------------------------------------------------------------------- 00632 * do_freenurbsproperty 00633 * 00634 *----------------------------------------------------------------------------- 00635 */ 00636 00637 void 00638 NurbsTessellator::do_freenurbsproperty( Property *prop ) 00639 { 00640 prop->deleteMe( propertyPool ); 00641 } 00642 00643 00644 /*----------------------------------------------------------------------------- 00645 * do_setnurbsproperty - 00646 * 00647 *----------------------------------------------------------------------------- 00648 */ 00649 00650 void 00651 NurbsTessellator::do_setnurbsproperty( Property *prop ) 00652 { 00653 renderhints.setProperty( prop->tag, prop->value ); 00654 if( prop->save == 0 ) 00655 do_freenurbsproperty( prop ); 00656 } 00657 00658 void 00659 NurbsTessellator::do_setnurbsproperty2( Property *prop ) 00660 { 00661 Mapdesc *mapdesc = maplist.find( prop->type ); 00662 00663 mapdesc->setProperty( prop->tag, prop->value ); 00664 if( prop->save == 0 ) 00665 do_freenurbsproperty( prop ); 00666 } 00667 00668 void 00669 NurbsTessellator::errorHandler( int ) 00670 { 00671 } 00672 00673 void 00674 NurbsTessellator::do_nurbserror( int msg ) 00675 { 00676 errorHandler( msg ); 00677 } 00678 00679 int 00680 NurbsTessellator::do_check_knots( Knotvector *knots, const char *msg ) 00681 { 00682 int status = knots->validate(); 00683 if( status ) { 00684 do_nurbserror( status ); 00685 if( renderhints.errorchecking != N_NOMSG ) knots->show( msg ); 00686 } 00687 return status; 00688 } 00689 00690 00691 00692 00693 Generated on Fri May 25 2012 04:21:54 for ReactOS by
1.7.6.1
|