physresourcemgr.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 : wwphys *
  23. * *
  24. * $Archive:: /Commando/Code/wwphys/physresourcemgr.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 6/20/01 3:22p $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "physresourcemgr.h"
  38. #include "vertmaterial.h"
  39. #include "texture.h"
  40. #include "matpass.h"
  41. #include "assetmgr.h"
  42. /**
  43. ** Resources that the physics resource manager can allocate-on-demand
  44. */
  45. static TextureClass * _ShadowBlobTexture = NULL;
  46. static MaterialPassClass * _HighlightMaterialPass = NULL;
  47. static TextureClass * _StealthTexture = NULL;
  48. static TextureClass * _GridTexture = NULL;
  49. void PhysResourceMgrClass::Init(void)
  50. {
  51. }
  52. void PhysResourceMgrClass::Shutdown(void)
  53. {
  54. REF_PTR_RELEASE(_ShadowBlobTexture);
  55. REF_PTR_RELEASE(_HighlightMaterialPass);
  56. REF_PTR_RELEASE(_StealthTexture);
  57. }
  58. bool PhysResourceMgrClass::Set_Shadow_Blob_Texture(const char * texname)
  59. {
  60. if (texname == NULL) return false;
  61. TextureClass * tex = WW3DAssetManager::Get_Instance()->Get_Texture(texname);
  62. if (tex == NULL) return false;
  63. REF_PTR_SET(_ShadowBlobTexture,tex);
  64. tex->Release_Ref();
  65. _ShadowBlobTexture->Set_U_Addr_Mode(TextureClass::TEXTURE_ADDRESS_CLAMP);
  66. _ShadowBlobTexture->Set_V_Addr_Mode(TextureClass::TEXTURE_ADDRESS_CLAMP);
  67. return true;
  68. }
  69. TextureClass * PhysResourceMgrClass::Get_Shadow_Blob_Texture(void)
  70. {
  71. if (_ShadowBlobTexture == NULL) {
  72. _ShadowBlobTexture = WW3DAssetManager::Get_Instance()->Get_Texture("shadowblob.tga");
  73. _ShadowBlobTexture->Set_U_Addr_Mode(TextureClass::TEXTURE_ADDRESS_CLAMP);
  74. _ShadowBlobTexture->Set_V_Addr_Mode(TextureClass::TEXTURE_ADDRESS_CLAMP);
  75. }
  76. WWASSERT(_ShadowBlobTexture != NULL);
  77. _ShadowBlobTexture->Add_Ref();
  78. return _ShadowBlobTexture;
  79. }
  80. MaterialPassClass * PhysResourceMgrClass::Get_Highlight_Material_Pass(void)
  81. {
  82. // If we haven't initialized the highlight material, do it now.
  83. if (_HighlightMaterialPass == NULL) {
  84. // otherwise, create and initialize it
  85. _HighlightMaterialPass = NEW_REF(MaterialPassClass,());
  86. VertexMaterialClass * vmtl = NEW_REF(VertexMaterialClass,());
  87. vmtl->Set_Ambient(0,0,0);
  88. vmtl->Set_Diffuse(0,0,0);
  89. vmtl->Set_Specular(0,0,0);
  90. vmtl->Set_Emissive(0.2f,1.0f,0.2f);
  91. vmtl->Set_Opacity(1.0f);
  92. vmtl->Set_Shininess(0.0f);
  93. vmtl->Set_Lighting(true);
  94. _HighlightMaterialPass->Set_Material(vmtl);
  95. REF_PTR_RELEASE(vmtl);
  96. }
  97. ShaderClass shader = ShaderClass::_PresetOpaqueShader;
  98. shader.Set_Texturing(ShaderClass::TEXTURING_DISABLE);
  99. shader.Set_Depth_Compare(ShaderClass::PASS_ALWAYS);
  100. _HighlightMaterialPass->Set_Shader(shader);
  101. _HighlightMaterialPass->Add_Ref();
  102. return _HighlightMaterialPass;
  103. }
  104. TextureClass * PhysResourceMgrClass::Get_Stealth_Texture(void)
  105. {
  106. TextureClass * tex = Peek_Stealth_Texture();
  107. if (tex) {
  108. tex->Add_Ref();
  109. }
  110. return tex;
  111. }
  112. TextureClass * PhysResourceMgrClass::Peek_Stealth_Texture(void)
  113. {
  114. if (_StealthTexture == NULL) {
  115. _StealthTexture = WW3DAssetManager::Get_Instance()->Get_Texture("stealth_effect.tga");
  116. }
  117. return _StealthTexture;
  118. }
  119. VertexMaterialClass * PhysResourceMgrClass::Create_Emissive_Material(void)
  120. {
  121. VertexMaterialClass * vmtl = NEW_REF(VertexMaterialClass,());
  122. vmtl->Set_Ambient(0,0,0);
  123. vmtl->Set_Diffuse(0,0,0);
  124. vmtl->Set_Specular(0,0,0);
  125. vmtl->Set_Emissive(1.0f,1.0f,1.0f);
  126. vmtl->Set_Opacity(1.0f);
  127. vmtl->Set_Shininess(0.0f);
  128. vmtl->Set_Lighting(true);
  129. return vmtl;
  130. }
  131. TextureClass * PhysResourceMgrClass::Get_Grid_Texture(void)
  132. {
  133. TextureClass * tex = Peek_Grid_Texture();
  134. if (tex != NULL) {
  135. tex->Add_Ref();
  136. }
  137. return tex;
  138. }
  139. TextureClass * PhysResourceMgrClass::Peek_Grid_Texture(void)
  140. {
  141. if (_GridTexture == NULL) {
  142. _GridTexture = WW3DAssetManager::Get_Instance()->Get_Texture("grid_effect.tga");
  143. }
  144. return _GridTexture;
  145. }