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.

418 lines
9.7 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. * coveandtiler.c++ - $Revision: 1.1 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "myassert.h"
  18. #include "mystdio.h"
  19. #include "coveandt.h"
  20. #include "gridvert.h"
  21. #include "gridtrim.h"
  22. #include "uarray.h"
  23. #include "backend.h"
  24. const int CoveAndTiler::MAXSTRIPSIZE = 1000;
  25. CoveAndTiler::CoveAndTiler( Backend& b )
  26. : backend( b )
  27. { }
  28. CoveAndTiler::~CoveAndTiler( void )
  29. { }
  30. inline void
  31. CoveAndTiler::output( GridVertex &gv )
  32. {
  33. backend.tmeshvert( &gv );
  34. }
  35. inline void
  36. CoveAndTiler::output( TrimVertex *tv )
  37. {
  38. backend.tmeshvert( tv );
  39. }
  40. inline void
  41. CoveAndTiler::output( GridTrimVertex& g )
  42. {
  43. backend.tmeshvert( &g );
  44. }
  45. void
  46. CoveAndTiler::coveAndTile( void )
  47. {
  48. long ustart = (top.ustart >= bot.ustart) ? top.ustart : bot.ustart;
  49. long uend = (top.uend <= bot.uend) ? top.uend : bot.uend;
  50. if( ustart <= uend ) {
  51. tile( bot.vindex, ustart, uend );
  52. if( top.ustart >= bot.ustart )
  53. coveUpperLeft();
  54. else
  55. coveLowerLeft();
  56. if( top.uend <= bot.uend )
  57. coveUpperRight();
  58. else
  59. coveLowerRight();
  60. } else {
  61. TrimVertex blv, tlv, *bl, *tl;
  62. GridTrimVertex bllv, tllv;
  63. TrimVertex *lf = left.first();
  64. TrimVertex *ll = left.last();
  65. if( lf->param[0] >= ll->param[0] ) {
  66. blv.param[0] = lf->param[0];
  67. blv.param[1] = ll->param[1];
  68. blv.nuid = 0; // XXX
  69. assert( blv.param[1] == bot.vval );
  70. bl = &blv;
  71. tl = lf;
  72. tllv.set( lf );
  73. if( ll->param[0] > uarray.uarray[top.ustart-1] ) {
  74. bllv.set( ll );
  75. assert( ll->param[0] <= uarray.uarray[bot.ustart] );
  76. } else {
  77. bllv.set( top.ustart-1, bot.vindex );
  78. }
  79. coveUpperLeftNoGrid( bl );
  80. } else {
  81. tlv.param[0] = ll->param[0];
  82. tlv.param[1] = lf->param[1];
  83. tlv.nuid = 0; // XXX
  84. assert( tlv.param[1] == top.vval );
  85. tl = &tlv;
  86. bl = ll;
  87. bllv.set( ll );
  88. if( lf->param[0] > uarray.uarray[bot.ustart-1] ) {
  89. assert( lf->param[0] <= uarray.uarray[bot.ustart] );
  90. tllv.set( lf );
  91. } else {
  92. tllv.set( bot.ustart-1, top.vindex );
  93. }
  94. coveLowerLeftNoGrid( tl );
  95. }
  96. TrimVertex brv, trv, *br, *tr;
  97. GridTrimVertex brrv, trrv;
  98. TrimVertex *rf = right.first();
  99. TrimVertex *rl = right.last();
  100. if( rf->param[0] <= rl->param[0] ) {
  101. brv.param[0] = rf->param[0];
  102. brv.param[1] = rl->param[1];
  103. brv.nuid = 0; // XXX
  104. assert( brv.param[1] == bot.vval );
  105. br = &brv;
  106. tr = rf;
  107. trrv.set( rf );
  108. if( rl->param[0] < uarray.uarray[top.uend+1] ) {
  109. assert( rl->param[0] >= uarray.uarray[top.uend] );
  110. brrv.set( rl );
  111. } else {
  112. brrv.set( top.uend+1, bot.vindex );
  113. }
  114. coveUpperRightNoGrid( br );
  115. } else {
  116. trv.param[0] = rl->param[0];
  117. trv.param[1] = rf->param[1];
  118. trv.nuid = 0; // XXX
  119. assert( trv.param[1] == top.vval );
  120. tr = &trv;
  121. br = rl;
  122. brrv.set( rl );
  123. if( rf->param[0] < uarray.uarray[bot.uend+1] ) {
  124. assert( rf->param[0] >= uarray.uarray[bot.uend] );
  125. trrv.set( rf );
  126. } else {
  127. trrv.set( bot.uend+1, top.vindex );
  128. }
  129. coveLowerRightNoGrid( tr );
  130. }
  131. backend.bgntmesh( "doit" );
  132. output(trrv);
  133. output(tllv);
  134. output( tr );
  135. output( tl );
  136. output( br );
  137. output( bl );
  138. output(brrv);
  139. output(bllv);
  140. backend.endtmesh();
  141. }
  142. }
  143. void
  144. CoveAndTiler::tile( long vindex, long ustart, long uend )
  145. {
  146. long numsteps = uend - ustart;
  147. if( numsteps == 0 ) return;
  148. if( numsteps > MAXSTRIPSIZE ) {
  149. long umid = ustart + (uend - ustart) / 2;
  150. tile( vindex, ustart, umid );
  151. tile( vindex, umid, uend );
  152. } else {
  153. backend.surfmesh( ustart, vindex-1, numsteps, 1 );
  154. }
  155. }
  156. void
  157. CoveAndTiler::coveUpperRight( void )
  158. {
  159. GridVertex tgv( top.uend, top.vindex );
  160. GridVertex gv( top.uend, bot.vindex );
  161. right.first();
  162. backend.bgntmesh( "coveUpperRight" );
  163. output( right.next() );
  164. output( tgv );
  165. backend.swaptmesh();
  166. output( gv );
  167. coveUR();
  168. backend.endtmesh();
  169. }
  170. void
  171. CoveAndTiler::coveUpperRightNoGrid( TrimVertex* br )
  172. {
  173. backend.bgntmesh( "coveUpperRight" );
  174. output( right.first() );
  175. output( right.next() );
  176. backend.swaptmesh();
  177. output( br );
  178. coveUR();
  179. backend.endtmesh();
  180. }
  181. void
  182. CoveAndTiler::coveUR( )
  183. {
  184. GridVertex gv( top.uend, bot.vindex );
  185. TrimVertex *vert = right.next();
  186. if( vert == NULL ) return;
  187. assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
  188. if( gv.nextu() >= bot.uend ) {
  189. for( ; vert; vert = right.next() ) {
  190. output( vert );
  191. backend.swaptmesh();
  192. }
  193. } else while( 1 ) {
  194. if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
  195. output( vert );
  196. backend.swaptmesh();
  197. vert = right.next();
  198. if( vert == NULL ) break;
  199. } else {
  200. backend.swaptmesh();
  201. output( gv );
  202. if( gv.nextu() == bot.uend ) {
  203. for( ; vert; vert = right.next() ) {
  204. output( vert );
  205. backend.swaptmesh();
  206. }
  207. break;
  208. }
  209. }
  210. }
  211. }
  212. void
  213. CoveAndTiler::coveUpperLeft( void )
  214. {
  215. GridVertex tgv( top.ustart, top.vindex );
  216. GridVertex gv( top.ustart, bot.vindex );
  217. left.first();
  218. backend.bgntmesh( "coveUpperLeft" );
  219. output( tgv );
  220. output( left.next() );
  221. output( gv );
  222. backend.swaptmesh();
  223. coveUL();
  224. backend.endtmesh();
  225. }
  226. void
  227. CoveAndTiler::coveUpperLeftNoGrid( TrimVertex* bl )
  228. {
  229. backend.bgntmesh( "coveUpperLeftNoGrid" );
  230. output( left.first() );
  231. output( left.next() );
  232. output( bl );
  233. backend.swaptmesh();
  234. coveUL();
  235. backend.endtmesh();
  236. }
  237. void
  238. CoveAndTiler::coveUL()
  239. {
  240. GridVertex gv( top.ustart, bot.vindex );
  241. TrimVertex *vert = left.next();
  242. if( vert == NULL ) return;
  243. assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
  244. if( gv.prevu() <= bot.ustart ) {
  245. for( ; vert; vert = left.next() ) {
  246. backend.swaptmesh();
  247. output( vert );
  248. }
  249. } else while( 1 ) {
  250. if( vert->param[0] > uarray.uarray[gv.gparam[0]] ) {
  251. backend.swaptmesh();
  252. output( vert );
  253. vert = left.next();
  254. if( vert == NULL ) break;
  255. } else {
  256. output( gv );
  257. backend.swaptmesh();
  258. if( gv.prevu() == bot.ustart ) {
  259. for( ; vert; vert = left.next() ) {
  260. backend.swaptmesh();
  261. output( vert );
  262. }
  263. break;
  264. }
  265. }
  266. }
  267. }
  268. void
  269. CoveAndTiler::coveLowerLeft( void )
  270. {
  271. GridVertex bgv( bot.ustart, bot.vindex );
  272. GridVertex gv( bot.ustart, top.vindex );
  273. left.last();
  274. backend.bgntmesh( "coveLowerLeft" );
  275. output( left.prev() );
  276. output( bgv );
  277. backend.swaptmesh();
  278. output( gv );
  279. coveLL();
  280. backend.endtmesh();
  281. }
  282. void
  283. CoveAndTiler::coveLowerLeftNoGrid( TrimVertex* tl )
  284. {
  285. backend.bgntmesh( "coveLowerLeft" );
  286. output( left.last() );
  287. output( left.prev() );
  288. backend.swaptmesh();
  289. output( tl );
  290. coveLL( );
  291. backend.endtmesh();
  292. }
  293. void
  294. CoveAndTiler::coveLL()
  295. {
  296. GridVertex gv( bot.ustart, top.vindex );
  297. TrimVertex *vert = left.prev();
  298. if( vert == NULL ) return;
  299. assert( vert->param[0] <= uarray.uarray[gv.gparam[0]] );
  300. if( gv.prevu() <= top.ustart ) {
  301. for( ; vert; vert = left.prev() ) {
  302. output( vert );
  303. backend.swaptmesh();
  304. }
  305. } else while( 1 ) {
  306. if( vert->param[0] > uarray.uarray[gv.gparam[0]] ){
  307. output( vert );
  308. backend.swaptmesh();
  309. vert = left.prev();
  310. if( vert == NULL ) break;
  311. } else {
  312. backend.swaptmesh();
  313. output( gv );
  314. if( gv.prevu() == top.ustart ) {
  315. for( ; vert; vert = left.prev() ) {
  316. output( vert );
  317. backend.swaptmesh();
  318. }
  319. break;
  320. }
  321. }
  322. }
  323. }
  324. void
  325. CoveAndTiler::coveLowerRight( void )
  326. {
  327. GridVertex bgv( bot.uend, bot.vindex );
  328. GridVertex gv( bot.uend, top.vindex );
  329. right.last();
  330. backend.bgntmesh( "coveLowerRight" );
  331. output( bgv );
  332. output( right.prev() );
  333. output( gv );
  334. backend.swaptmesh();
  335. coveLR();
  336. backend.endtmesh( );
  337. }
  338. void
  339. CoveAndTiler::coveLowerRightNoGrid( TrimVertex* tr )
  340. {
  341. backend.bgntmesh( "coveLowerRIght" );
  342. output( right.last() );
  343. output( right.prev() );
  344. output( tr );
  345. backend.swaptmesh();
  346. coveLR();
  347. backend.endtmesh();
  348. }
  349. void
  350. CoveAndTiler::coveLR( )
  351. {
  352. GridVertex gv( bot.uend, top.vindex );
  353. TrimVertex *vert = right.prev();
  354. if( vert == NULL ) return;
  355. assert( vert->param[0] >= uarray.uarray[gv.gparam[0]] );
  356. if( gv.nextu() >= top.uend ) {
  357. for( ; vert; vert = right.prev() ) {
  358. backend.swaptmesh();
  359. output( vert );
  360. }
  361. } else while( 1 ) {
  362. if( vert->param[0] < uarray.uarray[gv.gparam[0]] ) {
  363. backend.swaptmesh();
  364. output( vert );
  365. vert = right.prev();
  366. if( vert == NULL ) break;
  367. } else {
  368. output( gv );
  369. backend.swaptmesh();
  370. if( gv.nextu() == top.uend ) {
  371. for( ; vert; vert = right.prev() ) {
  372. backend.swaptmesh();
  373. output( vert );
  374. }
  375. break;
  376. }
  377. }
  378. }
  379. }