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.

492 lines
12 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. * backend.c++ - $Revision: 1.5 $
  14. * Derrick Burns - 1991
  15. */
  16. /* Bezier surface backend
  17. - interprets display mode (wireframe,shaded,...)
  18. */
  19. #include "glimport.h"
  20. #include "mystdio.h"
  21. #include "backend.h"
  22. #include "basiccrv.h"
  23. #include "basicsur.h"
  24. #include "nurbscon.h"
  25. /*-------------------------------------------------------------------------
  26. * bgnsurf - preamble to surface definition and evaluations
  27. *-------------------------------------------------------------------------
  28. */
  29. void
  30. Backend::bgnsurf( int wiretris, int wirequads, long nuid )
  31. {
  32. #ifndef NOWIREFRAME
  33. wireframetris = wiretris;
  34. wireframequads = wirequads;
  35. #endif
  36. surfaceEvaluator.bgnmap2f( nuid );
  37. }
  38. void
  39. Backend::patch( REAL ulo, REAL uhi, REAL vlo, REAL vhi )
  40. {
  41. surfaceEvaluator.domain2f( ulo, uhi, vlo, vhi );
  42. }
  43. void
  44. Backend::surfbbox( long type, REAL *from, REAL *to )
  45. {
  46. surfaceEvaluator.range2f( type, from, to );
  47. }
  48. /*-------------------------------------------------------------------------
  49. * surfpts - pass a desription of a surface map
  50. *-------------------------------------------------------------------------
  51. */
  52. void
  53. Backend::surfpts(
  54. long type, /* geometry, color, texture, normal */
  55. REAL *pts, /* control points */
  56. long ustride, /* distance to next point in u direction */
  57. long vstride, /* distance to next point in v direction */
  58. int uorder, /* u parametric order */
  59. int vorder, /* v parametric order */
  60. REAL ulo, /* u lower bound */
  61. REAL uhi, /* u upper bound */
  62. REAL vlo, /* v lower bound */
  63. REAL vhi ) /* v upper bound */
  64. {
  65. surfaceEvaluator.map2f( type,ulo,uhi,ustride,uorder,vlo,vhi,vstride,vorder,pts );
  66. surfaceEvaluator.enable( type );
  67. }
  68. /*-------------------------------------------------------------------------
  69. * surfgrid - define a lattice of points with origin and offset
  70. *-------------------------------------------------------------------------
  71. */
  72. void
  73. Backend::surfgrid( REAL u0, REAL u1, long nu, REAL v0, REAL v1, long nv )
  74. {
  75. surfaceEvaluator.mapgrid2f( nu, u0, u1, nv, v0, v1 );
  76. }
  77. /*-------------------------------------------------------------------------
  78. * surfmesh - evaluate a mesh of points on lattice
  79. *-------------------------------------------------------------------------
  80. */
  81. void
  82. Backend::surfmesh( long u, long v, long n, long m )
  83. {
  84. #ifndef NOWIREFRAME
  85. if( wireframequads ) {
  86. long v0, v1;
  87. long u0f = u, u1f = u+n;
  88. long v0f = v, v1f = v+m;
  89. long parity = (u & 1);
  90. for( v0 = v0f, v1 = v0f++ ; v0<v1f; v0 = v1, v1++ ) {
  91. surfaceEvaluator.bgnline();
  92. for( long u = u0f; u<=u1f; u++ ) {
  93. if( parity ) {
  94. surfaceEvaluator.evalpoint2i( u, v0 );
  95. surfaceEvaluator.evalpoint2i( u, v1 );
  96. } else {
  97. surfaceEvaluator.evalpoint2i( u, v1 );
  98. surfaceEvaluator.evalpoint2i( u, v0 );
  99. }
  100. parity = 1 - parity;
  101. }
  102. surfaceEvaluator.endline();
  103. }
  104. } else {
  105. surfaceEvaluator.mapmesh2f( N_MESHFILL, u, u+n, v, v+m );
  106. }
  107. #else
  108. if( wireframequads ) {
  109. surfaceEvaluator.mapmesh2f( N_MESHLINE, u, u+n, v, v+m );
  110. } else {
  111. surfaceEvaluator.mapmesh2f( N_MESHFILL, u, u+n, v, v+m );
  112. }
  113. #endif
  114. }
  115. /*-------------------------------------------------------------------------
  116. * endsurf - postamble to surface
  117. *-------------------------------------------------------------------------
  118. */
  119. void
  120. Backend::endsurf( void )
  121. {
  122. surfaceEvaluator.endmap2f();
  123. }
  124. /***************************************/
  125. void
  126. Backend::bgntfan( void )
  127. {
  128. // surfaceEvaluator.bgntfan();
  129. }
  130. void
  131. Backend::endtfan( void )
  132. {
  133. // surfaceEvaluator.endtfan();
  134. }
  135. void
  136. Backend::bgnqstrip( void )
  137. {
  138. /*
  139. if(wireframequads)
  140. surfaceEvaluator.polymode( N_MESHLINE );
  141. else
  142. surfaceEvaluator.polymode( N_MESHFILL );
  143. */
  144. surfaceEvaluator.bgnqstrip();
  145. }
  146. void
  147. Backend::endqstrip( void )
  148. {
  149. surfaceEvaluator.endqstrip();
  150. }
  151. void
  152. Backend::evalUStrip(int n_upper, REAL v_upper, REAL* upper_val,
  153. int n_lower, REAL v_lower, REAL* lower_val
  154. )
  155. {
  156. }
  157. void
  158. Backend::evalVStrip(int n_left, REAL u_left, REAL* left_val,
  159. int n_right, REAL u_right, REAL* right_val
  160. )
  161. {
  162. }
  163. /***************************************/
  164. /*-------------------------------------------------------------------------
  165. * bgntmesh - preamble to a triangle mesh
  166. *-------------------------------------------------------------------------
  167. */
  168. void
  169. Backend::bgntmesh( char * )
  170. {
  171. #ifndef NOWIREFRAME
  172. meshindex = 0; /* I think these need to be initialized to zero */
  173. npts = 0;
  174. if( !wireframetris ) {
  175. surfaceEvaluator.bgntmesh();
  176. }
  177. #else
  178. if( wireframetris ) {
  179. surfaceEvaluator.polymode( N_MESHLINE );
  180. surfaceEvaluator.bgntmesh();
  181. } else {
  182. surfaceEvaluator.polymode( N_MESHFILL );
  183. surfaceEvaluator.bgntmesh();
  184. }
  185. #endif
  186. }
  187. void
  188. Backend::tmeshvert( GridTrimVertex *v )
  189. {
  190. if( v->isGridVert() ) {
  191. tmeshvert( v->g );
  192. } else {
  193. tmeshvert( v->t );
  194. }
  195. }
  196. void
  197. Backend::tmeshvertNOGE(TrimVertex *t)
  198. {
  199. #ifdef USE_OPTTT
  200. // surfaceEvaluator.inDoEvalCoord2NOGE( t->param[0], t->param[1], t->cache_point, t->cache_normal);
  201. #endif
  202. }
  203. //opt for a line with the same u.
  204. void
  205. Backend::tmeshvertNOGE_BU(TrimVertex *t)
  206. {
  207. #ifdef USE_OPTTT
  208. // surfaceEvaluator.inDoEvalCoord2NOGE_BU( t->param[0], t->param[1], t->cache_point, t->cache_normal);
  209. #endif
  210. }
  211. //opt for a line with the same v.
  212. void
  213. Backend::tmeshvertNOGE_BV(TrimVertex *t)
  214. {
  215. #ifdef USE_OPTTT
  216. // surfaceEvaluator.inDoEvalCoord2NOGE_BV( t->param[0], t->param[1], t->cache_point, t->cache_normal);
  217. #endif
  218. }
  219. void
  220. Backend::preEvaluateBU(REAL u)
  221. {
  222. // surfaceEvaluator.inPreEvaluateBU_intfac(u);
  223. }
  224. void
  225. Backend::preEvaluateBV(REAL v)
  226. {
  227. // surfaceEvaluator.inPreEvaluateBV_intfac(v);
  228. }
  229. /*-------------------------------------------------------------------------
  230. * tmeshvert - evaluate a point on a triangle mesh
  231. *-------------------------------------------------------------------------
  232. */
  233. void
  234. Backend::tmeshvert( TrimVertex *t )
  235. {
  236. const long nuid = t->nuid;
  237. const REAL u = t->param[0];
  238. const REAL v = t->param[1];
  239. #ifndef NOWIREFRAME
  240. npts++;
  241. if( wireframetris ) {
  242. if( npts >= 3 ) {
  243. surfaceEvaluator.bgnclosedline();
  244. if( mesh[0][2] == 0 )
  245. surfaceEvaluator.evalcoord2f( mesh[0][3], mesh[0][0], mesh[0][1] );
  246. else
  247. surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] );
  248. if( mesh[1][2] == 0 )
  249. surfaceEvaluator.evalcoord2f( mesh[1][3], mesh[1][0], mesh[1][1] );
  250. else
  251. surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] );
  252. surfaceEvaluator.evalcoord2f( nuid, u, v );
  253. surfaceEvaluator.endclosedline();
  254. }
  255. mesh[meshindex][0] = u;
  256. mesh[meshindex][1] = v;
  257. mesh[meshindex][2] = 0;
  258. mesh[meshindex][3] = nuid;
  259. meshindex = (meshindex+1) % 2;
  260. } else {
  261. surfaceEvaluator.evalcoord2f( nuid, u, v );
  262. }
  263. #else
  264. surfaceEvaluator.evalcoord2f( nuid, u, v );
  265. #endif
  266. }
  267. /*-------------------------------------------------------------------------
  268. * tmeshvert - evaluate a grid point of a triangle mesh
  269. *-------------------------------------------------------------------------
  270. */
  271. void
  272. Backend::tmeshvert( GridVertex *g )
  273. {
  274. const long u = g->gparam[0];
  275. const long v = g->gparam[1];
  276. #ifndef NOWIREFRAME
  277. npts++;
  278. if( wireframetris ) {
  279. if( npts >= 3 ) {
  280. surfaceEvaluator.bgnclosedline();
  281. if( mesh[0][2] == 0 )
  282. surfaceEvaluator.evalcoord2f( (long) mesh[0][3], mesh[0][0], mesh[0][1] );
  283. else
  284. surfaceEvaluator.evalpoint2i( (long) mesh[0][0], (long) mesh[0][1] );
  285. if( mesh[1][2] == 0 )
  286. surfaceEvaluator.evalcoord2f( (long) mesh[1][3], mesh[1][0], mesh[1][1] );
  287. else
  288. surfaceEvaluator.evalpoint2i( (long) mesh[1][0], (long) mesh[1][1] );
  289. surfaceEvaluator.evalpoint2i( u, v );
  290. surfaceEvaluator.endclosedline();
  291. }
  292. mesh[meshindex][0] = u;
  293. mesh[meshindex][1] = v;
  294. mesh[meshindex][2] = 1;
  295. meshindex = (meshindex+1) % 2;
  296. } else {
  297. surfaceEvaluator.evalpoint2i( u, v );
  298. }
  299. #else
  300. surfaceEvaluator.evalpoint2i( u, v );
  301. #endif
  302. }
  303. /*-------------------------------------------------------------------------
  304. * swaptmesh - perform a swap of the triangle mesh pointers
  305. *-------------------------------------------------------------------------
  306. */
  307. void
  308. Backend::swaptmesh( void )
  309. {
  310. #ifndef NOWIREFRAME
  311. if( wireframetris ) {
  312. meshindex = 1 - meshindex;
  313. } else {
  314. surfaceEvaluator.swaptmesh();
  315. }
  316. #else
  317. surfaceEvaluator.swaptmesh();
  318. #endif
  319. }
  320. /*-------------------------------------------------------------------------
  321. * endtmesh - postamble to triangle mesh
  322. *-------------------------------------------------------------------------
  323. */
  324. void
  325. Backend::endtmesh( void )
  326. {
  327. #ifndef NOWIREFRAME
  328. if( ! wireframetris )
  329. surfaceEvaluator.endtmesh();
  330. #else
  331. surfaceEvaluator.endtmesh();
  332. surfaceEvaluator.polymode( N_MESHFILL );
  333. #endif
  334. }
  335. /*-------------------------------------------------------------------------
  336. * bgnoutline - preamble to outlined rendering
  337. *-------------------------------------------------------------------------
  338. */
  339. void
  340. Backend::bgnoutline( void )
  341. {
  342. surfaceEvaluator.bgnline();
  343. }
  344. /*-------------------------------------------------------------------------
  345. * linevert - evaluate a point on an outlined contour
  346. *-------------------------------------------------------------------------
  347. */
  348. void
  349. Backend::linevert( TrimVertex *t )
  350. {
  351. surfaceEvaluator.evalcoord2f( t->nuid, t->param[0], t->param[1] );
  352. }
  353. /*-------------------------------------------------------------------------
  354. * linevert - evaluate a grid point of an outlined contour
  355. *-------------------------------------------------------------------------
  356. */
  357. void
  358. Backend::linevert( GridVertex *g )
  359. {
  360. surfaceEvaluator.evalpoint2i( g->gparam[0], g->gparam[1] );
  361. }
  362. /*-------------------------------------------------------------------------
  363. * endoutline - postamble to outlined rendering
  364. *-------------------------------------------------------------------------
  365. */
  366. void
  367. Backend::endoutline( void )
  368. {
  369. surfaceEvaluator.endline();
  370. }
  371. /*-------------------------------------------------------------------------
  372. * triangle - output a triangle
  373. *-------------------------------------------------------------------------
  374. */
  375. void
  376. Backend::triangle( TrimVertex *a, TrimVertex *b, TrimVertex *c )
  377. {
  378. bgntmesh( "spittriangle" );
  379. tmeshvert( a );
  380. tmeshvert( b );
  381. tmeshvert( c );
  382. endtmesh();
  383. }
  384. void
  385. Backend::bgncurv( void )
  386. {
  387. curveEvaluator.bgnmap1f( 0 );
  388. }
  389. void
  390. Backend::segment( REAL ulo, REAL uhi )
  391. {
  392. curveEvaluator.domain1f( ulo, uhi );
  393. }
  394. void
  395. Backend::curvpts(
  396. long type, /* geometry, color, texture, normal */
  397. REAL *pts, /* control points */
  398. long stride, /* distance to next point */
  399. int order, /* parametric order */
  400. REAL ulo, /* lower parametric bound */
  401. REAL uhi ) /* upper parametric bound */
  402. {
  403. curveEvaluator.map1f( type, ulo, uhi, stride, order, pts );
  404. curveEvaluator.enable( type );
  405. }
  406. void
  407. Backend::curvgrid( REAL u0, REAL u1, long nu )
  408. {
  409. curveEvaluator.mapgrid1f( nu, u0, u1 );
  410. }
  411. void
  412. Backend::curvmesh( long from, long n )
  413. {
  414. curveEvaluator.mapmesh1f( N_MESHFILL, from, from+n );
  415. }
  416. void
  417. Backend::curvpt(REAL u)
  418. {
  419. curveEvaluator.evalcoord1f( 0, u );
  420. }
  421. void
  422. Backend::bgnline( void )
  423. {
  424. curveEvaluator.bgnline();
  425. }
  426. void
  427. Backend::endline( void )
  428. {
  429. curveEvaluator.endline();
  430. }
  431. void
  432. Backend::endcurv( void )
  433. {
  434. curveEvaluator.endmap1f();
  435. }