dx8indexbuffer.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. ** Command & Conquer Renegade(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 RefCountClass
  53. {
  54. protected:
  55. virtual ~IndexBufferClass();
  56. public:
  57. IndexBufferClass(unsigned type, unsigned short index_count);
  58. void Copy(unsigned int* indices,unsigned start_index,unsigned index_count);
  59. void Copy(unsigned short* indices,unsigned start_index,unsigned index_count);
  60. inline unsigned short Get_Index_Count() const { return index_count; }
  61. inline unsigned Type() const { return type; }
  62. void Add_Engine_Ref() const;
  63. void Release_Engine_Ref() const;
  64. inline unsigned Engine_Refs() const { return engine_refs; }
  65. class WriteLockClass
  66. {
  67. IndexBufferClass* index_buffer;
  68. unsigned short* indices;
  69. public:
  70. WriteLockClass(IndexBufferClass* index_buffer);
  71. ~WriteLockClass();
  72. unsigned short* Get_Index_Array() { return indices; }
  73. };
  74. class AppendLockClass
  75. {
  76. IndexBufferClass* index_buffer;
  77. unsigned short* indices;
  78. public:
  79. AppendLockClass(IndexBufferClass* index_buffer,unsigned start_index, unsigned index_range);
  80. ~AppendLockClass();
  81. unsigned short* Get_Index_Array() { return indices; }
  82. };
  83. static unsigned Get_Total_Buffer_Count();
  84. static unsigned Get_Total_Allocated_Indices();
  85. static unsigned Get_Total_Allocated_Memory();
  86. protected:
  87. mutable int engine_refs;
  88. unsigned short index_count; // number of indices
  89. unsigned type;
  90. };
  91. // HY 2/14/01
  92. // Created
  93. class DynamicIBAccessClass
  94. {
  95. friend DX8Wrapper;
  96. friend SortingRendererClass;
  97. unsigned Type;
  98. unsigned short IndexCount;
  99. unsigned short IndexBufferOffset;
  100. IndexBufferClass* IndexBuffer;
  101. void Allocate_Sorting_Dynamic_Buffer();
  102. void Allocate_DX8_Dynamic_Buffer();
  103. public:
  104. DynamicIBAccessClass(unsigned short type, unsigned short index_count);
  105. ~DynamicIBAccessClass();
  106. unsigned Get_Type() const { return Type; }
  107. unsigned short Get_Index_Count() const { return IndexCount; }
  108. // Call at the end of the execution, or at whatever time you wish to release
  109. // the recycled dynamic index buffer.
  110. static void _Deinit();
  111. static void _Reset(bool frame_changed);
  112. // To lock the index buffer, create instance of this write class locally.
  113. // The buffer is automatically unlocked when you exit the scope.
  114. class WriteLockClass
  115. {
  116. DynamicIBAccessClass* DynamicIBAccess;
  117. unsigned short* Indices;
  118. public:
  119. WriteLockClass(DynamicIBAccessClass* ib_access);
  120. ~WriteLockClass();
  121. unsigned short* Get_Index_Array() { return Indices; }
  122. };
  123. friend WriteLockClass;
  124. };
  125. /**
  126. ** DX8IndexBufferClass
  127. ** This class wraps a DX8 index buffer.
  128. */
  129. class DX8IndexBufferClass : public IndexBufferClass
  130. {
  131. friend IndexBufferClass::WriteLockClass;
  132. friend IndexBufferClass::AppendLockClass;
  133. public:
  134. enum UsageType {
  135. USAGE_DEFAULT=0,
  136. USAGE_DYNAMIC=1,
  137. USAGE_SOFTWAREPROCESSING=2,
  138. USAGE_NPATCHES=4
  139. };
  140. DX8IndexBufferClass(unsigned short index_count,UsageType usage=USAGE_DEFAULT);
  141. ~DX8IndexBufferClass();
  142. void Copy(unsigned int* indices,unsigned start_index,unsigned index_count);
  143. void Copy(unsigned short* indices,unsigned start_index,unsigned index_count);
  144. inline IDirect3DIndexBuffer8* Get_DX8_Index_Buffer() { return index_buffer; }
  145. private:
  146. IDirect3DIndexBuffer8* index_buffer; // actual dx8 index buffer
  147. };
  148. class SortingIndexBufferClass : public IndexBufferClass
  149. {
  150. friend DX8Wrapper;
  151. friend SortingRendererClass;
  152. friend IndexBufferClass::WriteLockClass;
  153. friend IndexBufferClass::AppendLockClass;
  154. friend DynamicIBAccessClass::WriteLockClass;
  155. public:
  156. SortingIndexBufferClass(unsigned short index_count);
  157. ~SortingIndexBufferClass();
  158. protected:
  159. unsigned short* index_buffer;
  160. };
  161. #endif //DX8INDEXBUFFER_H