matpass.cpp 14 KB

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