ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

nurbsinterfac.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  * nurbsinterfac.c++
00037  *
00038  */
00039 
00040 #include "glimports.h"
00041 #include "mystdio.h"
00042 #include "nurbsconsts.h"
00043 #include "nurbstess.h"
00044 #include "bufpool.h"
00045 #include "quilt.h"
00046 #include "displaylist.h"
00047 #include "knotvector.h"
00048 #include "mapdesc.h"
00049 
00050 #define THREAD( work, arg, cleanup ) \
00051     if( dl ) {\
00052         arg->save = 1;\
00053         dl->append( (PFVS)&NurbsTessellator::work, (void *) arg, (PFVS)&NurbsTessellator::cleanup );\
00054     } else {\
00055         arg->save = 0;\
00056         work( arg );\
00057     }
00058 
00059 #define THREAD2( work ) \
00060     if( dl ) {\
00061         dl->append( (PFVS)&NurbsTessellator::work, 0, 0 );\
00062     } else {\
00063         work( );\
00064     }
00065 
00066 NurbsTessellator::NurbsTessellator( BasicCurveEvaluator &c, BasicSurfaceEvaluator& e) 
00067     : maplist( backend ),
00068       backend( c, e ),
00069           subdivider( renderhints, backend ),
00070       o_pwlcurvePool( sizeof( O_pwlcurve ), 32, "o_pwlcurvePool" ),
00071       o_nurbscurvePool( sizeof( O_nurbscurve ), 32, "o_nurbscurvePool"),
00072       o_curvePool( sizeof( O_curve ), 32,  "o_curvePool" ),
00073       o_trimPool( sizeof( O_trim ), 32,  "o_trimPool" ),
00074       o_surfacePool( sizeof( O_surface ), 1, "o_surfacePool" ),
00075       o_nurbssurfacePool( sizeof( O_nurbssurface ), 4, "o_nurbssurfacePool" ),
00076       propertyPool( sizeof( Property ), 32, "propertyPool" ),
00077           quiltPool( sizeof( Quilt  ), 32, "quiltPool" )
00078 {
00079     dl      = 0;
00080     inSurface   = 0;
00081     inCurve = 0;
00082     inTrim  = 0;
00083     playBack    = 0;
00084     jumpbuffer  = newJumpbuffer();
00085     subdivider.setJumpbuffer( jumpbuffer );
00086 }
00087 
00088 NurbsTessellator::~NurbsTessellator( void ) 
00089 {
00090     if( inTrim ) {
00091     do_nurbserror( 12 );
00092     endtrim();
00093     }
00094 
00095     if( inSurface ) {
00096         *nextNurbssurface = 0;
00097         do_freeall();
00098     }
00099 
00100     if (jumpbuffer) {
00101         deleteJumpbuffer(jumpbuffer);
00102     jumpbuffer= 0;
00103     }   
00104 }
00105 
00106 /*-----------------------------------------------------------------------------
00107  * bgnsurface - allocate and initialize an o_surface structure
00108  *
00109  * Client: GL user
00110  *-----------------------------------------------------------------------------
00111  */
00112 void
00113 NurbsTessellator::bgnsurface( long nuid )
00114 {
00115     O_surface *o_surface = new(o_surfacePool) O_surface;
00116     o_surface->nuid = nuid;
00117     THREAD( do_bgnsurface, o_surface, do_freebgnsurface );
00118 }
00119 
00120 /*-----------------------------------------------------------------------------
00121  * bgncurve - allocate an initialize an o_curve structure
00122  * 
00123  * Client: GL user
00124  *-----------------------------------------------------------------------------
00125  */
00126 void
00127 NurbsTessellator::bgncurve( long nuid )
00128 {
00129     O_curve *o_curve = new(o_curvePool) O_curve;
00130     o_curve->nuid = nuid;
00131     THREAD( do_bgncurve, o_curve, do_freebgncurve );
00132 }
00133 /*-----------------------------------------------------------------------------
00134  * endcurve -
00135  * 
00136  * Client:
00137  *-----------------------------------------------------------------------------
00138  */
00139 
00140 void
00141 NurbsTessellator::endcurve( void )
00142 {
00143     THREAD2( do_endcurve );
00144 }
00145 
00146 /*-----------------------------------------------------------------------------
00147  * endsurface - user level end of surface call
00148  *
00149  * Client: GL user
00150  *-----------------------------------------------------------------------------
00151  */
00152 void
00153 NurbsTessellator::endsurface( void )
00154 {
00155     THREAD2( do_endsurface );
00156 }
00157 
00158 
00159 /*-----------------------------------------------------------------------------
00160  * bgntrim - allocate and initialize a new trim loop structure (o_trim )
00161  *
00162  * Client: GL user
00163  *-----------------------------------------------------------------------------
00164  */
00165 void
00166 NurbsTessellator::bgntrim( void )
00167 {
00168     O_trim *o_trim = new(o_trimPool) O_trim;
00169     THREAD( do_bgntrim, o_trim, do_freebgntrim );
00170 }
00171 
00172 /*-----------------------------------------------------------------------------
00173  * endtrim -
00174  *
00175  * Client: GL user
00176  *-----------------------------------------------------------------------------
00177  */
00178 void
00179 NurbsTessellator::endtrim( void )
00180 {
00181     THREAD2( do_endtrim );
00182 }
00183 
00184 
00185 /*-----------------------------------------------------------------------------
00186  * pwlcurve -
00187  *
00188  *      count        - number of points on curve
00189  *      array        - array of points on curve
00190  *      byte_stride  - distance between points in bytes
00191  *      type         - valid data flag
00192  *
00193  * Client: Gl user
00194  *-----------------------------------------------------------------------------
00195  */
00196 void
00197 NurbsTessellator::pwlcurve( long count, INREAL array[], long byte_stride, long type )
00198 {
00199     Mapdesc *mapdesc = maplist.locate( type );
00200 
00201     if( mapdesc == 0 ) {
00202     do_nurbserror( 35 );
00203     isDataValid = 0;
00204     return;
00205     }
00206 
00207     if ( (type != N_P2D) && (type != N_P2DR) ) {
00208     do_nurbserror( 22 );
00209     isDataValid = 0;
00210     return;
00211     }
00212     if( count < 0 ) {
00213     do_nurbserror( 33 );
00214     isDataValid = 0;
00215     return;
00216     }
00217     if( byte_stride < 0 ) {
00218     do_nurbserror( 34 );
00219     isDataValid = 0;
00220     return;
00221     }
00222 
00223 #ifdef NOTDEF
00224     if( mapdesc->isRational() ) {
00225     INREAL *p = array;
00226     INREAL x = p[0]; INREAL y = p[1]; INREAL w = p[2];
00227     p = (INREAL *) (((char *) p) + byte_stride);
00228     for( long i = 1; i != count; i++ ) {
00229         if( p[0] == x && p[1] == y && p[2] == w ) break;
00230         x = p[0]; y = p[1]; w = p[2];
00231         p = (INREAL *) (((char *) p) + byte_stride);
00232     }
00233     if( i != count ) {
00234         do_nurbserror( 37 );
00235         dprintf( "point %d (%f,%f)\n", i, x, y );
00236         isDataValid = 0;
00237         return;
00238     }
00239     } else {
00240     INREAL *p = array;
00241     INREAL x = p[0]; INREAL y = p[1];
00242     p = (INREAL *) (((char *) p) + byte_stride);
00243     for( long i = 1; i != count; i++ ) {
00244         if( p[0] == x && p[1] == y ) break;
00245         x = p[0]; y = p[1];
00246         p = (INREAL *) (((char *) p) + byte_stride);
00247     }
00248     if( i != count ) {
00249         do_nurbserror( 37 );
00250         dprintf( "point %d (%f,%f)\n", i, x, y );
00251         isDataValid = 0;
00252         return;
00253     }
00254     }
00255 #endif
00256 
00257     O_pwlcurve  *o_pwlcurve = new(o_pwlcurvePool) O_pwlcurve( type, count, array, byte_stride, extTrimVertexPool.get((int)count) );
00258     THREAD( do_pwlcurve, o_pwlcurve, do_freepwlcurve );
00259 }
00260 
00261 
00262 /*-----------------------------------------------------------------------------
00263  * nurbscurve -
00264  *
00265  * Client: GL user
00266  *-----------------------------------------------------------------------------
00267  */
00268 void
00269 NurbsTessellator::nurbscurve(
00270     long nknots,        /* number of p knots */
00271     INREAL knot[],      /* nondecreasing knot values in p */
00272     long byte_stride,       /* distance in bytes between control points */
00273     INREAL ctlarray[],      /* pointer to first control point */
00274     long order,         /* order of spline */
00275     long type )         /* description of range space */
00276 {
00277 
00278     Mapdesc *mapdesc = maplist.locate( type );
00279 
00280     if( mapdesc == 0 ) {
00281     do_nurbserror( 35 );
00282     isDataValid = 0;
00283     return;
00284     }
00285 
00286     if( ctlarray == 0 ) {
00287     do_nurbserror( 36 );
00288     isDataValid = 0;
00289     return;
00290     }
00291 
00292     if( byte_stride < 0 ) {
00293     do_nurbserror( 34 );
00294     isDataValid = 0;
00295     return;
00296     }
00297 
00298     Knotvector knots;
00299 
00300     knots.init( nknots, byte_stride, order, knot );
00301     if( do_check_knots( &knots, "curve" ) ) return;
00302     
00303     O_nurbscurve *o_nurbscurve = new(o_nurbscurvePool) O_nurbscurve(type);
00304     o_nurbscurve->bezier_curves = new(quiltPool) Quilt(mapdesc);
00305     o_nurbscurve->bezier_curves->toBezier( knots,ctlarray, mapdesc->getNcoords() );
00306  
00307     THREAD( do_nurbscurve, o_nurbscurve, do_freenurbscurve );
00308 }
00309 
00310 
00311 /*-----------------------------------------------------------------------------
00312  * nurbssurface -
00313  *
00314  * Client: User routine
00315  *-----------------------------------------------------------------------------
00316  */
00317 void
00318 NurbsTessellator::nurbssurface(
00319     long sknot_count,       /* number of s knots */
00320     INREAL sknot[],     /* nondecreasing knot values in s */
00321     long tknot_count,       /* number of t knots */
00322     INREAL tknot[],     /* nondecreasing knot values in t */
00323     long s_byte_stride,     /* s step size in memory bytes */
00324     long t_byte_stride,     /* t step size in memory bytes */
00325     INREAL ctlarray[],      /* pointer to first control point */
00326     long sorder,        /* order of the spline in s parameter */
00327     long torder,        /* order of the spline in t parameter */
00328     long type)          /* description of range space */
00329 { 
00330     Mapdesc *mapdesc = maplist.locate( type );
00331 
00332     if( mapdesc == 0 ) {
00333     do_nurbserror( 35 );
00334     isDataValid = 0;
00335     return;
00336     }
00337 
00338     if( s_byte_stride < 0 ) {
00339     do_nurbserror( 34 );
00340     isDataValid = 0;
00341     return;
00342     }
00343 
00344     if( t_byte_stride < 0 ) {
00345     do_nurbserror( 34 );
00346     isDataValid = 0;
00347     return;
00348     }
00349 
00350     Knotvector sknotvector, tknotvector;
00351 
00352     sknotvector.init( sknot_count, s_byte_stride, sorder, sknot );
00353     if( do_check_knots( &sknotvector, "surface" ) ) return;
00354 
00355     tknotvector.init( tknot_count, t_byte_stride, torder, tknot );
00356     if( do_check_knots( &tknotvector, "surface" ) ) return;
00357 
00358     O_nurbssurface *o_nurbssurface = new(o_nurbssurfacePool) O_nurbssurface(type);
00359     o_nurbssurface->bezier_patches = new(quiltPool) Quilt(mapdesc);
00360 
00361     o_nurbssurface->bezier_patches->toBezier( sknotvector, tknotvector,
00362     ctlarray, mapdesc->getNcoords() ); 
00363     THREAD( do_nurbssurface, o_nurbssurface, do_freenurbssurface );
00364 }
00365 
00366 
00367 /*-----------------------------------------------------------------------------
00368  * setnurbsproperty -
00369  * 
00370  *-----------------------------------------------------------------------------
00371  */
00372 void
00373 NurbsTessellator::setnurbsproperty( long tag, INREAL value )
00374 {
00375     if( ! renderhints.isProperty( tag ) ) {
00376     do_nurbserror( 26 );
00377     } else {
00378     Property *prop = new(propertyPool) Property( tag, value );
00379     THREAD( do_setnurbsproperty, prop, do_freenurbsproperty );
00380     }
00381 }
00382 
00383 /*-----------------------------------------------------------------------------
00384  * setnurbsproperty -
00385  * 
00386  *-----------------------------------------------------------------------------
00387  */
00388 void
00389 NurbsTessellator::setnurbsproperty( long type, long tag, INREAL value )
00390 {
00391     Mapdesc *mapdesc = maplist.locate( type );
00392 
00393     if( mapdesc == 0 ) {
00394     do_nurbserror( 35 );
00395     return;
00396     }
00397 
00398     if( ! mapdesc->isProperty( tag ) ) {
00399     do_nurbserror( 26 );
00400     return;
00401     }
00402 
00403     Property *prop = new(propertyPool) Property( type, tag, value );
00404     THREAD( do_setnurbsproperty2, prop, do_freenurbsproperty );
00405 }
00406 
00407 
00408 /*-----------------------------------------------------------------------------
00409  * getnurbsproperty - 
00410  * 
00411  *-----------------------------------------------------------------------------
00412  */
00413 
00414 void
00415 NurbsTessellator::getnurbsproperty( long tag, INREAL *value )
00416 {
00417     if( renderhints.isProperty( tag ) ) {
00418     *value = renderhints.getProperty( tag );
00419     } else {
00420     do_nurbserror( 26 );
00421     }
00422 }
00423 
00424 /*-----------------------------------------------------------------------------
00425  * getnurbsproperty - 
00426  * 
00427  *-----------------------------------------------------------------------------
00428  */
00429 
00430 void
00431 NurbsTessellator::getnurbsproperty( long type, long tag, INREAL *value )
00432 {
00433     Mapdesc *mapdesc = maplist.locate( type );
00434 
00435     if( mapdesc == 0 ) 
00436     do_nurbserror( 35 );
00437 
00438     if( mapdesc->isProperty( tag  ) ) {
00439     *value = mapdesc->getProperty( tag );
00440     } else {
00441     do_nurbserror( 26 );
00442     }
00443 }
00444 
00445 /*--------------------------------------------------------------------------
00446  * setnurbsproperty - accept a user supplied matrix as culling or sampling mat
00447  *--------------------------------------------------------------------------
00448  */
00449 
00450 void 
00451 NurbsTessellator::setnurbsproperty( long type, long purpose, INREAL *mat )
00452 {
00453     // XXX - cannot be put in display list
00454     Mapdesc *mapdesc = maplist.locate( type );
00455 
00456     if( mapdesc == 0 ) {
00457     do_nurbserror( 35 );
00458     isDataValid = 0;
00459     } else if( purpose == N_BBOXSIZE ) {
00460     mapdesc->setBboxsize( mat );
00461     } else {
00462 #ifndef NDEBUG
00463         dprintf( "ERRORRORRORR!!!\n");
00464 #endif
00465     }
00466 }
00467 
00468 /*--------------------------------------------------------------------------
00469  * setnurbsproperty - accept a user supplied matrix as culling or sampling mat
00470  *--------------------------------------------------------------------------
00471  */
00472 
00473 void 
00474 NurbsTessellator::setnurbsproperty( long type, long purpose, INREAL *mat, 
00475     long rstride, long cstride )
00476 {
00477     // XXX - cannot be put in display list
00478     Mapdesc *mapdesc = maplist.locate( type );
00479 
00480     if( mapdesc == 0 ) {
00481     do_nurbserror( 35 );
00482     isDataValid = 0;
00483     } else if( purpose == N_CULLINGMATRIX ) {
00484     mapdesc->setCmat( mat, rstride, cstride );
00485     } else if( purpose == N_SAMPLINGMATRIX ) {
00486     mapdesc->setSmat( mat, rstride, cstride );
00487     } else if( purpose == N_BBOXMATRIX ) {
00488     mapdesc->setBmat( mat, rstride, cstride );
00489     } else {
00490 #ifndef NDEBUG
00491         dprintf( "ERRORRORRORR!!!\n");
00492 #endif
00493     }
00494 }
00495 
00496 void    
00497 NurbsTessellator::redefineMaps( void )
00498 {
00499     maplist.initialize();
00500 }
00501 
00502 void    
00503 NurbsTessellator::defineMap( long type, long rational, long ncoords )
00504 {
00505     maplist.define( type, (int) rational, (int) ncoords );
00506 }
00507 
00508 void 
00509 NurbsTessellator::discardRecording( void *_dl )
00510 {
00511     delete (DisplayList *) _dl;
00512 }
00513 
00514 void * 
00515 NurbsTessellator::beginRecording( void )
00516 {
00517     dl = new DisplayList( this );
00518     return (void *) dl;
00519 }
00520 
00521 void 
00522 NurbsTessellator::endRecording( void )
00523 {
00524     dl->endList();
00525     dl = 0;
00526 }
00527 
00528 void 
00529 NurbsTessellator::playRecording( void *_dl )
00530 {
00531     playBack = 1;
00532     bgnrender();
00533     ((DisplayList *)_dl)->play();
00534     endrender();
00535     playBack = 0;
00536 }
00537 

Generated on Sun May 27 2012 04:23:40 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.