Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

492 lines
20 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CSHADER_H
  8. #define CSHADER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. // uncomment this if you want to build for nv3x
  13. //#define NV3X 1
  14. // This is what all shaders include.
  15. // CBaseShader will become CShader in this file.
  16. #include "materialsystem/ishaderapi.h"
  17. #include "utlvector.h"
  18. #include "materialsystem/imaterialvar.h"
  19. #include "materialsystem/imaterial.h"
  20. #include "BaseShader.h"
  21. #include "materialsystem/itexture.h"
  22. // Included for convenience because they are used in a bunch of shaders
  23. #include "materialsystem/imesh.h"
  24. #include "materialsystem/imaterialsystemhardwareconfig.h"
  25. #include "materialsystem/materialsystem_config.h"
  26. #include "shaderlib/ShaderDLL.h"
  27. // make "local variable is initialized but not referenced" warnings errors for combo checking macros
  28. #pragma warning ( error : 4189 )
  29. //-----------------------------------------------------------------------------
  30. // Global interfaces
  31. //-----------------------------------------------------------------------------
  32. extern IMaterialSystemHardwareConfig *g_pHardwareConfig;
  33. extern const MaterialSystem_Config_t *g_pConfig;
  34. extern bool g_shaderConfigDumpEnable;
  35. // Helper method
  36. bool IsUsingGraphics();
  37. #define SOFTWARE_VERTEX_SHADER(name) \
  38. static void SoftwareVertexShader_ ## name( CMeshBuilder &meshBuilder, IMaterialVar **params, IShaderDynamicAPI* pShaderAPI )
  39. #define FORWARD_DECLARE_SOFTWARE_VERTEX_SHADER(name)\
  40. static void SoftwareVertexShader_ ## name( CMeshBuilder &meshBuilder, IMaterialVar **params, IShaderDynamicAPI* pShaderAPI );
  41. #define USE_SOFTWARE_VERTEX_SHADER(name) \
  42. m_SoftwareVertexShader = SoftwareVertexShader_ ## name
  43. #define SHADER_INIT_PARAMS() \
  44. virtual void OnInitShaderParams( IMaterialVar **params, const char *pMaterialName )
  45. #define SHADER_FALLBACK \
  46. virtual char const* GetFallbackShader( IMaterialVar** params ) const
  47. // Typesafe flag setting
  48. inline void CShader_SetFlags( IMaterialVar **params, MaterialVarFlags_t _flag )
  49. {
  50. params[FLAGS]->SetIntValue( params[FLAGS]->GetIntValue() | (_flag) );
  51. }
  52. inline bool CShader_IsFlagSet( IMaterialVar **params, MaterialVarFlags_t _flag )
  53. {
  54. return ((params[FLAGS]->GetIntValue() & (_flag) ) != 0);
  55. }
  56. #define SET_FLAGS( _flag ) CShader_SetFlags( params, _flag )
  57. #define CLEAR_FLAGS( _flag ) params[FLAGS]->SetIntValue( params[FLAGS]->GetIntValue() & ~(_flag) )
  58. #define IS_FLAG_SET( _flag ) CShader_IsFlagSet( params, _flag )
  59. #define IS_FLAG_DEFINED( _flag ) ((params[FLAGS_DEFINED]->GetIntValue() & (_flag) ) != 0)
  60. #define IS_PARAM_DEFINED( _param ) ( ( ( _param >= 0 ) && ( params[_param]->IsDefined() ) ) )
  61. #define SET_PARAM_STRING_IF_NOT_DEFINED( nParamIndex, kDefaultValue ) \
  62. if ( ( nParamIndex != -1 ) && ( !params[nParamIndex]->IsDefined() ) ) \
  63. { \
  64. params[nParamIndex]->SetStringValue( kDefaultValue ); \
  65. }
  66. #define SET_PARAM_INT_IF_NOT_DEFINED( nParamIndex, kDefaultValue ) \
  67. if ( ( nParamIndex != -1 ) && ( !params[nParamIndex]->IsDefined() ) ) \
  68. { \
  69. params[nParamIndex]->SetIntValue( kDefaultValue ); \
  70. }
  71. #define SET_PARAM_FLOAT_IF_NOT_DEFINED( nParamIndex, kDefaultValue ) \
  72. if ( ( nParamIndex != -1 ) && ( !params[nParamIndex]->IsDefined() ) ) \
  73. { \
  74. params[nParamIndex]->SetFloatValue( kDefaultValue ); \
  75. }
  76. #define SET_PARAM_VEC_IF_NOT_DEFINED( nParamIndex, kDefaultValue, nSize ) \
  77. if ( ( nParamIndex != -1 ) && ( !params[nParamIndex]->IsDefined() ) ) \
  78. { \
  79. params[nParamIndex]->SetVecValue( kDefaultValue, nSize ); \
  80. }
  81. // Typesafe flag setting
  82. inline void CShader_SetFlags2( IMaterialVar **params, MaterialVarFlags2_t _flag )
  83. {
  84. params[FLAGS2]->SetIntValue( params[FLAGS2]->GetIntValue() | (_flag) );
  85. }
  86. inline bool CShader_IsFlag2Set( IMaterialVar **params, MaterialVarFlags2_t _flag )
  87. {
  88. return ((params[FLAGS2]->GetIntValue() & (_flag) ) != 0);
  89. }
  90. #define SET_FLAGS2( _flag ) CShader_SetFlags2( params, _flag )
  91. #define CLEAR_FLAGS2( _flag ) params[FLAGS2]->SetIntValue( params[FLAGS2]->GetIntValue() & ~(_flag) )
  92. #define IS_FLAG2_SET( _flag ) CShader_IsFlag2Set( params, _flag )
  93. #define IS_FLAG2_DEFINED( _flag ) ((params[FLAGS_DEFINED2]->GetIntValue() & (_flag) ) != 0)
  94. #define __BEGIN_SHADER_INTERNAL(_baseclass, name, help, flags) \
  95. namespace name \
  96. {\
  97. typedef _baseclass CBaseClass;\
  98. static const char *s_HelpString = help; \
  99. static const char *s_Name = #name; \
  100. static int s_nFlags = flags; \
  101. class CShaderParam;\
  102. static CUtlVector<CShaderParam *> s_ShaderParams;\
  103. static CShaderParam *s_pShaderParamOverrides[NUM_SHADER_MATERIAL_VARS];\
  104. class CShaderParam\
  105. {\
  106. public:\
  107. CShaderParam( ShaderMaterialVars_t var, ShaderParamType_t type, const char *pDefaultParam, const char *pHelp, int nFlags )\
  108. {\
  109. m_Info.m_pName = "override";\
  110. m_Info.m_Type = type;\
  111. m_Info.m_pDefaultValue = pDefaultParam;\
  112. m_Info.m_pHelp = pHelp;\
  113. m_Info.m_nFlags = nFlags;\
  114. AssertMsg( !s_pShaderParamOverrides[var], ( "Shader parameter override duplicately defined!" ) );\
  115. s_pShaderParamOverrides[var] = this;\
  116. m_Index = var;\
  117. }\
  118. CShaderParam( const char *pName, ShaderParamType_t type, const char *pDefaultParam, const char *pHelp, int nFlags )\
  119. {\
  120. m_Info.m_pName = pName;\
  121. m_Info.m_Type = type;\
  122. m_Info.m_pDefaultValue = pDefaultParam;\
  123. m_Info.m_pHelp = pHelp;\
  124. m_Info.m_nFlags = nFlags;\
  125. m_Index = NUM_SHADER_MATERIAL_VARS + s_ShaderParams.Count();\
  126. s_ShaderParams.AddToTail( this );\
  127. }\
  128. operator int() \
  129. {\
  130. return m_Index;\
  131. }\
  132. const char *GetName()\
  133. {\
  134. return m_Info.m_pName;\
  135. }\
  136. ShaderParamType_t GetType()\
  137. {\
  138. return m_Info.m_Type;\
  139. }\
  140. const char *GetDefault()\
  141. {\
  142. return m_Info.m_pDefaultValue;\
  143. }\
  144. int GetFlags() const\
  145. {\
  146. return m_Info.m_nFlags;\
  147. }\
  148. const char *GetHelp()\
  149. {\
  150. return m_Info.m_pHelp;\
  151. }\
  152. private:\
  153. ShaderParamInfo_t m_Info; \
  154. int m_Index;\
  155. };\
  156. #define BEGIN_SHADER(name,help) __BEGIN_SHADER_INTERNAL( CBaseShader, name, help, 0 )
  157. #define BEGIN_SHADER_FLAGS(name,help,flags) __BEGIN_SHADER_INTERNAL( CBaseShader, name, help, flags )
  158. #define BEGIN_SHADER_PARAMS
  159. #define SHADER_PARAM( param, paramtype, paramdefault, paramhelp ) \
  160. static CShaderParam param( "$" #param, paramtype, paramdefault, paramhelp, 0 );
  161. #define SHADER_PARAM_FLAGS( param, paramtype, paramdefault, paramhelp, flags ) \
  162. static CShaderParam param( "$" #param, paramtype, paramdefault, paramhelp, flags );
  163. #define SHADER_PARAM_OVERRIDE( param, paramtype, paramdefault, paramhelp, flags ) \
  164. static CShaderParam param( (ShaderMaterialVars_t) ::param, paramtype, paramdefault, paramhelp, flags );
  165. // regarding the macro above: the "::" was added to the first argument in order to disambiguate it for GCC.
  166. // for example, in cloak.cpp, this usage appears:
  167. // SHADER_PARAM_OVERRIDE( COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE )
  168. // which in turn tries to ask the compiler to instantiate an object like so:
  169. // static CShaderParam COLOR( (ShaderMaterialVars_t)COLOR, SHADER_PARAM_TYPE_COLOR, "{255 255 255}", "unused", SHADER_PARAM_NOT_EDITABLE )
  170. // and GCC thinks that the reference to COLOR in the arg list is actually a reference to the object we're in the middle of making.
  171. // and you get --> error: invalid cast from type ‘Cloak_DX90::CShaderParam’ to type ‘ShaderMaterialVars_t’
  172. // Resolved: add the "::" so compiler knows that reference is to the enum, not to the name of the object being made.
  173. #define END_SHADER_PARAMS \
  174. class CShader : public CBaseClass\
  175. {\
  176. public:
  177. #define END_SHADER }; \
  178. static CShader s_ShaderInstance;\
  179. } // namespace
  180. #define SHADER_INIT \
  181. char const* GetName() const \
  182. { \
  183. return s_Name; \
  184. } \
  185. int GetFlags() const \
  186. { \
  187. return s_nFlags; \
  188. } \
  189. int GetNumParams() const \
  190. {\
  191. return CBaseClass::GetNumParams() + s_ShaderParams.Count();\
  192. }\
  193. char const* GetParamName( int param ) const \
  194. {\
  195. int nBaseClassParamCount = CBaseClass::GetNumParams(); \
  196. if (param < nBaseClassParamCount) \
  197. return CBaseClass::GetParamName(param); \
  198. else \
  199. return s_ShaderParams[param - nBaseClassParamCount]->GetName(); \
  200. }\
  201. char const* GetParamHelp( int param ) const \
  202. {\
  203. int nBaseClassParamCount = CBaseClass::GetNumParams(); \
  204. if (param < nBaseClassParamCount) \
  205. { \
  206. if ( !s_pShaderParamOverrides[param] ) \
  207. return CBaseClass::GetParamHelp( param ); \
  208. else \
  209. return s_pShaderParamOverrides[param]->GetHelp(); \
  210. } \
  211. else \
  212. return s_ShaderParams[param - nBaseClassParamCount]->GetHelp(); \
  213. }\
  214. ShaderParamType_t GetParamType( int param ) const \
  215. {\
  216. int nBaseClassParamCount = CBaseClass::GetNumParams(); \
  217. if (param < nBaseClassParamCount) \
  218. return CBaseClass::GetParamType( param ); \
  219. else \
  220. return s_ShaderParams[param - nBaseClassParamCount]->GetType(); \
  221. }\
  222. char const* GetParamDefault( int param ) const \
  223. {\
  224. int nBaseClassParamCount = CBaseClass::GetNumParams(); \
  225. if (param < nBaseClassParamCount) \
  226. { \
  227. if ( !s_pShaderParamOverrides[param] ) \
  228. return CBaseClass::GetParamDefault( param ); \
  229. else \
  230. return s_pShaderParamOverrides[param]->GetDefault(); \
  231. } \
  232. else \
  233. return s_ShaderParams[param - nBaseClassParamCount]->GetDefault(); \
  234. }\
  235. int GetParamFlags( int param ) const \
  236. {\
  237. int nBaseClassParamCount = CBaseClass::GetNumParams(); \
  238. if (param < nBaseClassParamCount) \
  239. { \
  240. if ( !s_pShaderParamOverrides[param] ) \
  241. return CBaseClass::GetParamFlags( param ); \
  242. else \
  243. return s_pShaderParamOverrides[param]->GetFlags(); \
  244. } \
  245. else \
  246. return s_ShaderParams[param - nBaseClassParamCount]->GetFlags(); \
  247. }\
  248. void OnInitShaderInstance( IMaterialVar **params, IShaderInit *pShaderInit, const char *pMaterialName )
  249. #define SHADER_DRAW \
  250. void OnDrawElements( IMaterialVar **params, IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr )
  251. #define SHADOW_STATE if (pShaderShadow)
  252. #define DYNAMIC_STATE if (pShaderAPI)
  253. #define ShaderWarning if (pShaderShadow) Warning
  254. //-----------------------------------------------------------------------------
  255. // Used to easily define a shader which *always* falls back
  256. //-----------------------------------------------------------------------------
  257. #define DEFINE_FALLBACK_SHADER( _shadername, _fallbackshadername ) \
  258. BEGIN_SHADER( _shadername, "" ) \
  259. BEGIN_SHADER_PARAMS \
  260. END_SHADER_PARAMS \
  261. SHADER_FALLBACK { return #_fallbackshadername; } \
  262. SHADER_INIT {} \
  263. SHADER_DRAW {} \
  264. END_SHADER
  265. //-----------------------------------------------------------------------------
  266. // Used to easily define a shader which inherits from another shader
  267. //-----------------------------------------------------------------------------
  268. // FIXME: There's a compiler bug preventing this from working.
  269. // Maybe it'll work under VC7!
  270. /*
  271. //#define BEGIN_INHERITED_SHADER( name, _baseclass, help ) \
  272. // namespace _baseclass \
  273. // {\
  274. // __BEGIN_SHADER_INTERNAL( _baseclass::CShader, name, help )
  275. */
  276. //#define END_INHERITED_SHADER END_SHADER }
  277. //#define CHAIN_SHADER_INIT_PARAMS() CBaseClass::OnInitShaderParams( params, pMaterialName )
  278. //#define CHAIN_SHADER_FALLBACK() CBaseClass::GetFallbackShader( params )
  279. //#define CHAIN_SHADER_INIT() CBaseClass::OnInitShaderInstance( params, pShaderInit, pMaterialName )
  280. //#define CHAIN_SHADER_DRAW() CBaseClass::OnDrawElements( params, pShaderShadow, pShaderAPI )
  281. // A dumbed-down version which does what I need now which works
  282. // This version doesn't allow you to do chain *anything* down to the base class
  283. #define BEGIN_INHERITED_SHADER_FLAGS( _name, _base, _help, _flags ) \
  284. namespace _base\
  285. {\
  286. namespace _name\
  287. {\
  288. static const char *s_Name = #_name; \
  289. static const char *s_HelpString = _help;\
  290. static int s_nFlags = _flags;\
  291. class CShader : public _base::CShader\
  292. {\
  293. public:\
  294. char const* GetName() const \
  295. { \
  296. return s_Name; \
  297. } \
  298. int GetFlags() const \
  299. { \
  300. return s_nFlags; \
  301. }
  302. #define BEGIN_INHERITED_SHADER( _name, _base, _help ) BEGIN_INHERITED_SHADER_FLAGS( _name, _base, _help, 0 )
  303. #define END_INHERITED_SHADER END_SHADER }
  304. // psh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_PIXEL_SHADER
  305. #define DECLARE_DYNAMIC_PIXEL_SHADER( shader ) \
  306. int declaredynpixshader_ ## shader ## _missingcurlybraces = 0; \
  307. NOTE_UNUSED( declaredynpixshader_ ## shader ## _missingcurlybraces ); \
  308. shader ## _Dynamic_Index _pshIndex; \
  309. int psh ## shader = 0
  310. // vsh ## shader is used here to generate a warning if you don't ever call SET_DYNAMIC_VERTEX_SHADER
  311. #define DECLARE_DYNAMIC_VERTEX_SHADER( shader ) \
  312. int declaredynvertshader_ ## shader ## _missingcurlybraces = 0; \
  313. NOTE_UNUSED( declaredynvertshader_ ## shader ## _missingcurlybraces ); \
  314. shader ## _Dynamic_Index _vshIndex; \
  315. int vsh ## shader = 0
  316. // psh ## shader is used here to generate a warning if you don't ever call SET_STATIC_PIXEL_SHADER
  317. #define DECLARE_STATIC_PIXEL_SHADER( shader ) \
  318. int declarestaticpixshader_ ## shader ## _missingcurlybraces = 0; \
  319. NOTE_UNUSED( declarestaticpixshader_ ## shader ## _missingcurlybraces ); \
  320. shader ## _Static_Index _pshIndex; \
  321. int psh ## shader = 0
  322. // vsh ## shader is used here to generate a warning if you don't ever call SET_STATIC_VERTEX_SHADER
  323. #define DECLARE_STATIC_VERTEX_SHADER( shader ) \
  324. int declarestaticvertshader_ ## shader ## _missingcurlybraces = 0; \
  325. NOTE_UNUSED( declarestaticvertshader_ ## shader ## _missingcurlybraces ); \
  326. shader ## _Static_Index _vshIndex; \
  327. int vsh ## shader = 0
  328. // psh_forgot_to_set_dynamic_ ## var is used to make sure that you set all
  329. // all combos. If you don't, you will get an undefined variable used error
  330. // in the SET_DYNAMIC_PIXEL_SHADER block.
  331. #define SET_DYNAMIC_PIXEL_SHADER_COMBO( var, val ) \
  332. int dynpixshadercombo_ ## var ## _missingcurlybraces = 0; \
  333. NOTE_UNUSED( dynpixshadercombo_ ## var ## _missingcurlybraces ); \
  334. _pshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n PS dyn var %s = %d (%s)", #var, (int) val, #val );}; \
  335. int psh_forgot_to_set_dynamic_ ## var = 0
  336. // vsh_forgot_to_set_dynamic_ ## var is used to make sure that you set all
  337. // all combos. If you don't, you will get an undefined variable used error
  338. // in the SET_DYNAMIC_VERTEX_SHADER block.
  339. #define SET_DYNAMIC_VERTEX_SHADER_COMBO( var, val ) \
  340. int dynvertshadercombo_ ## var ## _missingcurlybraces = 0; \
  341. NOTE_UNUSED( dynvertshadercombo_ ## var ## _missingcurlybraces ); \
  342. _vshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n VS dyn var %s = %d (%s)", #var, (int) val, #val );}; \
  343. int vsh_forgot_to_set_dynamic_ ## var = 0
  344. // psh_forgot_to_set_static_ ## var is used to make sure that you set all
  345. // all combos. If you don't, you will get an undefined variable used error
  346. // in the SET_STATIC_PIXEL_SHADER block.
  347. #define SET_STATIC_PIXEL_SHADER_COMBO( var, val ) \
  348. int staticpixshadercombo_ ## var ## _missingcurlybraces = 0; \
  349. NOTE_UNUSED( staticpixshadercombo_ ## var ## _missingcurlybraces ); \
  350. _pshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n PS stat var %s = %d (%s)", #var, (int) val, #val );}; \
  351. int psh_forgot_to_set_static_ ## var = 0
  352. // vsh_forgot_to_set_static_ ## var is used to make sure that you set all
  353. // all combos. If you don't, you will get an undefined variable used error
  354. // in the SET_STATIC_VERTEX_SHADER block.
  355. #define SET_STATIC_VERTEX_SHADER_COMBO( var, val ) \
  356. int staticvertshadercombo_ ## var ## _missingcurlybraces = 0; \
  357. NOTE_UNUSED( staticvertshadercombo_ ## var ## _missingcurlybraces ); \
  358. _vshIndex.Set ## var( ( val ) ); if(g_shaderConfigDumpEnable){printf("\n VS stat var %s = %d (%s)", #var, (int) val, #val );}; \
  359. int vsh_forgot_to_set_static_ ## var = 0
  360. // psh_testAllCombos adds up all of the psh_forgot_to_set_dynamic_ ## var's from
  361. // SET_DYNAMIC_PIXEL_SHADER_COMBO so that an error is generated if they aren't set.
  362. // psh_testAllCombos is set to itself to avoid an unused variable warning.
  363. // psh ## shader being set to itself ensures that DECLARE_DYNAMIC_PIXEL_SHADER
  364. // was called for this particular shader.
  365. #define SET_DYNAMIC_PIXEL_SHADER( shader ) \
  366. int dynamicpixshader_ ## shader ## _missingcurlybraces = 0; \
  367. NOTE_UNUSED( dynamicpixshader_ ## shader ## _missingcurlybraces ); \
  368. int psh_testAllCombos = shaderDynamicTest_ ## shader; \
  369. NOTE_UNUSED( psh_testAllCombos ); \
  370. NOTE_UNUSED( psh ## shader ); \
  371. pShaderAPI->SetPixelShaderIndex( _pshIndex.GetIndex() )
  372. #define SET_DYNAMIC_PIXEL_SHADER_CMD( cmdstream, shader ) \
  373. int dynamicpixshader_ ## shader ## _missingcurlybraces = 0; \
  374. NOTE_UNUSED( dynamicpixshader_ ## shader ## _missingcurlybraces ); \
  375. int psh_testAllCombos = shaderDynamicTest_ ## shader; \
  376. NOTE_UNUSED( psh_testAllCombos ); \
  377. NOTE_UNUSED( psh ## shader ); \
  378. cmdstream.SetPixelShaderIndex( _pshIndex.GetIndex() )
  379. // vsh_testAllCombos adds up all of the vsh_forgot_to_set_dynamic_ ## var's from
  380. // SET_DYNAMIC_VERTEX_SHADER_COMBO so that an error is generated if they aren't set.
  381. // vsh_testAllCombos is set to itself to avoid an unused variable warning.
  382. // vsh ## shader being set to itself ensures that DECLARE_DYNAMIC_VERTEX_SHADER
  383. // was called for this particular shader.
  384. #define SET_DYNAMIC_VERTEX_SHADER( shader ) \
  385. int dynamicvertshader_ ## shader ## _missingcurlybraces = 0; \
  386. NOTE_UNUSED( dynamicvertshader_ ## shader ## _missingcurlybraces ); \
  387. int vsh_testAllCombos = shaderDynamicTest_ ## shader; \
  388. NOTE_UNUSED( vsh_testAllCombos ); \
  389. NOTE_UNUSED( vsh ## shader ); \
  390. pShaderAPI->SetVertexShaderIndex( _vshIndex.GetIndex() )
  391. #define SET_DYNAMIC_VERTEX_SHADER_CMD( cmdstream, shader ) \
  392. int dynamicvertshader_ ## shader ## _missingcurlybraces = 0; \
  393. NOTE_UNUSED( dynamicvertshader_ ## shader ## _missingcurlybraces ); \
  394. int vsh_testAllCombos = shaderDynamicTest_ ## shader; \
  395. NOTE_UNUSED( vsh_testAllCombos ); \
  396. NOTE_UNUSED( vsh ## shader ); \
  397. cmdstream.SetVertexShaderIndex( _vshIndex.GetIndex() )
  398. // psh_testAllCombos adds up all of the psh_forgot_to_set_static_ ## var's from
  399. // SET_STATIC_PIXEL_SHADER_COMBO so that an error is generated if they aren't set.
  400. // psh_testAllCombos is set to itself to avoid an unused variable warning.
  401. // psh ## shader being set to itself ensures that DECLARE_STATIC_PIXEL_SHADER
  402. // was called for this particular shader.
  403. #define SET_STATIC_PIXEL_SHADER( shader ) \
  404. int staticpixshader_ ## shader ## _missingcurlybraces = 0; \
  405. NOTE_UNUSED( staticpixshader_ ## shader ## _missingcurlybraces ); \
  406. int psh_testAllCombos = shaderStaticTest_ ## shader; \
  407. NOTE_UNUSED( psh_testAllCombos ); \
  408. NOTE_UNUSED( psh ## shader ); \
  409. pShaderShadow->SetPixelShader( #shader, _pshIndex.GetIndex() )
  410. // vsh_testAllCombos adds up all of the vsh_forgot_to_set_static_ ## var's from
  411. // SET_STATIC_VERTEX_SHADER_COMBO so that an error is generated if they aren't set.
  412. // vsh_testAllCombos is set to itself to avoid an unused variable warning.
  413. // vsh ## shader being set to itself ensures that DECLARE_STATIC_VERTEX_SHADER
  414. // was called for this particular shader.
  415. #define SET_STATIC_VERTEX_SHADER( shader ) \
  416. int staticvertshader_ ## shader ## _missingcurlybraces = 0; \
  417. NOTE_UNUSED( staticvertshader_ ## shader ## _missingcurlybraces ); \
  418. int vsh_testAllCombos = shaderStaticTest_ ## shader; \
  419. NOTE_UNUSED( vsh_testAllCombos ); \
  420. NOTE_UNUSED( vsh ## shader ); \
  421. pShaderShadow->SetVertexShader( #shader, _vshIndex.GetIndex() )
  422. #endif // CSHADER_H