MLRTriangleCloud.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. #if !defined(MLR_MLRCLIPTRICK_HPP)
  6. #include <MLR\MLRClipTrick.hpp>
  7. #endif
  8. extern DWORD gShowClippedPolys;
  9. //#############################################################################
  10. //####################### MLRTriangleCloud ##############################
  11. //#############################################################################
  12. DynamicArrayOf<MLRClippingState>
  13. *MLRTriangleCloud::clipPerVertex;
  14. DynamicArrayOf<Vector4D>
  15. *MLRTriangleCloud::clipExtraCoords;
  16. DynamicArrayOf<RGBAColor>
  17. *MLRTriangleCloud::clipExtraColors;
  18. DynamicArrayOf<int>
  19. *MLRTriangleCloud::clipExtraLength;
  20. MLRTriangleCloud::ClassData*
  21. MLRTriangleCloud::DefaultData = NULL;
  22. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. //
  24. void
  25. MLRTriangleCloud::InitializeClass()
  26. {
  27. Verify(!DefaultData);
  28. Verify(gos_GetCurrentHeap() == StaticHeap);
  29. DefaultData =
  30. new ClassData(
  31. MLRTriangleCloudClassID,
  32. "MidLevelRenderer::MLRTriangleCloud",
  33. MLREffect::DefaultData
  34. );
  35. Register_Object(DefaultData);
  36. clipPerVertex = new DynamicArrayOf<MLRClippingState> (Limits::Max_Number_Vertices_Per_Mesh);
  37. Register_Pointer(clipPerVertex);
  38. clipExtraCoords = new DynamicArrayOf<Vector4D> (Limits::Max_Number_Vertices_Per_Mesh);
  39. Register_Pointer(clipExtraCoords);
  40. clipExtraColors = new DynamicArrayOf<RGBAColor> (Limits::Max_Number_Vertices_Per_Mesh);
  41. Register_Pointer(clipExtraColors);
  42. clipExtraLength = new DynamicArrayOf<int> (Limits::Max_Number_Primitives_Per_Frame);
  43. Register_Pointer(clipExtraLength);
  44. }
  45. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  46. //
  47. void
  48. MLRTriangleCloud::TerminateClass()
  49. {
  50. Unregister_Pointer(clipPerVertex);
  51. delete clipPerVertex;
  52. Unregister_Pointer(clipExtraCoords);
  53. delete clipExtraCoords;
  54. Unregister_Pointer(clipExtraColors);
  55. delete clipExtraColors;
  56. Unregister_Pointer(clipExtraLength);
  57. delete clipExtraLength;
  58. Unregister_Object(DefaultData);
  59. delete DefaultData;
  60. DefaultData = NULL;
  61. }
  62. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. //
  64. MLRTriangleCloud::MLRTriangleCloud(int nr) :
  65. MLREffect(nr, DefaultData)
  66. {
  67. Verify(gos_GetCurrentHeap() == Heap);
  68. usedNrOfTriangles = NULL;
  69. Check_Pointer(this);
  70. drawMode = SortData::TriList;
  71. }
  72. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. //
  74. MLRTriangleCloud::~MLRTriangleCloud()
  75. {
  76. Check_Object(this);
  77. }
  78. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. //
  80. void
  81. MLRTriangleCloud::SetData
  82. (
  83. const int *count,
  84. const Stuff::Point3D *point_data,
  85. const Stuff::RGBAColor *color_data
  86. )
  87. {
  88. Check_Pointer(this);
  89. usedNrOfTriangles = count;
  90. Verify(*usedNrOfTriangles <= maxNrOf);
  91. points = point_data;
  92. colors = color_data;
  93. }
  94. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. //
  96. void
  97. MLRTriangleCloud::Draw (DrawEffectInformation *dInfo, GOSVertexPool *allVerticesToDraw, MLRSorter *sorter)
  98. {
  99. Check_Object(this);
  100. worldToEffect.Invert(*dInfo->effectToWorld);
  101. Transform(*usedNrOfTriangles, 3);
  102. #if 0
  103. Lighting(*shape->worldToShape, dInfo->activeLights, dInfo->nrOfActiveLights);
  104. #endif
  105. if( Clip(dInfo->clippingFlags, allVerticesToDraw) )
  106. {
  107. sorter->AddEffect(this, dInfo->state);
  108. }
  109. }
  110. static MLRClippingState theAnd, theOr, theTest;
  111. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112. //
  113. int
  114. MLRTriangleCloud::Clip(MLRClippingState clippingFlags, GOSVertexPool *vt)
  115. {
  116. Check_Object(this);
  117. int i, j, k;
  118. int end, len = *usedNrOfTriangles;
  119. int ret = 0;
  120. #if EFECT_CLIPPED // this effect gets not clipped
  121. int l, mask, k1, ct=0,
  122. Scalar a=0.0f, bc0, bc1;
  123. #endif
  124. //
  125. //--------------------------------------
  126. // See if we don't have to draw anything
  127. //--------------------------------------
  128. //
  129. if(clippingFlags.GetClippingState() == 0 || len <= 0)
  130. {
  131. if(len <= 0)
  132. {
  133. visible = 0;
  134. }
  135. else
  136. {
  137. Check_Object(vt);
  138. gos_vertices = vt->GetActualVertexPool();
  139. numGOSVertices = 0;
  140. //
  141. //-------------------------------
  142. // Handle the non-indexed version
  143. //-------------------------------
  144. //
  145. for(i=0,j=0;i<len;i++,j+=3)
  146. {
  147. if(IsOn(i) == false)
  148. {
  149. continue;
  150. }
  151. GOSCopyTriangleData(
  152. &gos_vertices[numGOSVertices],
  153. transformedCoords->GetData(),
  154. colors,
  155. j, j+2, j+1,
  156. true
  157. );
  158. numGOSVertices += 3;
  159. }
  160. Check_Object(vt);
  161. vt->Increase(numGOSVertices);
  162. visible = numGOSVertices ? 1 : 0;
  163. }
  164. return visible;
  165. }
  166. int myNumberUsedClipVertex, myNumberUsedClipIndex, myNumberUsedClipLength;
  167. myNumberUsedClipVertex = 0;
  168. myNumberUsedClipIndex = 0;
  169. myNumberUsedClipLength = 0;
  170. gos_vertices = vt->GetActualVertexPool();
  171. numGOSVertices = 0;
  172. //
  173. //-------------------------------
  174. // Handle the non-indexed version
  175. //-------------------------------
  176. //
  177. //
  178. //-----------------------------------------------------------------
  179. // Step through each polygon, making sure that we don't try to clip
  180. // backfaced polygons
  181. //-----------------------------------------------------------------
  182. //
  183. for(i=0,j=0;i<len;i++,j+=3)
  184. {
  185. // if(IsOn(i) == false)
  186. // {
  187. // continue;
  188. // }
  189. TurnVisible(i);
  190. //
  191. //---------------------------------------------------------------
  192. // Test each vertex of the polygon against the allowed clipping
  193. // planes, and accumulate status for which planes always clip and
  194. // which planes clipped at least once
  195. //---------------------------------------------------------------
  196. //
  197. theAnd.SetClippingState(0x3f);
  198. theOr.SetClippingState(0);
  199. end = j+3;
  200. Stuff::Vector4D *v4d = transformedCoords->GetData() + j;
  201. MLRClippingState *cs = clipPerVertex->GetData() + j;
  202. for(k=j;k<end;k++,v4d++,cs++)
  203. {
  204. cs->Clip4dVertex(v4d);
  205. theAnd &= (*clipPerVertex)[k];
  206. theOr |= (*clipPerVertex)[k];
  207. #ifdef LAB_ONLY
  208. if(*cs==0)
  209. {
  210. Set_Statistic(NonClippedVertices, NonClippedVertices+1);
  211. }
  212. else
  213. {
  214. Set_Statistic(ClippedVertices, ClippedVertices+1);
  215. }
  216. #endif
  217. }
  218. theAnd = theOr = 0; //ASSUME NO CLIPPING NEEDED FOR MC2. Its just not done here!
  219. //
  220. //-------------------------------------------------------------------
  221. // If any bit is set for all vertices, then the polygon is completely
  222. // outside the viewing space and we don't have to draw it. On the
  223. // other hand, if no bits at all were ever set, we can do a trivial
  224. // accept of the polygon
  225. //-------------------------------------------------------------------
  226. //
  227. if (theAnd != 0)
  228. {
  229. continue;
  230. // TurnInVisible(i);
  231. }
  232. else if (theOr == 0)
  233. {
  234. // TurnVisible(i);
  235. GOSCopyTriangleData(
  236. &gos_vertices[numGOSVertices],
  237. transformedCoords->GetData(),
  238. colors,
  239. j, j+2, j+1,
  240. true
  241. );
  242. #ifdef LAB_ONLY
  243. if(gShowClippedPolys)
  244. {
  245. gos_vertices[numGOSVertices].argb = 0xff0000ff;
  246. gos_vertices[numGOSVertices].u = 0.0f;
  247. gos_vertices[numGOSVertices].v = 0.0f;
  248. gos_vertices[numGOSVertices+1].argb = 0xff0000ff;
  249. gos_vertices[numGOSVertices+1].u = 0.0f;
  250. gos_vertices[numGOSVertices+1].v = 0.0f;
  251. gos_vertices[numGOSVertices+2].argb = 0xff0000ff;
  252. gos_vertices[numGOSVertices+2].u = 0.0f;
  253. gos_vertices[numGOSVertices+2].v = 0.0f;
  254. }
  255. #endif
  256. numGOSVertices += 3;
  257. ret++;
  258. }
  259. //
  260. //-----------------------------------------------------------------
  261. // It is not a trivial case, so we must now do real clipping on the
  262. // polygon
  263. //-----------------------------------------------------------------
  264. //
  265. else
  266. {
  267. #if EFECT_CLIPPED // this effect gets not clipped
  268. int numberVerticesPerPolygon = 0;
  269. //
  270. //---------------------------------------------------------------
  271. // Handle the case of a single clipping plane by stepping through
  272. // the vertices and finding the edge it originates
  273. //---------------------------------------------------------------
  274. //
  275. if (theOr.GetNumberOfSetBits() == 1)
  276. {
  277. for(k=j;k<end;k++)
  278. {
  279. k1 = (k+1 < end) ? k + 1 : j;
  280. //
  281. //----------------------------------------------------
  282. // If this vertex is inside the viewing space, copy it
  283. // directly to the clipping buffer
  284. //----------------------------------------------------
  285. //
  286. int clipped_index =
  287. myNumberUsedClipVertex + numberVerticesPerPolygon;
  288. theTest = clipPerVertex[k];
  289. if(theTest == 0)
  290. {
  291. clipExtraCoords[clipped_index] = transformedCoords[k];
  292. clipExtraColors[clipped_index] = colors[k];
  293. numberVerticesPerPolygon++;
  294. clipped_index++;
  295. //
  296. //-------------------------------------------------------
  297. // We don't need to clip this edge if the next vertex is
  298. // also in the viewing space, so just move on to the next
  299. // vertex
  300. //-------------------------------------------------------
  301. //
  302. if(clipPerVertex[k1] == 0)
  303. {
  304. continue;
  305. }
  306. }
  307. //
  308. //---------------------------------------------------------
  309. // This vertex is outside the viewing space, so if the next
  310. // vertex is also outside the viewing space, no clipping is
  311. // needed and we throw this vertex away. Since only one
  312. // clipping plane is involved, it must be in the same space
  313. // as the first vertex
  314. //---------------------------------------------------------
  315. //
  316. else if(clipPerVertex[k1] != 0)
  317. {
  318. Verify(clipPerVertex[k1] == clipPerVertex[k]);
  319. continue;
  320. }
  321. //
  322. //--------------------------------------------------
  323. // We now find the distance along the edge where the
  324. // clipping plane will intersect
  325. //--------------------------------------------------
  326. //
  327. mask = 1;
  328. theTest |= clipPerVertex[k1];
  329. //
  330. //-----------------------------------------------------
  331. // Find the boundary conditions that match our clipping
  332. // plane
  333. //-----------------------------------------------------
  334. //
  335. for (l=0; l<MLRClippingState::NextBit; l++)
  336. {
  337. if(theTest.IsClipped(mask))
  338. {
  339. //
  340. //-------------------------------------------
  341. // Find the clipping interval from bc0 to bc1
  342. //-------------------------------------------
  343. //
  344. a = GetLerpFactor(l, (*transformedCoords)[k], (*transformedCoords)[k1]);
  345. Verify(a >= 0.0f && a <= 1.0f);
  346. ct = l;
  347. break;
  348. }
  349. mask <<= 1;
  350. }
  351. //
  352. //------------------------------
  353. // Lerp the homogeneous position
  354. //------------------------------
  355. //
  356. clipExtraCoords[clipped_index].Lerp(
  357. transformedCoords[k],
  358. transformedCoords[k1],
  359. a
  360. );
  361. DoClipTrick(clipExtraCoords[clipped_index], ct);
  362. //
  363. //----------------------------------------------------------
  364. // If there are colors, lerp them in screen space for now as
  365. // most cards do that anyway
  366. //----------------------------------------------------------
  367. //
  368. clipExtraColors[clipped_index].Lerp(
  369. colors[k],
  370. colors[k1],
  371. a
  372. );
  373. //
  374. //--------------------------------
  375. // Bump the polygon's vertex count
  376. //--------------------------------
  377. //
  378. numberVerticesPerPolygon++;
  379. }
  380. }
  381. //
  382. //---------------------------------------------------------------
  383. // We have to handle multiple planes. We do this by creating two
  384. // buffers and we switch between them as we clip plane by plane
  385. //---------------------------------------------------------------
  386. //
  387. else
  388. {
  389. EffectClipData srcPolygon, dstPolygon;
  390. int dstBuffer = 0;
  391. //
  392. //-----------------------------------------------------
  393. // Point the source polygon buffer at our original data
  394. //-----------------------------------------------------
  395. //
  396. srcPolygon.coords = &transformedCoords[j];
  397. srcPolygon.clipPerVertex = &clipPerVertex[j];
  398. srcPolygon.flags = 0;
  399. srcPolygon.colors = const_cast<RGBAColor*>(&colors[j]);
  400. srcPolygon.flags |= 1;
  401. srcPolygon.texCoords = NULL;
  402. srcPolygon.length = 3;
  403. //
  404. //--------------------------------
  405. // Point to the destination buffer
  406. //--------------------------------
  407. //
  408. dstPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
  409. dstPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
  410. dstPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
  411. dstPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
  412. dstPolygon.flags = srcPolygon.flags;
  413. dstPolygon.length = 0;
  414. //
  415. //-----------------------------------------------------------
  416. // Spin through each plane that clipped the primitive and use
  417. // it to actually clip the primitive
  418. //-----------------------------------------------------------
  419. //
  420. mask = 1;
  421. MLRClippingState theNewOr(0);
  422. int loop = 4;
  423. do
  424. {
  425. for(l=0; l<MLRClippingState::NextBit; l++)
  426. {
  427. if(theOr.IsClipped(mask))
  428. {
  429. //
  430. //-----------------------------------
  431. // Clip each vertex against the plane
  432. //-----------------------------------
  433. //
  434. for(k=0;k<srcPolygon.length;k++)
  435. {
  436. k1 = (k+1 < srcPolygon.length) ? k+1 : 0;
  437. theTest = srcPolygon.clipPerVertex[k];
  438. //
  439. //----------------------------------------------------
  440. // If this vertex is inside the viewing space, copy it
  441. // directly to the clipping buffer
  442. //----------------------------------------------------
  443. //
  444. if(theTest.IsClipped(mask) == 0)
  445. {
  446. dstPolygon.coords[dstPolygon.length] =
  447. srcPolygon.coords[k];
  448. dstPolygon.clipPerVertex[dstPolygon.length] =
  449. srcPolygon.clipPerVertex[k];
  450. if(srcPolygon.flags & 0x1)
  451. {
  452. dstPolygon.colors[dstPolygon.length] =
  453. srcPolygon.colors[k];
  454. }
  455. if(srcPolygon.flags & 0x2)
  456. {
  457. dstPolygon.texCoords[dstPolygon.length] =
  458. srcPolygon.texCoords[k];
  459. }
  460. dstPolygon.length++;
  461. //
  462. //-------------------------------------------------------
  463. // We don't need to clip this edge if the next vertex is
  464. // also in the viewing space, so just move on to the next
  465. // vertex
  466. //-------------------------------------------------------
  467. //
  468. if(srcPolygon.clipPerVertex[k1].IsClipped(mask) == 0)
  469. {
  470. continue;
  471. }
  472. }
  473. //
  474. //---------------------------------------------------------
  475. // This vertex is outside the viewing space, so if the next
  476. // vertex is also outside the viewing space, no clipping is
  477. // needed and we throw this vertex away. Since only one
  478. // clipping plane is involved, it must be in the same space
  479. // as the first vertex
  480. //---------------------------------------------------------
  481. //
  482. else if(srcPolygon.clipPerVertex[k1].IsClipped(mask) != 0)
  483. {
  484. Verify(
  485. srcPolygon.clipPerVertex[k1].IsClipped(mask)
  486. == srcPolygon.clipPerVertex[k].IsClipped(mask)
  487. );
  488. continue;
  489. }
  490. //
  491. //-------------------------------------------
  492. // Find the clipping interval from bc0 to bc1
  493. //-------------------------------------------
  494. //
  495. bc0 = GetBC(l, srcPolygon.coords[k]);
  496. bc1 = GetBC(l, srcPolygon.coords[k1]);
  497. Verify(!Close_Enough(bc0, bc1));
  498. a = bc0 / (bc0 - bc1);
  499. Verify(a >= 0.0f && a <= 1.0f);
  500. //
  501. //------------------------------
  502. // Lerp the homogeneous position
  503. //------------------------------
  504. //
  505. dstPolygon.coords[dstPolygon.length].Lerp(
  506. srcPolygon.coords[k],
  507. srcPolygon.coords[k1],
  508. a
  509. );
  510. DoCleanClipTrick(dstPolygon.coords[dstPolygon.length], l);
  511. //
  512. //----------------------------------------------------------
  513. // If there are colors, lerp them in screen space for now as
  514. // most cards do that anyway
  515. //----------------------------------------------------------
  516. //
  517. if(srcPolygon.flags & 1)
  518. {
  519. dstPolygon.colors[dstPolygon.length].Lerp(
  520. srcPolygon.colors[k],
  521. srcPolygon.colors[k1],
  522. a
  523. );
  524. }
  525. //
  526. //-----------------------------------------------------
  527. // If there are texture uv's, we need to lerp them in a
  528. // perspective correct manner
  529. //-----------------------------------------------------
  530. //
  531. if(srcPolygon.flags & 2)
  532. {
  533. dstPolygon.texCoords[dstPolygon.length].Lerp
  534. (
  535. srcPolygon.texCoords[k],
  536. srcPolygon.texCoords[k1],
  537. a
  538. );
  539. }
  540. //
  541. //-------------------------------------
  542. // We have to generate a new clip state
  543. //-------------------------------------
  544. //
  545. dstPolygon.clipPerVertex[dstPolygon.length].Clip4dVertex(&dstPolygon.coords[dstPolygon.length]);
  546. //
  547. //----------------------------------
  548. // Bump the new polygon vertex count
  549. //----------------------------------
  550. //
  551. dstPolygon.length++;
  552. }
  553. //
  554. //-----------------------------------------------
  555. // Swap source and destination buffer pointers in
  556. // preparation for the next plane test
  557. //-----------------------------------------------
  558. //
  559. srcPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
  560. srcPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
  561. srcPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
  562. srcPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
  563. srcPolygon.length = dstPolygon.length;
  564. dstBuffer = !dstBuffer;
  565. dstPolygon.coords = clipBuffer[dstBuffer].coords.GetData();
  566. dstPolygon.colors = clipBuffer[dstBuffer].colors.GetData();
  567. dstPolygon.texCoords = clipBuffer[dstBuffer].texCoords.GetData();
  568. dstPolygon.clipPerVertex = clipBuffer[dstBuffer].clipPerVertex.GetData();
  569. dstPolygon.length = 0;
  570. }
  571. mask = mask << 1;
  572. }
  573. theNewOr = 0;
  574. for(k=0;k<srcPolygon.length;k++)
  575. {
  576. theNewOr |= srcPolygon.clipPerVertex[k];
  577. }
  578. theOr == theNewOr;
  579. loop++;
  580. } while (theNewOr != 0 && loop--);
  581. Verify(theNewOr == 0);
  582. //
  583. //--------------------------------------------------
  584. // Move the most recent polygon into the clip buffer
  585. //--------------------------------------------------
  586. //
  587. for(k=0;k<srcPolygon.length;k++)
  588. {
  589. int clipped_index = myNumberUsedClipVertex + k;
  590. if(srcPolygon.coords[k].z == srcPolygon.coords[k].w)
  591. {
  592. srcPolygon.coords[k].z -= SMALL;
  593. }
  594. clipExtraCoords[clipped_index] = srcPolygon.coords[k];
  595. clipExtraColors[clipped_index] = srcPolygon.colors[k];
  596. }
  597. numberVerticesPerPolygon = srcPolygon.length;
  598. }
  599. clipExtraLength[myNumberUsedClipLength] = numberVerticesPerPolygon;
  600. myNumberUsedClipVertex += numberVerticesPerPolygon;
  601. myNumberUsedClipLength++;
  602. ret++;
  603. // clip
  604. // dont draw the original
  605. TurnInVisible(i);
  606. #endif
  607. }
  608. }
  609. #if EFECT_CLIPPED // this effect gets not clipped
  610. if(myNumberUsedClipLength > 0)
  611. {
  612. for(i=0,j=0;i<myNumberUsedClipLength;i++)
  613. {
  614. int stride = clipExtraLength[i];
  615. for(k=1;k<stride-1;k++)
  616. {
  617. Verify((vt->GetLast() + 3 + numGOSVertices) < vt->GetLength());
  618. GOSCopyTriangleData(
  619. &gos_vertices[numGOSVertices],
  620. clipExtraCoords.GetData(),
  621. clipExtraColors.GetData(),
  622. j, j+k+1, j+k,
  623. true
  624. );
  625. #ifdef LAB_ONLY
  626. if(gShowClippedPolys)
  627. {
  628. gos_vertices[numGOSVertices].argb = 0xffff0000;
  629. gos_vertices[numGOSVertices].u = 0.0f;
  630. gos_vertices[numGOSVertices].v = 0.0f;
  631. gos_vertices[numGOSVertices+1].argb = 0xffff0000;
  632. gos_vertices[numGOSVertices+1].u = 0.0f;
  633. gos_vertices[numGOSVertices+1].v = 0.0f;
  634. gos_vertices[numGOSVertices+2].argb = 0xffff0000;
  635. gos_vertices[numGOSVertices+2].u = 0.0f;
  636. gos_vertices[numGOSVertices+2].v = 0.0f;
  637. }
  638. #endif
  639. numGOSVertices += 3;
  640. }
  641. j += stride;
  642. }
  643. }
  644. #endif
  645. vt->Increase(numGOSVertices);
  646. visible = numGOSVertices ? 1 : 0;
  647. if(visible)
  648. {
  649. }
  650. else
  651. {
  652. }
  653. return visible;
  654. }
  655. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  656. //
  657. void
  658. MLRTriangleCloud::TestInstance() const
  659. {
  660. if (usedNrOfTriangles)
  661. {
  662. Check_Pointer(usedNrOfTriangles);
  663. Verify(*usedNrOfTriangles >= 0);
  664. Verify(*usedNrOfTriangles <= maxNrOf);
  665. }
  666. }