Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

651 lines
16 KiB

  1. /**************************************************************************
  2. * *
  3. * Copyright (C) 1992, Silicon Graphics, Inc. *
  4. * *
  5. * These coded instructions, statements, and computer programs contain *
  6. * unpublished proprietary information of Silicon Graphics, Inc., and *
  7. * are protected by Federal copyright law. They may not be disclosed *
  8. * to third parties or copied or duplicated in any form, in whole or *
  9. * in part, without the prior written consent of Silicon Graphics, Inc. *
  10. * *
  11. **************************************************************************/
  12. /*
  13. * nurbstess.c++ - $Revision: 1.2 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "myassert.h"
  18. #include "mysetjmp.h"
  19. #include "mystdio.h"
  20. #include "nurbscon.h"
  21. #include "nurbstes.h"
  22. #include "bufpool.h"
  23. #include "quilt.h"
  24. #include "knotvect.h"
  25. #include "mapdesc.h"
  26. #include "maplist.h"
  27. void
  28. NurbsTessellator::resetObjects( void )
  29. {
  30. subdivider.clear();
  31. }
  32. void
  33. NurbsTessellator::makeobj( int )
  34. {
  35. #ifndef NDEBUG
  36. dprintf( "makeobj\n" );
  37. #endif
  38. }
  39. void
  40. NurbsTessellator::closeobj( void )
  41. {
  42. #ifndef NDEBUG
  43. dprintf( "closeobj\n" );
  44. #endif
  45. }
  46. void
  47. NurbsTessellator::bgnrender( void )
  48. {
  49. #ifndef NDEBUG
  50. dprintf( "bgnrender\n" );
  51. #endif
  52. }
  53. void
  54. NurbsTessellator::endrender( void )
  55. {
  56. #ifndef NDEBUG
  57. dprintf( "endrender\n" );
  58. #endif
  59. }
  60. /*-----------------------------------------------------------------------------
  61. * do_freebgnsurface - free o_surface structure
  62. *
  63. * Client: do_freeall(), bgnsurface()
  64. *-----------------------------------------------------------------------------
  65. */
  66. void
  67. NurbsTessellator::do_freebgnsurface( O_surface *o_surface )
  68. {
  69. o_surface->deleteMe( o_surfacePool );
  70. }
  71. /*-----------------------------------------------------------------------------
  72. * do_bgnsurface - begin the display of a surface
  73. *
  74. * Client: bgnsurface()
  75. *-----------------------------------------------------------------------------
  76. */
  77. void
  78. NurbsTessellator::do_bgnsurface( O_surface *o_surface )
  79. {
  80. if( inSurface ) {
  81. do_nurbserror( 27 );
  82. endsurface();
  83. }
  84. inSurface = 1;
  85. if( ! playBack ) bgnrender();
  86. isTrimModified = 0;
  87. isSurfaceModified = 0;
  88. isDataValid = 1;
  89. numTrims = 0;
  90. currentSurface = o_surface;
  91. nextTrim = &( currentSurface->o_trim );
  92. nextNurbssurface = &( currentSurface->o_nurbssurface );
  93. }
  94. /*-----------------------------------------------------------------------------
  95. * do_bgncurve - begin the display of a curve
  96. *
  97. * Client: bgncurve()
  98. *-----------------------------------------------------------------------------
  99. */
  100. void
  101. NurbsTessellator::do_bgncurve( O_curve *o_curve )
  102. {
  103. if ( inCurve ) {
  104. do_nurbserror( 6 );
  105. endcurve();
  106. }
  107. inCurve = 1;
  108. currentCurve = o_curve;
  109. currentCurve->curvetype = ct_none;
  110. if( inTrim ) {
  111. if( *nextCurve != o_curve ) {
  112. isCurveModified = 1;
  113. *nextCurve = o_curve;
  114. }
  115. } else {
  116. if( ! playBack ) bgnrender();
  117. isDataValid = 1;
  118. }
  119. nextCurve = &(o_curve->next);
  120. nextPwlcurve = &(o_curve->curve.o_pwlcurve);
  121. nextNurbscurve = &(o_curve->curve.o_nurbscurve);
  122. }
  123. /*-----------------------------------------------------------------------------
  124. * do_endcurve -
  125. *
  126. * Client: endcurve()
  127. *-----------------------------------------------------------------------------
  128. */
  129. void
  130. NurbsTessellator::do_endcurve( void )
  131. {
  132. if( ! inCurve ) {
  133. do_nurbserror( 7 );
  134. return;
  135. }
  136. inCurve = 0;
  137. *nextCurve = 0;
  138. if (currentCurve->curvetype == ct_nurbscurve)
  139. *nextNurbscurve = 0;
  140. else
  141. *nextPwlcurve = 0;
  142. if ( ! inTrim ) {
  143. if( ! isDataValid ) {
  144. do_freecurveall( currentCurve );
  145. return;
  146. }
  147. int errval;
  148. errval = ::mysetjmp( jumpbuffer );
  149. if( errval == 0 ) {
  150. if( currentCurve->curvetype == ct_nurbscurve ) {
  151. subdivider.beginQuilts();
  152. for( O_nurbscurve *n = currentCurve->curve.o_nurbscurve; n != 0; n = n->next )
  153. subdivider.addQuilt( n->bezier_curves );
  154. subdivider.endQuilts();
  155. subdivider.drawCurves();
  156. if( ! playBack ) endrender();
  157. } else {
  158. /* XXX */
  159. if( ! playBack ) endrender();
  160. /*do_draw_pwlcurve( currentCurve->curve.o_pwlcurve ) */;
  161. do_nurbserror( 9 );
  162. }
  163. } else {
  164. if( ! playBack ) endrender();
  165. do_nurbserror( errval );
  166. }
  167. do_freecurveall( currentCurve );
  168. resetObjects();
  169. }
  170. }
  171. /*-----------------------------------------------------------------------------
  172. * do_endsurface - mark end of surface, display surface, free immediate data
  173. *
  174. * Client:
  175. *-----------------------------------------------------------------------------
  176. */
  177. void
  178. NurbsTessellator::do_endsurface( void )
  179. {
  180. if( inTrim ) {
  181. do_nurbserror( 12 );
  182. endtrim();
  183. }
  184. if( ! inSurface ) {
  185. do_nurbserror( 13 );
  186. return;
  187. }
  188. inSurface = 0;
  189. *nextNurbssurface = 0;
  190. if( ! isDataValid ) {
  191. do_freeall( );
  192. return;
  193. }
  194. if( *nextTrim != 0 ) {
  195. isTrimModified = 1;
  196. *nextTrim = 0;
  197. }
  198. int errval;
  199. errval = ::mysetjmp( jumpbuffer );
  200. if( errval == 0 ) {
  201. if( numTrims > 0 ) {
  202. subdivider.beginTrims();
  203. for( O_trim *trim = currentSurface->o_trim; trim; trim = trim->next ) {
  204. subdivider.beginLoop();
  205. for( O_curve *curve = trim->o_curve; curve; curve = curve->next ) {
  206. curve->used = 0;
  207. assert( curve->curvetype != ct_none );
  208. if (curve->curvetype == ct_pwlcurve) {
  209. O_pwlcurve *c = curve->curve.o_pwlcurve;
  210. subdivider.addArc( c->npts, c->pts, curve->nuid );
  211. } else {
  212. Quilt *quilt = curve->curve.o_nurbscurve->bezier_curves;
  213. Quiltspec *qspec = quilt->qspec;
  214. REAL *cpts = quilt->cpts + qspec->offset;
  215. REAL *cptsend = cpts + (qspec->width * qspec->order * qspec->stride);
  216. for( ; cpts != cptsend; cpts += qspec->order*qspec->stride )
  217. subdivider.addArc( cpts, quilt, curve->nuid );
  218. }
  219. }
  220. subdivider.endLoop();
  221. }
  222. subdivider.endTrims();
  223. }
  224. subdivider.beginQuilts();
  225. for( O_nurbssurface *n = currentSurface->o_nurbssurface; n; n = n->next )
  226. subdivider.addQuilt( n->bezier_patches );
  227. subdivider.endQuilts();
  228. subdivider.drawSurfaces( currentSurface->nuid );
  229. if( ! playBack ) endrender();
  230. } else {
  231. if( ! playBack ) endrender();
  232. do_nurbserror( errval );
  233. }
  234. do_freeall( );
  235. resetObjects();
  236. }
  237. /*-----------------------------------------------------------------------------
  238. * do_freeall - free all data allocated in immediate mode
  239. *
  240. * Client:
  241. *-----------------------------------------------------------------------------
  242. */
  243. void
  244. NurbsTessellator::do_freeall( void )
  245. {
  246. for( O_trim *o_trim = currentSurface->o_trim; o_trim; ) {
  247. O_trim *next_o_trim = o_trim->next;
  248. for( O_curve *curve = o_trim->o_curve; curve; ) {
  249. O_curve *next_o_curve = curve->next;
  250. do_freecurveall( curve );
  251. curve = next_o_curve;
  252. }
  253. if( o_trim->save == 0 ) do_freebgntrim( o_trim );
  254. o_trim = next_o_trim;
  255. }
  256. O_nurbssurface *nurbss, *next_nurbss;
  257. for( nurbss= currentSurface->o_nurbssurface; nurbss; nurbss = next_nurbss) {
  258. next_nurbss = nurbss->next;
  259. if( nurbss->save == 0 )
  260. do_freenurbssurface( nurbss );
  261. else
  262. nurbss->used = 0;
  263. }
  264. if( currentSurface->save == 0 ) do_freebgnsurface( currentSurface );
  265. }
  266. void
  267. NurbsTessellator::do_freecurveall( O_curve *curve )
  268. {
  269. assert( curve->curvetype != ct_none );
  270. if( curve->curvetype == ct_nurbscurve ) {
  271. O_nurbscurve *ncurve, *next_ncurve;
  272. for( ncurve=curve->curve.o_nurbscurve; ncurve; ncurve=next_ncurve ) {
  273. next_ncurve = ncurve->next;
  274. if( ncurve->save == 0 )
  275. do_freenurbscurve( ncurve );
  276. else
  277. ncurve->used = 0;
  278. }
  279. } else {
  280. O_pwlcurve *pcurve, *next_pcurve;
  281. for( pcurve=curve->curve.o_pwlcurve; pcurve; pcurve=next_pcurve ) {
  282. next_pcurve = pcurve->next;
  283. if( pcurve->save == 0 )
  284. do_freepwlcurve( pcurve );
  285. else
  286. pcurve->used = 0;
  287. }
  288. }
  289. if( curve->save == 0 )
  290. do_freebgncurve( curve );
  291. }
  292. /*-----------------------------------------------------------------------------
  293. * do_freebgntrim - free the space allocated for a trim loop
  294. *
  295. * Client:
  296. *-----------------------------------------------------------------------------
  297. */
  298. void
  299. NurbsTessellator::do_freebgntrim( O_trim *o_trim )
  300. {
  301. o_trim->deleteMe( o_trimPool );
  302. }
  303. /*-----------------------------------------------------------------------------
  304. * do_bgntrim - link in a trim loop to the current trimmed surface description
  305. *
  306. * Client: bgntrim()
  307. *-----------------------------------------------------------------------------
  308. */
  309. void
  310. NurbsTessellator::do_bgntrim( O_trim *o_trim )
  311. {
  312. if( ! inSurface ) {
  313. do_nurbserror( 15 );
  314. bgnsurface( 0 );
  315. inSurface = 2;
  316. }
  317. if( inTrim ) {
  318. do_nurbserror( 16 );
  319. endtrim();
  320. }
  321. inTrim = 1;
  322. if( *nextTrim != o_trim ) {
  323. isTrimModified = 1;
  324. *nextTrim = o_trim;
  325. }
  326. currentTrim = o_trim;
  327. nextTrim = &(o_trim->next);
  328. nextCurve = &(o_trim->o_curve);
  329. }
  330. /*-----------------------------------------------------------------------------
  331. * do_endtrim - mark the end of the current trim loop
  332. *
  333. * Client: endtrim()
  334. *-----------------------------------------------------------------------------
  335. */
  336. void
  337. NurbsTessellator::do_endtrim( void )
  338. {
  339. if( ! inTrim ) {
  340. do_nurbserror( 17 );
  341. return;
  342. }
  343. inTrim = 0;
  344. if( currentTrim->o_curve == 0 ) {
  345. do_nurbserror( 18 );
  346. isDataValid = 0;
  347. }
  348. numTrims++;
  349. if( *nextCurve != 0 ) {
  350. isTrimModified = 1;
  351. *nextCurve = 0;
  352. }
  353. }
  354. /*-----------------------------------------------------------------------------
  355. * do_freepwlcurve -
  356. *
  357. * Client:
  358. *-----------------------------------------------------------------------------
  359. */
  360. void
  361. NurbsTessellator::do_freepwlcurve( O_pwlcurve *o_pwlcurve )
  362. {
  363. o_pwlcurve->deleteMe( o_pwlcurvePool );
  364. }
  365. void
  366. NurbsTessellator::do_freebgncurve( O_curve *o_curve )
  367. {
  368. o_curve->deleteMe( o_curvePool );
  369. }
  370. /*-----------------------------------------------------------------------------
  371. * do_pwlcurve - link in pwl trim loop to the current surface description
  372. *
  373. * Client: pwlcurve()
  374. *-----------------------------------------------------------------------------
  375. */
  376. void
  377. NurbsTessellator::do_pwlcurve( O_pwlcurve *o_pwlcurve )
  378. {
  379. if( ! inTrim ) {
  380. do_nurbserror( 19 );
  381. if( o_pwlcurve->save == 0 )
  382. do_freepwlcurve(o_pwlcurve );
  383. return;
  384. }
  385. if( ! inCurve ) {
  386. bgncurve( 0 );
  387. inCurve = 2;
  388. }
  389. if( o_pwlcurve->used ) {
  390. do_nurbserror( 20 );
  391. isDataValid = 0;
  392. return;
  393. } else
  394. o_pwlcurve->used = 1;
  395. if( currentCurve->curvetype == ct_none ) {
  396. currentCurve->curvetype = ct_pwlcurve;
  397. } else if( currentCurve->curvetype != ct_pwlcurve ) {
  398. do_nurbserror( 21 );
  399. isDataValid = 0;
  400. return;
  401. }
  402. if( *nextPwlcurve != o_pwlcurve ) {
  403. isCurveModified = 1;
  404. *nextPwlcurve = o_pwlcurve;
  405. }
  406. nextPwlcurve = &(o_pwlcurve->next);
  407. if( o_pwlcurve->owner != currentCurve ) {
  408. isCurveModified = 1;
  409. o_pwlcurve->owner = currentCurve;
  410. }
  411. if( (inCurve == 2) )
  412. endcurve();
  413. }
  414. /*-----------------------------------------------------------------------------
  415. * do_freenurbscurve -
  416. *
  417. * Client:
  418. *-----------------------------------------------------------------------------
  419. */
  420. void
  421. NurbsTessellator::do_freenurbscurve( O_nurbscurve *o_nurbscurve )
  422. {
  423. o_nurbscurve->bezier_curves->deleteMe( quiltPool );
  424. o_nurbscurve->deleteMe( o_nurbscurvePool );
  425. }
  426. /*-----------------------------------------------------------------------------
  427. * do_nurbscurve -
  428. *
  429. * Client: nurbscurve()
  430. *-----------------------------------------------------------------------------
  431. */
  432. void
  433. NurbsTessellator::do_nurbscurve( O_nurbscurve *o_nurbscurve )
  434. {
  435. if ( ! inCurve ) {
  436. bgncurve( 0 );
  437. inCurve = 2;
  438. }
  439. if( o_nurbscurve->used ) {
  440. /* error - curve was already called in current surface */
  441. do_nurbserror( 23 );
  442. isDataValid = 0;
  443. return;
  444. } else
  445. o_nurbscurve->used = 1;
  446. if( currentCurve->curvetype == ct_none ) {
  447. currentCurve->curvetype = ct_nurbscurve;
  448. } else if( currentCurve->curvetype != ct_nurbscurve ) {
  449. do_nurbserror( 24 );
  450. isDataValid = 0;
  451. return;
  452. }
  453. if( *nextNurbscurve != o_nurbscurve ) {
  454. isCurveModified = 1;
  455. *nextNurbscurve = o_nurbscurve;
  456. }
  457. nextNurbscurve = &(o_nurbscurve->next);
  458. if( o_nurbscurve->owner != currentCurve ) {
  459. isCurveModified = 1;
  460. o_nurbscurve->owner = currentCurve;
  461. }
  462. if( o_nurbscurve->owner == 0 )
  463. isCurveModified = 1;
  464. if( inCurve == 2 )
  465. endcurve();
  466. }
  467. /*-----------------------------------------------------------------------------
  468. * do_freenurbssurface -
  469. *
  470. * Client:
  471. *-----------------------------------------------------------------------------
  472. */
  473. void
  474. NurbsTessellator::do_freenurbssurface( O_nurbssurface *o_nurbssurface )
  475. {
  476. o_nurbssurface->bezier_patches->deleteMe( quiltPool );
  477. o_nurbssurface->deleteMe( o_nurbssurfacePool );
  478. }
  479. /*-----------------------------------------------------------------------------
  480. * do_nurbssurface -
  481. *
  482. * Client: nurbssurface()
  483. *-----------------------------------------------------------------------------
  484. */
  485. void
  486. NurbsTessellator::do_nurbssurface( O_nurbssurface *o_nurbssurface )
  487. {
  488. if( ! inSurface ) {
  489. bgnsurface( 0 );
  490. inSurface = 2;
  491. }
  492. if( o_nurbssurface->used ) {
  493. /* error - surface was already called in current block */
  494. do_nurbserror( 25 );
  495. isDataValid = 0;
  496. return;
  497. } else
  498. o_nurbssurface->used = 1;
  499. if( *nextNurbssurface != o_nurbssurface ) {
  500. isSurfaceModified = 1;
  501. *nextNurbssurface = o_nurbssurface;
  502. }
  503. if( o_nurbssurface->owner != currentSurface ) {
  504. isSurfaceModified = 1;
  505. o_nurbssurface->owner = currentSurface;
  506. }
  507. nextNurbssurface = &(o_nurbssurface->next);
  508. if( inSurface == 2 )
  509. endsurface();
  510. }
  511. /*-----------------------------------------------------------------------------
  512. * do_freenurbsproperty
  513. *
  514. *-----------------------------------------------------------------------------
  515. */
  516. void
  517. NurbsTessellator::do_freenurbsproperty( Property *prop )
  518. {
  519. prop->deleteMe( propertyPool );
  520. }
  521. /*-----------------------------------------------------------------------------
  522. * do_setnurbsproperty -
  523. *
  524. *-----------------------------------------------------------------------------
  525. */
  526. void
  527. NurbsTessellator::do_setnurbsproperty( Property *prop )
  528. {
  529. renderhints.setProperty( prop->tag, prop->value );
  530. if( prop->save == 0 )
  531. do_freenurbsproperty( prop );
  532. }
  533. void
  534. NurbsTessellator::do_setnurbsproperty2( Property *prop )
  535. {
  536. Mapdesc *mapdesc = maplist.find( prop->type );
  537. mapdesc->setProperty( prop->tag, prop->value );
  538. if( prop->save == 0 )
  539. do_freenurbsproperty( prop );
  540. }
  541. void
  542. NurbsTessellator::errorHandler( int )
  543. {
  544. }
  545. void
  546. NurbsTessellator::do_nurbserror( int msg )
  547. {
  548. errorHandler( msg );
  549. }
  550. int
  551. NurbsTessellator::do_check_knots( Knotvector *knots, char *msg )
  552. {
  553. int status = knots->validate();
  554. if( status ) {
  555. do_nurbserror( status );
  556. if( renderhints.errorchecking != N_NOMSG ) knots->show( msg );
  557. }
  558. return status;
  559. }