GOSVertexPool.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #pragma once
  5. #define MLR_GOSVERTEXPOOL_HPP
  6. #include <MLR\MLR.hpp>
  7. #include <MLR\GOSVertex.hpp>
  8. #include <MLR\GOSVertex2UV.hpp>
  9. extern bool MLRVertexLimitReached;
  10. namespace MidLevelRenderer {
  11. //##########################################################################
  12. //###################### GOSVertexPool ###############################
  13. //##########################################################################
  14. class GOSVertexPool
  15. {
  16. public:
  17. GOSVertexPool();
  18. void Reset();
  19. //
  20. //------------------------------------------------------------------------------------------------------------
  21. //
  22. int GetLength ()
  23. {
  24. Check_Object(this);
  25. return vertices.GetLength()-1;
  26. }
  27. unsigned GetLast ()
  28. {
  29. Check_Object(this);
  30. return lastUsed;
  31. }
  32. int Increase (int add=1)
  33. {
  34. Check_Object(this);
  35. lastUsed += add;
  36. Verify(lastUsed<Limits::Max_Number_Vertices_Per_Frame);
  37. MLRVertexLimitReached = (lastUsed > (Limits::Max_Number_Vertices_Per_Frame - 2000));
  38. return lastUsed;
  39. }
  40. GOSVertex*
  41. GetActualVertexPool(bool db=false)
  42. {
  43. Check_Object(this);
  44. if(db)
  45. {
  46. return verticesDB.GetData();
  47. }
  48. else
  49. {
  50. return (GOSVertex*)((char*)(vertices.GetData() + lastUsed)+vertexAlignment);
  51. }
  52. }
  53. //
  54. //------------------------------------------------------------------------------------------------------------
  55. //
  56. int GetLength2UV ()
  57. {
  58. Check_Object(this);
  59. return vertices2uv.GetLength()-1;
  60. }
  61. unsigned GetLast2UV ()
  62. {
  63. Check_Object(this);
  64. return lastUsed2uv;
  65. }
  66. int Increase2UV (int add=1)
  67. {
  68. Check_Object(this);
  69. lastUsed2uv += add;
  70. Verify(lastUsed2uv<Limits::Max_Number_Vertices_Per_Frame);
  71. return lastUsed2uv;
  72. }
  73. GOSVertex2UV*
  74. GetActualVertexPool2UV(bool db=false)
  75. {
  76. Check_Object(this);
  77. if(db)
  78. {
  79. return vertices2uvDB.GetData();
  80. }
  81. else
  82. {
  83. return (GOSVertex2UV*)((char*)(vertices2uv.GetData() + lastUsed2uv)+vertexAlignment);
  84. }
  85. }
  86. //
  87. //------------------------------------------------------------------------------------------------------------
  88. //
  89. unsigned GetLastIndex ()
  90. {
  91. Check_Object(this);
  92. return lastUsedIndex;
  93. }
  94. int IncreaseIndex (int add=1)
  95. {
  96. Check_Object(this);
  97. lastUsedIndex += add;
  98. Verify(lastUsedIndex<Limits::Max_Number_Vertices_Per_Frame);
  99. return lastUsedIndex;
  100. }
  101. unsigned short*
  102. GetActualIndexPool(bool db=false)
  103. {
  104. Check_Object(this);
  105. if(db)
  106. {
  107. return indicesDB.GetData();
  108. }
  109. else
  110. {
  111. return (unsigned short*)((char*)(indices.GetData() + lastUsedIndex)+indicesAlignment);
  112. }
  113. }
  114. //
  115. //------------------------------------------------------------------------------------------------------------
  116. //
  117. void
  118. TestInstance()
  119. {
  120. Verify(lastUsed < Limits::Max_Number_Vertices_Per_Frame);
  121. Verify(lastUsed2uv < Limits::Max_Number_Vertices_Per_Frame);
  122. Verify(lastUsedIndex < Limits::Max_Number_Vertices_Per_Frame);
  123. }
  124. protected:
  125. unsigned lastUsed;
  126. unsigned lastUsed2uv;
  127. unsigned lastUsedIndex;
  128. unsigned vertexAlignment;
  129. unsigned vertexAlignment2uv;
  130. unsigned indicesAlignment;
  131. Stuff::DynamicArrayOf<GOSVertex> vertices; // , Max_Number_Vertices_Per_Frame+4*Max_Number_ScreenQuads_Per_Frame
  132. Stuff::DynamicArrayOf<GOSVertex2UV> vertices2uv; // , Max_Number_Vertices_Per_Frame+4*Max_Number_ScreenQuads_Per_Frame
  133. Stuff::DynamicArrayOf<unsigned short> indices; // , Max_Number_Vertices_Per_Frame
  134. Stuff::DynamicArrayOf<GOSVertex> verticesDB; // , Max_Number_Vertices_Per_Mesh
  135. Stuff::DynamicArrayOf<GOSVertex2UV> vertices2uvDB; // , Max_Number_Vertices_Per_Mesh
  136. Stuff::DynamicArrayOf<unsigned short> indicesDB; // , Max_Number_Vertices_Per_Mesh
  137. private:
  138. GOSVertexPool(const GOSVertexPool&);
  139. };
  140. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141. inline
  142. GOSVertexPool::GOSVertexPool()
  143. {
  144. Verify(gos_GetCurrentHeap() == Heap);
  145. lastUsed = 0;
  146. lastUsed2uv = 0;
  147. lastUsedIndex = 0;
  148. gos_PushCurrentHeap(StaticHeap);
  149. vertices.SetLength(Limits::Max_Number_Vertices_Per_Frame+4*Limits::Max_Number_ScreenQuads_Per_Frame+1);
  150. vertices2uv.SetLength(Limits::Max_Number_Vertices_Per_Frame+4*Limits::Max_Number_ScreenQuads_Per_Frame+1);
  151. indices.SetLength(Limits::Max_Number_Vertices_Per_Frame+16);
  152. verticesDB.SetLength(2*Limits::Max_Number_Vertices_Per_Mesh);
  153. vertices2uvDB.SetLength(2*Limits::Max_Number_Vertices_Per_Mesh);
  154. indicesDB.SetLength(2*Limits::Max_Number_Vertices_Per_Mesh);
  155. gos_PopCurrentHeap();
  156. vertexAlignment=32-( (int)vertices.GetData() & 31 );
  157. vertexAlignment2uv=32-( (int)vertices2uv.GetData() & 31 );
  158. indicesAlignment=32-( (int)indices.GetData() & 31 );
  159. }
  160. inline void
  161. GOSVertexPool::Reset()
  162. {
  163. Check_Object(this);
  164. lastUsed = 0;
  165. lastUsed2uv = 0;
  166. lastUsedIndex = 0;
  167. MLRVertexLimitReached = false;
  168. }
  169. }