dx8texman.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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 : DX8 Texture Manager *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/dx8texman.cpp $*
  25. * *
  26. * Original Author:: Hector Yee *
  27. * *
  28. * Author : Kenny Mitchell *
  29. * *
  30. * $Modtime:: 06/27/02 1:27p $*
  31. * *
  32. * $Revision:: 4 $*
  33. * *
  34. * 06/27/02 KM Texture class abstraction *
  35. *---------------------------------------------------------------------------------------------*
  36. * Functions: *
  37. * DX8TextureManagerClass::Shutdown -- Shuts down the texture manager *
  38. * DX8TextureManagerClass::Add -- Adds a texture to be managed *
  39. * DX8TextureManagerClass::Remove -- Removes a texture from being managed *
  40. * DX8TextureManagerClass::Release_Textures -- Releases the internal d3d texture *
  41. * DX8TextureManagerClass::Recreate_Textures -- Reallocates lost textures *
  42. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  43. // This class manages textures that are in the default pool
  44. // ensuring that they are released on device loss
  45. // and created on device reset
  46. // Note: It does NOT addref to textures because it is called in the texture
  47. // destructor
  48. #include "dx8texman.h"
  49. TextureTrackerList DX8TextureManagerClass::Managed_Textures;
  50. /***********************************************************************************************
  51. * DX8TextureManagerClass::Shutdown -- Shuts down the texture manager *
  52. * *
  53. * *
  54. * *
  55. * *
  56. * INPUT: *
  57. * *
  58. * OUTPUT: *
  59. * *
  60. * WARNINGS: *
  61. * *
  62. * HISTORY: *
  63. * 4/25/2001 hy : Created. *
  64. * 5/16/2002 km : Added depth stencil texture tracking and abstraction *
  65. *=============================================================================================*/
  66. void DX8TextureManagerClass::Shutdown()
  67. {
  68. while (!Managed_Textures.Is_Empty())
  69. {
  70. TextureTrackerClass *track=Managed_Textures.Remove_Head();
  71. delete track;
  72. track=NULL;
  73. }
  74. }
  75. /***********************************************************************************************
  76. * DX8TextureManagerClass::Add -- Adds a texture to be managed *
  77. * *
  78. * *
  79. * *
  80. * *
  81. * INPUT: *
  82. * *
  83. * OUTPUT: *
  84. * *
  85. * WARNINGS: *
  86. * *
  87. * HISTORY: *
  88. * 4/25/2001 hy : Created. *
  89. * 5/16/2002 km : Added depth stencil texture tracking and abstraction *
  90. *=============================================================================================*/
  91. void DX8TextureManagerClass::Add(TextureTrackerClass *track)
  92. {
  93. // this function should only be called by the texture constructor
  94. Managed_Textures.Add(track);
  95. }
  96. /***********************************************************************************************
  97. * DX8TextureManagerClass::Remove -- Removes a texture from being managed *
  98. * *
  99. * *
  100. * *
  101. * *
  102. * INPUT: *
  103. * *
  104. * OUTPUT: *
  105. * *
  106. * WARNINGS: *
  107. * *
  108. * HISTORY: *
  109. * 4/25/2001 hy : Created. *
  110. * 5/16/2002 km : Added depth stencil texture tracking and abstraction *
  111. *=============================================================================================*/
  112. void DX8TextureManagerClass::Remove(TextureBaseClass *tex)
  113. {
  114. // this function should only be called by the texture destructor
  115. TextureTrackerListIterator it(&Managed_Textures);
  116. while (!it.Is_Done())
  117. {
  118. TextureTrackerClass *track=it.Peek_Obj();
  119. if (track->Get_Texture()==tex)
  120. {
  121. it.Remove_Current_Object();
  122. delete track;
  123. break;
  124. }
  125. it.Next();
  126. }
  127. }
  128. /***********************************************************************************************
  129. * DX8TextureManagerClass::Release_Textures -- Releases the internal d3d texture *
  130. * *
  131. * *
  132. * *
  133. * *
  134. * INPUT: *
  135. * *
  136. * OUTPUT: *
  137. * *
  138. * WARNINGS: *
  139. * *
  140. * HISTORY: *
  141. * 4/25/2001 hy : Created. *
  142. * 5/16/2002 km : Added depth stencil texture tracking and abstraction *
  143. *=============================================================================================*/
  144. void DX8TextureManagerClass::Release_Textures()
  145. {
  146. TextureTrackerListIterator it(&Managed_Textures);
  147. while (!it.Is_Done())
  148. {
  149. TextureTrackerClass *track=it.Peek_Obj();
  150. track->Release();
  151. it.Next();
  152. }
  153. }
  154. /***********************************************************************************************
  155. * DX8TextureManagerClass::Recreate_Textures -- Reallocates lost textures *
  156. * *
  157. * *
  158. * *
  159. * *
  160. * INPUT: *
  161. * *
  162. * OUTPUT: *
  163. * *
  164. * WARNINGS: *
  165. * *
  166. * HISTORY: *
  167. * 4/25/2001 hy : Created. *
  168. * 5/16/2002 km : Added depth stencil texture tracking and abstraction *
  169. *=============================================================================================*/
  170. void DX8TextureManagerClass::Recreate_Textures()
  171. {
  172. TextureTrackerListIterator it(&Managed_Textures);
  173. while (!it.Is_Done())
  174. {
  175. TextureTrackerClass *track=it.Peek_Obj();
  176. track->Recreate();
  177. track->Get_Texture()->Set_Dirty();
  178. it.Next();
  179. }
  180. }