dx8texman.cpp 12 KB

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