MLRIndexedPrimitiveBase.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. //#############################################################################
  6. //##################### MLRIndexedPrimitiveBase #########################
  7. //#############################################################################
  8. DynamicArrayOf<unsigned short>
  9. *MLRIndexedPrimitiveBase::clipExtraIndex;
  10. MLRIndexedPrimitiveBase::ClassData*
  11. MLRIndexedPrimitiveBase::DefaultData = NULL;
  12. unsigned short
  13. *indexOffset;
  14. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. //
  16. void
  17. MLRIndexedPrimitiveBase::InitializeClass()
  18. {
  19. Verify(!DefaultData);
  20. Verify(gos_GetCurrentHeap() == StaticHeap);
  21. DefaultData =
  22. new ClassData(
  23. MLRIndexedPrimitiveBaseClassID,
  24. "MidLevelRenderer::MLRIndexedPrimitiveBase",
  25. MLRPrimitiveBase::DefaultData,
  26. NULL
  27. );
  28. Register_Object(DefaultData);
  29. clipExtraIndex = new DynamicArrayOf<unsigned short> (Limits::Max_Number_Vertices_Per_Mesh);
  30. Register_Pointer(clipExtraIndex);
  31. indexOffset = new unsigned short [Limits::Max_Number_Vertices_Per_Mesh+1];
  32. Register_Pointer(indexOffset);
  33. }
  34. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. //
  36. void
  37. MLRIndexedPrimitiveBase::TerminateClass()
  38. {
  39. Unregister_Pointer(clipExtraIndex);
  40. delete clipExtraIndex;
  41. Unregister_Pointer(indexOffset);
  42. delete [] indexOffset;
  43. Unregister_Object(DefaultData);
  44. delete DefaultData;
  45. DefaultData = NULL;
  46. }
  47. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  48. //
  49. MLRIndexedPrimitiveBase::MLRIndexedPrimitiveBase(
  50. ClassData *class_data,
  51. MemoryStream *stream,
  52. int version
  53. ):
  54. MLRPrimitiveBase(class_data, stream, version)
  55. {
  56. Check_Pointer(this);
  57. Check_Object(stream);
  58. Verify(gos_GetCurrentHeap() == Heap);
  59. switch(version)
  60. {
  61. case 1:
  62. case 2:
  63. {
  64. STOP(("This class got created only after version 2 !"));
  65. }
  66. break;
  67. default:
  68. {
  69. MemoryStreamIO_Read(stream, &index);
  70. }
  71. break;
  72. }
  73. visibleIndexedVerticesKey = false;
  74. visibleIndexedVertices.SetLength(coords.GetLength());
  75. }
  76. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. //
  78. void
  79. MLRIndexedPrimitiveBase::Save(MemoryStream *stream)
  80. {
  81. Check_Object(this);
  82. Check_Object(stream);
  83. MLRPrimitiveBase::Save(stream);
  84. MemoryStreamIO_Write(stream, &index);
  85. }
  86. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. //
  88. MLRIndexedPrimitiveBase::MLRIndexedPrimitiveBase(ClassData *class_data):
  89. MLRPrimitiveBase(class_data), index(0)
  90. {
  91. Verify(gos_GetCurrentHeap() == Heap);
  92. }
  93. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94. //
  95. MLRIndexedPrimitiveBase::~MLRIndexedPrimitiveBase()
  96. {
  97. }
  98. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  99. //
  100. void
  101. MLRIndexedPrimitiveBase::TestInstance() const
  102. {
  103. Verify(IsDerivedFrom(DefaultData));
  104. }
  105. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  106. //
  107. void
  108. MLRIndexedPrimitiveBase::InitializeDrawPrimitive(unsigned char vis, int parameter)
  109. {
  110. MLRPrimitiveBase::InitializeDrawPrimitive(vis, parameter);
  111. gos_indices = NULL;
  112. numGOSIndices = -1;
  113. visibleIndexedVerticesKey = false;
  114. int i, len = visibleIndexedVertices.GetLength();
  115. for(i=0;i<len;i++)
  116. {
  117. visibleIndexedVertices[i] = 0;
  118. }
  119. }
  120. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. //
  122. void
  123. MLRIndexedPrimitiveBase::SetCoordData(
  124. const Point3D *data,
  125. int dataSize
  126. )
  127. {
  128. Check_Object(this);
  129. Check_Pointer(data);
  130. Verify(gos_GetCurrentHeap() == Heap);
  131. Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength());
  132. #if defined (MAX_NUMBER_VERTICES)
  133. Verify(dataSize <= MAX_NUMBER_VERTICES);
  134. #endif
  135. coords.AssignData(data, dataSize);
  136. if(index.GetLength() > 0 && visibleIndexedVertices.GetLength() != dataSize)
  137. {
  138. visibleIndexedVertices.SetLength(dataSize);
  139. }
  140. }
  141. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142. //
  143. void
  144. MLRIndexedPrimitiveBase::SetIndexData(
  145. unsigned short *index_array,
  146. int index_count
  147. )
  148. {
  149. Check_Object(this);
  150. Check_Pointer(index_array);
  151. Verify(gos_GetCurrentHeap() == Heap);
  152. if(coords.GetLength() > 0)
  153. {
  154. visibleIndexedVertices.SetLength(coords.GetLength());
  155. }
  156. #ifdef _ARMOR
  157. int len = coords.GetLength();
  158. for(int i=0;i<index_count;i++)
  159. {
  160. Verify(index_array[i] < len);
  161. }
  162. #endif
  163. index.AssignData(index_array, index_count);
  164. }
  165. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  166. //
  167. void
  168. MLRIndexedPrimitiveBase::GetIndexData(
  169. unsigned short **index_array,
  170. int *index_count
  171. )
  172. {
  173. Check_Object(this);
  174. *index_array = index.GetData();
  175. *index_count = index.GetLength();
  176. }
  177. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  178. //
  179. void
  180. MLRIndexedPrimitiveBase::Transform(Matrix4D *mat)
  181. {
  182. Check_Object(this);
  183. int i, len = coords.GetLength();
  184. for(i=0;i<len;i++)
  185. {
  186. (*transformedCoords)[i].Multiply(coords[i], *mat);
  187. }
  188. #ifdef LAB_ONLY
  189. Set_Statistic(TransformedVertices, TransformedVertices+len);
  190. #endif
  191. }
  192. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  193. //
  194. bool
  195. MLRIndexedPrimitiveBase::CheckIndicies()
  196. {
  197. for(int i=0;i<numGOSIndices;i++)
  198. {
  199. if(gos_indices[i] >= numGOSVertices)
  200. {
  201. STOP(("Invalid indicies detected !"));
  202. }
  203. }
  204. return true;
  205. }