MLRSorter.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #pragma once
  5. #define MLR_MLRSORTER_HPP
  6. #include <MLR\MLR.hpp>
  7. #include <MLR\MLRLight.hpp>
  8. #include <MLR\GOSVertex.hpp>
  9. #include <MLR\GOSVertex2UV.hpp>
  10. #include <MLR\GOSVertexPool.hpp>
  11. namespace MidLevelRenderer {
  12. class MLRPrimitive;
  13. class MLREffect;
  14. class GOSVertex;
  15. class DrawScreenQuadsInformation;
  16. struct SortAlpha;
  17. class SortData {
  18. public:
  19. SortData ()
  20. { vertices = NULL; numVertices = 0; indices = NULL;
  21. numIndices = 0; type = TriList; texture2 = 0; }
  22. void DrawTriList();
  23. void DrawTriIndexedList();
  24. void DrawPointCloud();
  25. void DrawLineCloud();
  26. void DrawQuads();
  27. int LoadAlphaFromTriList(SortAlpha**);
  28. int LoadAlphaFromTriIndexedList(SortAlpha**);
  29. int LoadAlphaFromPointCloud(SortAlpha**);
  30. int LoadAlphaFromLineCloud(SortAlpha**);
  31. int LoadAlphaFromQuads(SortAlpha**);
  32. enum {
  33. TriList = 0,
  34. TriIndexedList,
  35. PointCloud,
  36. Quads,
  37. LineCloud,
  38. LastMode
  39. };
  40. typedef void (SortData::* DrawFunc)();
  41. typedef int (SortData::* LoadSortAlphaFunc)(SortAlpha**);
  42. static DrawFunc Draw[LastMode];
  43. static LoadSortAlphaFunc LoadSortAlpha[LastMode];
  44. MLRState state;
  45. void *vertices;
  46. int numVertices;
  47. unsigned short *indices;
  48. int numIndices;
  49. int type;
  50. int texture2;
  51. };
  52. class MLRPrimitiveBase;
  53. #define CalDraw
  54. #ifdef CalDraw
  55. struct ToBeDrawnPrimitive {
  56. ToBeDrawnPrimitive();
  57. MLRPrimitiveBase *primitive;
  58. MLRState state;
  59. Stuff::Point3D cameraPosition;
  60. MLRClippingState clippingFlags;
  61. Stuff::Matrix4D shapeToClipMatrix;
  62. Stuff::LinearMatrix4D worldToShape;
  63. static GOSVertexPool *allVerticesToDraw;
  64. MLRLight* activeLights[Limits::Max_Number_Of_Lights_Per_Primitive];
  65. int nrOfActiveLights;
  66. };
  67. #endif
  68. //##########################################################################
  69. //######################### MLRSorter ################################
  70. //##########################################################################
  71. class _declspec(novtable) MLRSorter :
  72. public Stuff::RegisteredClass
  73. {
  74. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. // Initialization
  76. //
  77. public:
  78. static void
  79. InitializeClass();
  80. static void
  81. TerminateClass();
  82. static ClassData
  83. *DefaultData;
  84. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. // Constructors/Destructors
  86. //
  87. public:
  88. MLRSorter(ClassData *class_data, MLRTexturePool*);
  89. ~MLRSorter();
  90. virtual void AddPrimitive(MLRPrimitiveBase*, int=0) = 0;
  91. virtual void AddEffect(MLREffect*, const MLRState&) = 0;
  92. virtual void AddScreenQuads(GOSVertex*, const DrawScreenQuadsInformation*) = 0;
  93. virtual void AddSortRawData(SortData*) = 0;
  94. virtual void
  95. DrawPrimitive(MLRPrimitiveBase*, int=0);
  96. void
  97. SetTexturePool(MLRTexturePool *tp)
  98. { Check_Object(this); Check_Object(tp); texturePool = tp; }
  99. bool
  100. SetDifferences(const MLRState& original, const MLRState& newer);
  101. // starts the action
  102. virtual void RenderNow () = 0;
  103. // resets the sorting
  104. virtual void Reset ();
  105. // lets begin the dance
  106. virtual void StartDraw(const MLRState &default_state);
  107. // enter raw data
  108. SortData*
  109. SetRawData
  110. ( void *vertices,
  111. int numVertices,
  112. const MLRState& state,
  113. const int& mode,
  114. int tex2 = 0
  115. );
  116. SortData*
  117. SetRawIndexedData
  118. ( void* vertices,
  119. int numVertices,
  120. unsigned short *indices,
  121. int numIndices,
  122. const MLRState& state,
  123. const int& mode,
  124. int tex2 = 0
  125. );
  126. SortData*
  127. SetRawData(MLRPrimitiveBase*, int=0 );
  128. // Just scaling down a bit to keep z under 1.0f
  129. void
  130. SetFarClipReciprocal(Stuff::Scalar fcr)
  131. { Check_Object(this); farClipReciprocal = fcr*(1.0f-Stuff::SMALL); }
  132. #ifdef CalDraw
  133. ToBeDrawnPrimitive*
  134. GetCurrentTBDP()
  135. { Check_Object(this); return &drawData[lastUsedDraw]; }
  136. ToBeDrawnPrimitive*
  137. GetCurrentTBDP(int index)
  138. { Check_Object(this); Verify(index<lastUsedDraw); return &drawData[index]; }
  139. void
  140. IncreaseTBDPCounter();
  141. #endif
  142. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143. // Testing
  144. //
  145. public:
  146. void
  147. TestInstance() const;
  148. protected:
  149. MLRState theCurrentState;
  150. MLRTexturePool *texturePool;
  151. int lastUsedRaw;
  152. Stuff::DynamicArrayOf<SortData> rawDrawData; // Max_Number_Primitives_Per_Frame
  153. int
  154. lastUsedInBucketNotDrawn[MLRState::PriorityCount];
  155. #ifdef CalDraw
  156. int lastUsedDraw;
  157. Stuff::DynamicArrayOf<ToBeDrawnPrimitive> drawData; // Max_Number_Primitives_Per_Frame
  158. Stuff::DynamicArrayOf<ToBeDrawnPrimitive*> //, Max_Number_Primitives_Per_Frame + Max_Number_ScreenQuads_Per_Frame
  159. priorityBucketsNotDrawn[MLRState::PriorityCount];
  160. #endif
  161. Stuff::Scalar
  162. farClipReciprocal;
  163. };
  164. }