MLRPrimitive.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. //#############################################################################
  6. //############################### ClipPolygon ##################################
  7. //#############################################################################
  8. ClipPolygon::ClipPolygon()
  9. {
  10. coords.SetLength(Limits::Max_Number_Vertices_Per_Polygon);
  11. colors.SetLength(Limits::Max_Number_Vertices_Per_Polygon);
  12. texCoords.SetLength(Limits::Max_Number_Vertices_Per_Polygon);
  13. clipPerVertex.SetLength(Limits::Max_Number_Vertices_Per_Polygon);
  14. }
  15. //#############################################################################
  16. //############################### MLRPrimitive ##################################
  17. //#############################################################################
  18. DWORD Statistics::MLR_TransformedVertices = 0;
  19. DWORD Statistics::MLR_LitVertices = 0;
  20. DWORD Statistics::MLR_Primitives = 0;
  21. DWORD Statistics::MLR_NonClippedVertices = 0;
  22. DWORD Statistics::MLR_ClippedVertices = 0;
  23. DWORD Statistics::MLR_PrimitiveKB = 0;
  24. DWORD Statistics::MLR_PolysClippedButOutside = 0;
  25. DWORD Statistics::MLR_PolysClippedButInside = 0;
  26. DWORD Statistics::MLR_PolysClippedButOnePlane = 0;
  27. DWORD Statistics::MLR_PolysClippedButGOnePlane = 0;
  28. gos_CycleData Statistics::MLR_ClipTime;
  29. DWORD Statistics::MLR_NumAllIndices = 1;
  30. DWORD Statistics::MLR_NumAllVertices = 1;
  31. float Statistics::MLR_Index_Over_Vertex_Ratio = 1.0f;
  32. MLRPrimitive::ClassData*
  33. MLRPrimitive::DefaultData = NULL;
  34. DynamicArrayOf<MLRClippingState>
  35. MLRPrimitive::clipPerVertex;
  36. DynamicArrayOf<Vector4D>
  37. MLRPrimitive::clipExtraCoords;
  38. #if COLOR_AS_DWORD
  39. DynamicArrayOf<DWORD>
  40. #else
  41. DynamicArrayOf<RGBAColor>
  42. #endif
  43. MLRPrimitive::clipExtraColors;
  44. DynamicArrayOf<Vector2DScalar>
  45. MLRPrimitive::clipExtraTexCoords;
  46. DynamicArrayOf<int>
  47. MLRPrimitive::clipExtraIndex;
  48. DynamicArrayOf<unsigned short>
  49. MLRPrimitive::clipExtraLength;
  50. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51. //
  52. void
  53. MLRPrimitive::InitializeClass()
  54. {
  55. Verify(!DefaultData);
  56. DefaultData =
  57. new ClassData(
  58. MLRPrimitiveClassID,
  59. "MidLevelRenderer::MLRPrimitive",
  60. Plug::DefaultData,
  61. NULL
  62. );
  63. Register_Object(DefaultData);
  64. clipPerVertex.SetLength(Limits::Max_Number_Vertices_Per_Mesh);
  65. clipExtraCoords.SetLength(Limits::Max_Number_Vertices_Per_Mesh);
  66. clipExtraColors.SetLength(Limits::Max_Number_Vertices_Per_Mesh);
  67. clipExtraTexCoords.SetLength(Limits::Max_Number_Vertices_Per_Mesh);
  68. clipExtraIndex.SetLength(Limits::Max_Number_Vertices_Per_Mesh);
  69. clipExtraLength.SetLength(Limits::Max_Number_Primitives_Per_Frame);
  70. }
  71. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. //
  73. void
  74. MLRPrimitive::TerminateClass()
  75. {
  76. clipPerVertex.SetLength(0);
  77. clipExtraCoords.SetLength(0);
  78. clipExtraColors.SetLength(0);
  79. clipExtraTexCoords.SetLength(0);
  80. clipExtraIndex.SetLength(0);
  81. clipExtraLength.SetLength(0);
  82. Unregister_Object(DefaultData);
  83. delete DefaultData;
  84. DefaultData = NULL;
  85. }
  86. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. //
  88. MLRPrimitive::MLRPrimitive(
  89. ClassData *class_data,
  90. MemoryStream *stream,
  91. int version
  92. ):
  93. Plug(class_data)
  94. {
  95. Check_Pointer(this);
  96. Check_Object(stream);
  97. switch(version)
  98. {
  99. case 1:
  100. {
  101. actualColors = &colors;
  102. MemoryStreamIO_Read(stream, &coords);
  103. numVertices = coords.GetLength();
  104. transformedCoords.SetLength(numVertices);
  105. litColors.SetLength(numVertices);
  106. int i, len;
  107. #if COLOR_AS_DWORD
  108. Stuff::DynamicArrayOf<Stuff::RGBAColor> rgbaColors;
  109. MemoryStreamIO_Read(stream, &rgbaColors);
  110. len = rgbaColors.GetLength();
  111. const Stuff::RGBAColor *data = rgbaColors.GetData();
  112. colors.SetLength(len);
  113. for(i=0;i<len;i++)
  114. {
  115. colors[i] = GOSCopyColor(data+i);
  116. }
  117. #else
  118. MemoryStreamIO_Read(stream, &colors);
  119. #endif
  120. MemoryStreamIO_Read(stream, &normals);
  121. MemoryStreamIO_Read(stream, &texCoords);
  122. *stream >> visible;
  123. Stuff::DynamicArrayOf<int> tempLengths;
  124. MemoryStreamIO_Read(stream, &tempLengths);
  125. len = tempLengths.GetLength();
  126. lengths.SetLength(len);
  127. for(i=0;i<len;i++)
  128. {
  129. lengths[i] = (unsigned char)(tempLengths[i] & 0xff);
  130. }
  131. *stream >> visible;
  132. *stream >> drawMode;
  133. referenceState.Load(stream, version);
  134. }
  135. break;
  136. case 2:
  137. {
  138. actualColors = &colors;
  139. MemoryStreamIO_Read(stream, &coords);
  140. numVertices = coords.GetLength();
  141. transformedCoords.SetLength(numVertices);
  142. litColors.SetLength(numVertices);
  143. #if COLOR_AS_DWORD
  144. MemoryStreamIO_Read(stream, &colors);
  145. #else
  146. Stuff::DynamicArrayOf<DWORD> smallColors;
  147. MemoryStreamIO_Read(stream, &smallColors);
  148. int i, len = smallColors.GetLength();
  149. colors.SetLength(len);
  150. DWORD theColor;
  151. for(i=0;i<len;i++)
  152. {
  153. theColor = smallColors[i];
  154. colors[i].blue = (theColor & 0xff) * One_Over_256;
  155. theColor = theColor>>8;
  156. colors[i].green = (theColor & 0xff) * One_Over_256;
  157. theColor = theColor>>8;
  158. colors[i].red = (theColor & 0xff) * One_Over_256;
  159. theColor = theColor>>8;
  160. colors[i].alpha = (theColor & 0xff) * One_Over_256;
  161. }
  162. #endif
  163. MemoryStreamIO_Read(stream, &normals);
  164. MemoryStreamIO_Read(stream, &texCoords);
  165. MemoryStreamIO_Read(stream, &lengths);
  166. *stream >> drawMode;
  167. referenceState.Load(stream, version);
  168. }
  169. break;
  170. default:
  171. STOP(("ERF-Version is newer than loader !"));
  172. break;
  173. }
  174. referenceCount = 1;
  175. }
  176. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  177. //
  178. void
  179. MLRPrimitive::Save(MemoryStream *stream)
  180. {
  181. Check_Object(this);
  182. Check_Object(stream);
  183. *stream << GetClassID();
  184. MemoryStreamIO_Write(stream, &coords);
  185. #if COLOR_AS_DWORD
  186. MemoryStreamIO_Write(stream, &colors);
  187. #else
  188. Stuff::DynamicArrayOf<DWORD> smallColors;
  189. int i, len = colors.GetLength();
  190. const Stuff::RGBAColor *data = colors.GetData();
  191. smallColors.SetLength(len);
  192. for(i=0;i<len;i++)
  193. {
  194. smallColors[i] = GOSCopyColor(data+i);
  195. }
  196. MemoryStreamIO_Write(stream, &smallColors);
  197. #endif
  198. MemoryStreamIO_Write(stream, &normals);
  199. MemoryStreamIO_Write(stream, &texCoords);
  200. // *stream << visible; // changed from version 1 to 2
  201. MemoryStreamIO_Write(stream, &lengths);
  202. // *stream << visible; // changed from version 1 to 2
  203. *stream << static_cast<int>(drawMode);
  204. referenceState.Save(stream);
  205. }
  206. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  207. //
  208. MLRPrimitive::MLRPrimitive(ClassData *class_data):
  209. Plug(class_data), lengths(0),
  210. colors(0), normals(0), texCoords(0), coords(0)
  211. {
  212. referenceState = 0;
  213. state = 0;
  214. numVertices = 0; // number of verts for stats and vert arrays
  215. actualColors = &colors;
  216. referenceCount = 1;
  217. }
  218. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  219. //
  220. MLRPrimitive::~MLRPrimitive()
  221. {
  222. Verify(referenceCount==0);
  223. }
  224. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  225. //
  226. void
  227. MLRPrimitive::TestInstance() const
  228. {
  229. Verify(IsDerivedFrom(DefaultData));
  230. }
  231. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  232. //
  233. void
  234. MLRPrimitive::InitializeDraw()
  235. {
  236. #ifdef LAB_ONLY
  237. Statistics::MLR_NumAllIndices = 1;
  238. Statistics::MLR_NumAllVertices = 1;
  239. #endif
  240. }
  241. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  242. //
  243. void
  244. MLRPrimitive::InitializeDrawPrimitive(int vis, int)
  245. {
  246. gos_vertices = NULL;
  247. numGOSVertices = -1;
  248. visible = vis;
  249. }
  250. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251. //
  252. void
  253. MLRPrimitive::SetSubprimitiveLengths(unsigned char *data, int l)
  254. {
  255. Check_Object(this);
  256. lengths.AssignData(data, l);
  257. }
  258. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  259. //
  260. int
  261. MLRPrimitive::GetSubprimitiveLengths(unsigned char **data)
  262. {
  263. Check_Object(this);
  264. *data = lengths.GetData();
  265. return lengths.GetLength();
  266. }
  267. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  268. //
  269. int
  270. MLRPrimitive::GetSubprimitiveLength (int i) const
  271. {
  272. Check_Object(this);
  273. return (lengths.GetLength() > 0 ? abs(lengths[i]) : 1);
  274. }
  275. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  276. //
  277. void
  278. MLRPrimitive::SetCoordData(
  279. const Point3D *data,
  280. int dataSize
  281. )
  282. {
  283. Check_Object(this);
  284. Check_Pointer(data);
  285. Verify(colors.GetLength() == 0 || dataSize == colors.GetLength());
  286. Verify(normals.GetLength() == 0 || dataSize == normals.GetLength());
  287. Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength());
  288. #if defined (MAX_NUMBER_VERTICES)
  289. Verify(dataSize <= MAX_NUMBER_VERTICES);
  290. #endif
  291. coords.AssignData(data, dataSize);
  292. transformedCoords.SetLength(dataSize);
  293. numVertices = dataSize;
  294. }
  295. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  296. //
  297. void
  298. MLRPrimitive::GetCoordData(
  299. Point3D **data,
  300. int *dataSize
  301. )
  302. {
  303. Check_Object(this);
  304. *data = coords.GetData();
  305. *dataSize = coords.GetLength();
  306. }
  307. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  308. //
  309. void
  310. MLRPrimitive::SetColorData(
  311. #if COLOR_AS_DWORD
  312. const DWORD *data,
  313. #else
  314. const RGBAColor *data,
  315. #endif
  316. int dataSize
  317. )
  318. {
  319. Check_Object(this);
  320. Check_Pointer(data);
  321. Verify(coords.GetLength() == 0 || dataSize == coords.GetLength());
  322. Verify(normals.GetLength() == 0 || dataSize == normals.GetLength());
  323. Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength());
  324. colors.AssignData(data, dataSize);
  325. litColors.SetLength(dataSize);
  326. }
  327. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  328. //
  329. void
  330. MLRPrimitive::GetColorData(
  331. #if COLOR_AS_DWORD
  332. DWORD **data,
  333. #else
  334. RGBAColor **data,
  335. #endif
  336. int *dataSize
  337. )
  338. {
  339. Check_Object(this);
  340. *data = colors.GetData();
  341. *dataSize = colors.GetLength();
  342. }
  343. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  344. //
  345. void
  346. MLRPrimitive::SetNormalData(
  347. const Vector3D *data,
  348. int dataSize
  349. )
  350. {
  351. Check_Object(this);
  352. Check_Pointer(data);
  353. Verify(coords.GetLength() == 0 || dataSize == coords.GetLength());
  354. Verify(colors.GetLength() == 0 || dataSize == colors.GetLength());
  355. Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength());
  356. normals.AssignData(data, dataSize);
  357. }
  358. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  359. //
  360. void
  361. MLRPrimitive::GetNormalData(
  362. Vector3D **data,
  363. int *dataSize
  364. )
  365. {
  366. Check_Object(this);
  367. *data = normals.GetData();
  368. *dataSize = normals.GetLength();
  369. }
  370. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  371. //
  372. void
  373. MLRPrimitive::SetTexCoordData(
  374. const Vector2DScalar *data,
  375. int dataSize
  376. )
  377. {
  378. Check_Object(this);
  379. Check_Pointer(data);
  380. Verify(coords.GetLength() == 0 || dataSize == coords.GetLength());
  381. Verify(colors.GetLength() == 0 || dataSize == colors.GetLength());
  382. Verify(normals.GetLength() == 0 || dataSize == normals.GetLength());
  383. texCoords.AssignData((Vector2DScalar *)data, dataSize);
  384. }
  385. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  386. //
  387. void
  388. MLRPrimitive::GetTexCoordData(
  389. Vector2DScalar **data,
  390. int *dataSize
  391. )
  392. {
  393. Check_Object(this);
  394. *data = texCoords.GetData();
  395. *dataSize = texCoords.GetLength();
  396. }
  397. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  398. //
  399. void
  400. MLRPrimitive::Transform(Matrix4D *mat)
  401. {
  402. Check_Object(this);
  403. int i, len = coords.GetLength();
  404. for(i=0;i<len;i++)
  405. {
  406. transformedCoords[i].Multiply(coords[i], *mat);
  407. }
  408. #ifdef LAB_ONLY
  409. Statistics::MLR_TransformedVertices += len;
  410. #endif
  411. }
  412. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  413. //
  414. void
  415. MLRPrimitive::Lighting (
  416. MLRLight **lights,
  417. int nrLights
  418. )
  419. {
  420. Check_Object(this);
  421. // set the to use colors to the original colors ...
  422. // only lighting could overwrite this;
  423. actualColors = &colors;
  424. if(nrLights == 0)
  425. {
  426. return;
  427. }
  428. if(normals.GetLength() == 0)
  429. {
  430. return;
  431. }
  432. if(lights == NULL)
  433. {
  434. return;
  435. }
  436. switch (GetCurrentState().GetLightingMode())
  437. {
  438. case MLRState::LightingOffMode:
  439. return;
  440. case MLRState::LightingClassicOnlyMode:
  441. {
  442. Verify(colors.GetLength() == litColors.GetLength());
  443. Verify(normals.GetLength() == colors.GetLength());
  444. Verify(coords.GetLength() == colors.GetLength());
  445. int i, k, len = colors.GetLength();
  446. MLRVertexData vertexData;
  447. #if COLOR_AS_DWORD
  448. TO_DO;
  449. #else
  450. RGBAColor *color = &colors[0];
  451. RGBAColor *litColor = &litColors[0];
  452. #if USE_ASSEMBLER_CODE
  453. _asm {
  454. push esi
  455. push edi
  456. mov esi, color
  457. mov edi, litColor
  458. mov ecx, len
  459. _loop1:
  460. mov eax, dword ptr [esi]
  461. mov ebx, dword ptr [esi+4]
  462. mov dword ptr [edi], eax
  463. mov dword ptr [edi+ 4], ebx
  464. mov eax, dword ptr [esi + 8]
  465. mov ebx, dword ptr [esi + 12]
  466. mov dword ptr [edi + 8], eax
  467. mov dword ptr [edi + 12], ebx
  468. add esi,16
  469. add edi,16
  470. dec ecx
  471. jnz _loop1
  472. pop edi
  473. pop esi
  474. }
  475. #else // it doesnt know that ...
  476. memcpy(litColor, color, (len<<2)*sizeof(Scalar));
  477. #endif
  478. #endif
  479. //
  480. //-----------------------------------
  481. // Test each light against the vertex
  482. //-----------------------------------
  483. //
  484. for (i=0;i<nrLights;i++)
  485. {
  486. MLRLight *light = lights[i];
  487. Check_Object(light);
  488. vertexData.point = &coords[0];
  489. vertexData.color = &litColors[0];
  490. vertexData.normal = &normals[0];
  491. for(k=0;k<len;k++)
  492. {
  493. light->LightVertex(vertexData);
  494. vertexData.point++;
  495. vertexData.color++;
  496. vertexData.normal++;
  497. }
  498. }
  499. #ifdef LAB_ONLY
  500. Statistics::MLR_LitVertices += len*nrLights;
  501. #endif
  502. // set the to use colors to the original colors ...
  503. // only lighting could overwrite this;
  504. actualColors = &litColors;
  505. }
  506. break;
  507. case MLRState::LightingLightMapOnlyMode:
  508. {
  509. Verify(state.GetAlphaMode() == MLRState::OneZeroMode);
  510. STOP(("Lightmaps not implemented yet."));
  511. }
  512. break;
  513. case MLRState::LightingClassicAndLightMapMode:
  514. {
  515. Verify(state.GetAlphaMode() == MLRState::OneZeroMode);
  516. Verify(colors.GetLength() == litColors.GetLength());
  517. Verify(normals.GetLength() == colors.GetLength());
  518. Verify(coords.GetLength() == colors.GetLength());
  519. int i, k, len = colors.GetLength();
  520. MLRVertexData vertexData;
  521. #if COLOR_AS_DWORD
  522. #else
  523. RGBAColor *color = &colors[0];
  524. RGBAColor *litColor = &litColors[0];
  525. #if USE_ASSEMBLER_CODE
  526. _asm {
  527. push esi
  528. push edi
  529. mov esi, color
  530. mov edi, litColor
  531. mov ecx, len
  532. _loop2:
  533. mov eax, dword ptr [esi]
  534. mov ebx, dword ptr [esi+4]
  535. mov dword ptr [edi], eax
  536. mov dword ptr [edi+ 4], ebx
  537. mov eax, dword ptr [esi + 8]
  538. mov ebx, dword ptr [esi + 12]
  539. mov dword ptr [edi + 8], eax
  540. mov dword ptr [edi + 12], ebx
  541. add esi,16
  542. add edi,16
  543. dec ecx
  544. jnz _loop2
  545. pop edi
  546. pop esi
  547. }
  548. #else // it doesnt know that ...
  549. memcpy(litColor, color, (len<<2)*sizeof(Scalar));
  550. #endif
  551. #endif
  552. //
  553. //-----------------------------------
  554. // Test each light against the vertex
  555. //-----------------------------------
  556. //
  557. for (i=0;i<nrLights;i++)
  558. {
  559. MLRLight *light = lights[i];
  560. Check_Object(light);
  561. vertexData.point = &coords[0];
  562. vertexData.color = &litColors[0];
  563. vertexData.normal = &normals[0];
  564. for(k=0;k<len;k++)
  565. {
  566. light->LightVertex(vertexData);
  567. vertexData.point++;
  568. vertexData.color++;
  569. vertexData.normal++;
  570. }
  571. }
  572. #ifdef LAB_ONLY
  573. Statistics::MLR_LitVertices += len*nrLights;
  574. #endif
  575. // set the to use colors to the original colors ...
  576. // only lighting could overwrite this;
  577. actualColors = &litColors;
  578. STOP(("Lightmaps not implemented yet."));
  579. }
  580. break;
  581. }
  582. }
  583. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  584. //
  585. void
  586. MLRPrimitive::PaintMe(const Stuff::RGBAColor *paintMe)
  587. {
  588. Check_Object(this);
  589. Verify(colors.GetLength() == litColors.GetLength());
  590. int k, len = litColors.GetLength();
  591. #if COLOR_AS_DWORD
  592. DWORD argb = GOSCopyColor(paintMe);
  593. for(k=0;k<len;k++)
  594. {
  595. litColors[k] = argb;
  596. }
  597. #else
  598. for(k=0;k<len;k++)
  599. {
  600. litColors[k] = *paintMe;
  601. }
  602. #endif
  603. // set the to use colors to the original colors ...
  604. // only lighting could overwrite this;
  605. actualColors = &litColors;
  606. }
  607. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  608. //
  609. bool
  610. MLRPrimitive::CastRay(
  611. Line3D *line,
  612. Normal3D *normal
  613. )
  614. {
  615. Check_Object(this);
  616. Check_Object(line);
  617. Check_Pointer(normal);
  618. STOP(("Not implemented"));
  619. return false;
  620. }
  621. //#############################################################################
  622. //####################### MLRPrimitive__ClassData #######################
  623. //#############################################################################
  624. void
  625. MLRPrimitive__ClassData::TestInstance()
  626. {
  627. Verify(IsDerivedFrom(MLRPrimitive::DefaultData));
  628. }