MLREffect.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. //#############################################################################
  6. //############################ MLREffect #################################
  7. //#############################################################################
  8. void EffectClipPolygon::Init()
  9. {
  10. Verify(gos_GetCurrentHeap() == StaticHeap);
  11. coords.SetLength(Limits::Max_Number_Vertices_Per_Polygon);
  12. colors.SetLength(Limits::Max_Number_Vertices_Per_Polygon);
  13. texCoords.SetLength(Limits::Max_Number_Vertices_Per_Polygon);
  14. clipPerVertex.SetLength(Limits::Max_Number_Vertices_Per_Polygon);
  15. }
  16. void EffectClipPolygon::Destroy()
  17. {
  18. coords.SetLength(0);
  19. colors.SetLength(0);
  20. texCoords.SetLength(0);
  21. clipPerVertex.SetLength(0);
  22. }
  23. //#############################################################################
  24. //############################ MLREffect #################################
  25. //#############################################################################
  26. MLREffect::ClassData*
  27. MLREffect::DefaultData = NULL;
  28. EffectClipPolygon
  29. *MLREffect::clipBuffer;
  30. DynamicArrayOf<Vector4D>
  31. *MLREffect::transformedCoords;
  32. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. //
  34. void
  35. MLREffect::InitializeClass()
  36. {
  37. Verify(!DefaultData);
  38. Verify(gos_GetCurrentHeap() == StaticHeap);
  39. DefaultData =
  40. new ClassData(
  41. MLREffectClassID,
  42. "MidLevelRenderer::MLREffect",
  43. RegisteredClass::DefaultData
  44. );
  45. Register_Object(DefaultData);
  46. transformedCoords = new DynamicArrayOf<Vector4D> (Limits::Max_Number_Vertices_Per_Mesh);
  47. Register_Object(transformedCoords);
  48. clipBuffer = new EffectClipPolygon [2];
  49. Register_Pointer(clipBuffer);
  50. clipBuffer[0].Init();
  51. clipBuffer[1].Init();
  52. }
  53. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  54. //
  55. void
  56. MLREffect::TerminateClass()
  57. {
  58. clipBuffer[1].Destroy();
  59. clipBuffer[0].Destroy();
  60. Unregister_Pointer(clipBuffer);
  61. delete [] clipBuffer;
  62. Unregister_Object(transformedCoords);
  63. delete transformedCoords;
  64. Unregister_Object(DefaultData);
  65. delete DefaultData;
  66. DefaultData = NULL;
  67. }
  68. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69. //
  70. MLREffect::MLREffect(int nr, ClassData *class_data):
  71. RegisteredClass(class_data)
  72. {
  73. Verify(gos_GetCurrentHeap() == Heap);
  74. visible = 0;
  75. maxNrOf = nr;
  76. testList.SetLength(maxNrOf);
  77. for(int i=0; i < maxNrOf; i++)
  78. {
  79. testList[i] = 0;
  80. }
  81. TurnAllOff();
  82. TurnAllVisible();
  83. worldToEffect = LinearMatrix4D::Identity;
  84. gos_vertices = NULL;
  85. numGOSVertices = 0;
  86. }
  87. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. //
  89. MLREffect::~MLREffect()
  90. {
  91. }
  92. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. //
  94. void
  95. MLREffect::Transform(int nrOfUsedEffects, int nrOfVertices)
  96. {
  97. Check_Object(this);
  98. Start_Timer(Transform_Time);
  99. int i, j, k;
  100. for(i=0,j=0;i<nrOfUsedEffects;i++,j+=nrOfVertices)
  101. {
  102. if(IsOn(i) == false)
  103. {
  104. continue;
  105. }
  106. for(k=j;k<j+nrOfVertices;k++)
  107. {
  108. (*transformedCoords)[k].Multiply(points[k], effectToClipMatrix);
  109. }
  110. }
  111. Stop_Timer(Transform_Time);
  112. }
  113. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  114. //
  115. void
  116. MLREffect::TurnAllOn()
  117. {
  118. Check_Object(this);
  119. int i;
  120. for(i=0;i<maxNrOf;i++)
  121. {
  122. testList[i] |= 2;
  123. }
  124. }
  125. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  126. //
  127. void
  128. MLREffect::TurnAllOff()
  129. {
  130. Check_Object(this);
  131. int i;
  132. for(i=0;i<maxNrOf;i++)
  133. {
  134. testList[i] &= ~2;
  135. }
  136. }
  137. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  138. //
  139. void
  140. MLREffect::TurnAllVisible()
  141. {
  142. Check_Object(this);
  143. int i;
  144. for(i=0;i<maxNrOf;i++)
  145. {
  146. testList[i] |= 1;
  147. }
  148. }
  149. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. //
  151. void
  152. MLREffect::TurnAllInVisible()
  153. {
  154. Check_Object(this);
  155. int i;
  156. for(i=0;i<maxNrOf;i++)
  157. {
  158. testList[i] &= ~1;
  159. }
  160. }