matpass.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 : WW3d *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/matpass.cpp $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * Author : Kenny Mitchell *
  29. * *
  30. * $Modtime:: 06/27/02 1:27p $*
  31. * *
  32. * $Revision:: 8 $*
  33. * *
  34. * 06/27/02 KM Changes to max texture stage caps *
  35. *---------------------------------------------------------------------------------------------*
  36. * Functions: *
  37. * MaterialPassClass::MaterialPassClass -- Constructor *
  38. * MaterialPassClass::~MaterialPassClass -- Destructor *
  39. * MaterialPassClass::Install_Materials -- Plug our material settings into D3D *
  40. * MaterialPassClass::Set_Texture -- Set texture to use *
  41. * MaterialPassClass::Set_Shader -- Set the shader to use *
  42. * MaterialPassClass::Set_Material -- set vertex material to use *
  43. * MaterialPassClass::Get_Texture -- Get a pointer to the texture *
  44. * MaterialPassClass::Get_Material -- get the vertex material *
  45. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  46. #include "matpass.h"
  47. #include "vertmaterial.h"
  48. #include "shader.h"
  49. #include "texture.h"
  50. #include "statistics.h"
  51. #include "dx8wrapper.h"
  52. bool MaterialPassClass::EnablePerPolygonCulling = true;
  53. /***********************************************************************************************
  54. * MaterialPassClass::MaterialPassClass -- Constructor *
  55. * *
  56. * INPUT: *
  57. * *
  58. * OUTPUT: *
  59. * *
  60. * WARNINGS: *
  61. * *
  62. * HISTORY: *
  63. * 2/26/2001 gth : Created. *
  64. *=============================================================================================*/
  65. MaterialPassClass::MaterialPassClass(void) :
  66. Shader(0),
  67. Material(NULL),
  68. CullVolume(NULL),
  69. EnableOnTranslucentMeshes(true)
  70. {
  71. for (int i=0; i<MAX_TEX_STAGES; i++) {
  72. Texture[i] = NULL;
  73. }
  74. }
  75. /***********************************************************************************************
  76. * MaterialPassClass::~MaterialPassClass -- Destructor *
  77. * *
  78. * INPUT: *
  79. * *
  80. * OUTPUT: *
  81. * *
  82. * WARNINGS: *
  83. * *
  84. * HISTORY: *
  85. * 12/9/99 gth : Created. *
  86. * 06/27/02 kjm : Changes to max texture stage caps *
  87. *=============================================================================================*/
  88. MaterialPassClass::~MaterialPassClass(void)
  89. {
  90. for (int i=0; i<MAX_TEX_STAGES; i++) {
  91. REF_PTR_RELEASE(Texture[i]);
  92. }
  93. REF_PTR_RELEASE(Material);
  94. }
  95. /***********************************************************************************************
  96. * MaterialPassClass::Install_Materials -- Plug our material settings into D3D *
  97. * *
  98. * INPUT: *
  99. * *
  100. * OUTPUT: *
  101. * *
  102. * WARNINGS: *
  103. * *
  104. * HISTORY: *
  105. * 12/9/99 gth : Created. *
  106. * 2/26/2001 gth : Changed to Install_Materials *
  107. *=============================================================================================*/
  108. void MaterialPassClass::Install_Materials(void) const
  109. {
  110. DX8Wrapper::Set_Material(Peek_Material());
  111. DX8Wrapper::Set_Shader(Peek_Shader());
  112. for (int i=0;i<DX8Wrapper::Get_Current_Caps()->Get_Max_Textures_Per_Pass();++i)
  113. {
  114. DX8Wrapper::Set_Texture(i,Peek_Texture(i));
  115. }
  116. }
  117. /***********************************************************************************************
  118. * MaterialPassClass::Set_Texture -- Set texture to use *
  119. * *
  120. * INPUT: *
  121. * tex - pointer to the texture for this material pass (or NULL) *
  122. * *
  123. * OUTPUT: *
  124. * *
  125. * WARNINGS: *
  126. * *
  127. * HISTORY: *
  128. * 12/9/99 gth : Created. *
  129. *=============================================================================================*/
  130. void MaterialPassClass::Set_Texture(TextureClass * tex,int stage)
  131. {
  132. WWASSERT(stage >= 0);
  133. WWASSERT(stage < MAX_TEX_STAGES);
  134. REF_PTR_SET(Texture[stage],tex);
  135. }
  136. /***********************************************************************************************
  137. * MaterialPassClass::Set_Shader -- Set the shader to use *
  138. * *
  139. * INPUT: *
  140. * shader - shader for this material pass *
  141. * *
  142. * OUTPUT: *
  143. * *
  144. * WARNINGS: *
  145. * *
  146. * HISTORY: *
  147. * 12/9/99 gth : Created. *
  148. *=============================================================================================*/
  149. void MaterialPassClass::Set_Shader(ShaderClass shader)
  150. {
  151. Shader = shader;
  152. Shader.Enable_Fog ("MaterialPassClass");
  153. }
  154. /***********************************************************************************************
  155. * MaterialPassClass::Set_Material -- set vertex material to use *
  156. * *
  157. * INPUT: *
  158. * mat - pointer to the vertex material this material pass uses *
  159. * *
  160. * OUTPUT: *
  161. * *
  162. * WARNINGS: *
  163. * *
  164. * HISTORY: *
  165. * 12/9/99 gth : Created. *
  166. *=============================================================================================*/
  167. void MaterialPassClass::Set_Material(VertexMaterialClass * mat)
  168. {
  169. REF_PTR_SET(Material,mat);
  170. }
  171. /***********************************************************************************************
  172. * MaterialPassClass::Get_Texture -- Get a pointer to the texture *
  173. * *
  174. * INPUT: *
  175. * *
  176. * OUTPUT: *
  177. * reference counted pointer to the texture this material pass is using *
  178. * *
  179. * WARNINGS: *
  180. * *
  181. * HISTORY: *
  182. * 12/9/99 gth : Created. *
  183. *=============================================================================================*/
  184. TextureClass * MaterialPassClass::Get_Texture(int stage) const
  185. {
  186. WWASSERT(stage >= 0);
  187. WWASSERT(stage < MAX_TEX_STAGES);
  188. if (Texture[stage]) {
  189. Texture[stage]->Add_Ref();
  190. }
  191. return Texture[stage];
  192. }
  193. /***********************************************************************************************
  194. * MaterialPassClass::Get_Material -- get the vertex material *
  195. * *
  196. * INPUT: *
  197. * *
  198. * OUTPUT: *
  199. * reference counted pointer to the vertex material being used by this material pass *
  200. * *
  201. * WARNINGS: *
  202. * *
  203. * HISTORY: *
  204. * 12/9/99 gth : Created. *
  205. *=============================================================================================*/
  206. VertexMaterialClass * MaterialPassClass::Get_Material(void) const
  207. {
  208. if (Material) {
  209. Material->Add_Ref();
  210. }
  211. return Material;
  212. }