dx8indexbuffer.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : ww3d *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/dx8indexbuffer.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Jani_p $*
  29. * *
  30. * $Modtime:: 7/10/01 12:27p $*
  31. * *
  32. * $Revision:: 12 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef DX8INDEXBUFFER_H
  41. #define DX8INDEXBUFFER_H
  42. #include "always.h"
  43. #include "wwdebug.h"
  44. #include "refcount.h"
  45. #include "sphere.h"
  46. class DX8Wrapper;
  47. class SortingRendererClass;
  48. struct IDirect3DIndexBuffer8;
  49. class DX8IndexBufferClass;
  50. class SortingIndexBufferClass;
  51. // ----------------------------------------------------------------------------
  52. class IndexBufferClass : public W3DMPO, public RefCountClass
  53. {
  54. // nope, it's an ABC
  55. //W3DMPO_GLUE(IndexBufferClass)
  56. protected:
  57. virtual ~IndexBufferClass();
  58. public:
  59. IndexBufferClass(unsigned type, unsigned short index_count);
  60. void Copy(unsigned int* indices,unsigned start_index,unsigned index_count);
  61. void Copy(unsigned short* indices,unsigned start_index,unsigned index_count);
  62. inline unsigned short Get_Index_Count() const { return index_count; }
  63. inline unsigned Type() const { return type; }
  64. void Add_Engine_Ref() const;
  65. void Release_Engine_Ref() const;
  66. inline unsigned Engine_Refs() const { return engine_refs; }
  67. class WriteLockClass
  68. {
  69. IndexBufferClass* index_buffer;
  70. unsigned short* indices;
  71. public:
  72. WriteLockClass(IndexBufferClass* index_buffer);
  73. ~WriteLockClass();
  74. unsigned short* Get_Index_Array() { return indices; }
  75. };
  76. class AppendLockClass
  77. {
  78. IndexBufferClass* index_buffer;
  79. unsigned short* indices;
  80. public:
  81. AppendLockClass(IndexBufferClass* index_buffer,unsigned start_index, unsigned index_range);
  82. ~AppendLockClass();
  83. unsigned short* Get_Index_Array() { return indices; }
  84. };
  85. static unsigned Get_Total_Buffer_Count();
  86. static unsigned Get_Total_Allocated_Indices();
  87. static unsigned Get_Total_Allocated_Memory();
  88. protected:
  89. mutable int engine_refs;
  90. unsigned short index_count; // number of indices
  91. unsigned type;
  92. };
  93. // HY 2/14/01
  94. // Created
  95. class DynamicIBAccessClass : public W3DMPO
  96. {
  97. W3DMPO_GLUE(DynamicIBAccessClass)
  98. friend DX8Wrapper;
  99. friend SortingRendererClass;
  100. unsigned Type;
  101. unsigned short IndexCount;
  102. unsigned short IndexBufferOffset;
  103. IndexBufferClass* IndexBuffer;
  104. void Allocate_Sorting_Dynamic_Buffer();
  105. void Allocate_DX8_Dynamic_Buffer();
  106. public:
  107. DynamicIBAccessClass(unsigned short type, unsigned short index_count);
  108. ~DynamicIBAccessClass();
  109. unsigned Get_Type() const { return Type; }
  110. unsigned short Get_Index_Count() const { return IndexCount; }
  111. // Call at the end of the execution, or at whatever time you wish to release
  112. // the recycled dynamic index buffer.
  113. static void _Deinit();
  114. static void _Reset(bool frame_changed);
  115. static unsigned short Get_Default_Index_Count(void); ///<current size of dynamic index buffer
  116. // To lock the index buffer, create instance of this write class locally.
  117. // The buffer is automatically unlocked when you exit the scope.
  118. class WriteLockClass
  119. {
  120. DynamicIBAccessClass* DynamicIBAccess;
  121. unsigned short* Indices;
  122. public:
  123. WriteLockClass(DynamicIBAccessClass* ib_access);
  124. ~WriteLockClass();
  125. unsigned short* Get_Index_Array() { return Indices; }
  126. };
  127. friend WriteLockClass;
  128. };
  129. /**
  130. ** DX8IndexBufferClass
  131. ** This class wraps a DX8 index buffer.
  132. */
  133. class DX8IndexBufferClass : public IndexBufferClass
  134. {
  135. W3DMPO_GLUE(DX8IndexBufferClass)
  136. friend IndexBufferClass::WriteLockClass;
  137. friend IndexBufferClass::AppendLockClass;
  138. public:
  139. enum UsageType {
  140. USAGE_DEFAULT=0,
  141. USAGE_DYNAMIC=1,
  142. USAGE_SOFTWAREPROCESSING=2,
  143. USAGE_NPATCHES=4
  144. };
  145. DX8IndexBufferClass(unsigned short index_count,UsageType usage=USAGE_DEFAULT);
  146. ~DX8IndexBufferClass();
  147. void Copy(unsigned int* indices,unsigned start_index,unsigned index_count);
  148. void Copy(unsigned short* indices,unsigned start_index,unsigned index_count);
  149. inline IDirect3DIndexBuffer8* Get_DX8_Index_Buffer() { return index_buffer; }
  150. private:
  151. IDirect3DIndexBuffer8* index_buffer; // actual dx8 index buffer
  152. };
  153. class SortingIndexBufferClass : public IndexBufferClass
  154. {
  155. W3DMPO_GLUE(SortingIndexBufferClass)
  156. friend DX8Wrapper;
  157. friend SortingRendererClass;
  158. friend IndexBufferClass::WriteLockClass;
  159. friend IndexBufferClass::AppendLockClass;
  160. friend DynamicIBAccessClass::WriteLockClass;
  161. public:
  162. SortingIndexBufferClass(unsigned short index_count);
  163. ~SortingIndexBufferClass();
  164. protected:
  165. unsigned short* index_buffer;
  166. };
  167. #endif //DX8INDEXBUFFER_H