Counter Strike : Global Offensive Source Code
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.

256 lines
8.7 KiB

  1. //========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ISHADER_H
  9. #define ISHADER_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. //==================================================================================================
  14. // **this goes into both platforms which run the translator, either the real Mac client or
  15. // the Windows client running with r_emulategl mode **
  16. //
  17. // size of the VS register bank in ARB / GLSL we expose
  18. #define DXABSTRACT_VS_PARAM_SLOTS 256
  19. #define DXABSTRACT_VS_FIRST_BONE_SLOT VERTEX_SHADER_MODEL
  20. #define DXABSTRACT_VS_LAST_BONE_SLOT (VERTEX_SHADER_SHADER_SPECIFIC_CONST_13-1)
  21. // user clip plane 0 goes in DXABSTRACT_VS_CLIP_PLANE_BASE... plane 1 goes in the slot after that
  22. // dxabstract uses these constants to check plane index limit and to deliver planes to shader for DP4 -> oCLP[n]
  23. #define DXABSTRACT_VS_CLIP_PLANE_BASE (DXABSTRACT_VS_PARAM_SLOTS-2)
  24. //==================================================================================================
  25. #include "materialsystem/imaterialsystem.h"
  26. #include "materialsystem/ishaderapi.h"
  27. //-----------------------------------------------------------------------------
  28. // forward declarations
  29. //-----------------------------------------------------------------------------
  30. class IMaterialVar;
  31. class IShaderShadow;
  32. class IShaderDynamicAPI;
  33. class IShaderInit;
  34. class CBasePerMaterialContextData;
  35. //-----------------------------------------------------------------------------
  36. // Shader flags
  37. //-----------------------------------------------------------------------------
  38. enum ShaderFlags_t
  39. {
  40. SHADER_NOT_EDITABLE = 0x1
  41. };
  42. //-----------------------------------------------------------------------------
  43. // Shader parameter flags
  44. //-----------------------------------------------------------------------------
  45. enum ShaderParamFlags_t
  46. {
  47. SHADER_PARAM_NOT_EDITABLE = 0x1
  48. };
  49. //-----------------------------------------------------------------------------
  50. // Information about each shader parameter
  51. //-----------------------------------------------------------------------------
  52. struct ShaderParamInfo_t
  53. {
  54. const char *m_pName;
  55. const char *m_pHelp;
  56. ShaderParamType_t m_Type;
  57. const char *m_pDefaultValue;
  58. int m_nFlags;
  59. };
  60. //-----------------------------------------------------------------------------
  61. // shaders can keep per material data in classes descended from this
  62. //-----------------------------------------------------------------------------
  63. class CBasePerMaterialContextData
  64. {
  65. public:
  66. uint32 m_nVarChangeID;
  67. bool m_bMaterialVarsChanged; // set by mat system when material vars change. shader should rehtink and then clear the var
  68. FORCEINLINE CBasePerMaterialContextData( void )
  69. {
  70. m_bMaterialVarsChanged = true;
  71. m_nVarChangeID = 0xffffffff;
  72. }
  73. // virtual destructor so that derived classes can have their own data to be cleaned up on
  74. // delete of material
  75. virtual ~CBasePerMaterialContextData( void )
  76. {
  77. }
  78. };
  79. //-----------------------------------------------------------------------------
  80. // shaders can keep per instance data in classes descended from this
  81. //-----------------------------------------------------------------------------
  82. class CBasePerInstanceContextData
  83. {
  84. public:
  85. virtual unsigned char* GetInstanceCommandBuffer() = 0;
  86. // virtual destructor so that derived classes can have their own data
  87. // to be cleaned up on delete of material
  88. virtual ~CBasePerInstanceContextData( void )
  89. {
  90. }
  91. };
  92. //-----------------------------------------------------------------------------
  93. // Standard vertex shader constants
  94. //-----------------------------------------------------------------------------
  95. enum
  96. {
  97. // Standard vertex shader constants
  98. VERTEX_SHADER_MATH_CONSTANTS0 = 0,
  99. VERTEX_SHADER_MATH_CONSTANTS1 = 1,
  100. VERTEX_SHADER_CAMERA_POS = 2,
  101. VERTEX_SHADER_LIGHT_INDEX = 3,
  102. VERTEX_SHADER_MODELVIEWPROJ = 4,
  103. VERTEX_SHADER_VIEWPROJ = 8,
  104. VERTEX_SHADER_SHADER_SPECIFIC_CONST_12 = 12,
  105. VERTEX_SHADER_FLEXSCALE = 13,
  106. VERTEX_SHADER_SHADER_SPECIFIC_CONST_10 = 14,
  107. VERTEX_SHADER_SHADER_SPECIFIC_CONST_11 = 15,
  108. VERTEX_SHADER_FOG_PARAMS = 16,
  109. VERTEX_SHADER_VIEWMODEL = 17,
  110. VERTEX_SHADER_AMBIENT_LIGHT = 21,
  111. VERTEX_SHADER_LIGHTS = 27,
  112. VERTEX_SHADER_LIGHT0_POSITION = 29,
  113. VERTEX_SHADER_MODULATION_COLOR = 47,
  114. VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 = 48,
  115. VERTEX_SHADER_SHADER_SPECIFIC_CONST_1 = 49,
  116. VERTEX_SHADER_SHADER_SPECIFIC_CONST_2 = 50,
  117. VERTEX_SHADER_SHADER_SPECIFIC_CONST_3 = 51,
  118. VERTEX_SHADER_SHADER_SPECIFIC_CONST_4 = 52,
  119. VERTEX_SHADER_SHADER_SPECIFIC_CONST_5 = 53,
  120. VERTEX_SHADER_SHADER_SPECIFIC_CONST_6 = 54,
  121. VERTEX_SHADER_SHADER_SPECIFIC_CONST_7 = 55,
  122. VERTEX_SHADER_SHADER_SPECIFIC_CONST_8 = 56,
  123. VERTEX_SHADER_SHADER_SPECIFIC_CONST_9 = 57,
  124. VERTEX_SHADER_MODEL = 58,
  125. //
  126. // We reserve up through 217 for the 53 bones supported on DX9
  127. //
  128. VERTEX_SHADER_SHADER_SPECIFIC_CONST_CSM = 37, // to match the define in common_vs_fxc.h
  129. VERTEX_SHADER_SHADER_SPECIFIC_CONST_13 = 217,
  130. VERTEX_SHADER_SHADER_SPECIFIC_CONST_14 = 219,
  131. VERTEX_SHADER_SHADER_SPECIFIC_CONST_15 = 221,
  132. VERTEX_SHADER_SHADER_SPECIFIC_CONST_16 = 223,
  133. // 254 ClipPlane0 |------ OpenGL will jam clip planes into these two
  134. // 255 ClipPlane1 |
  135. VERTEX_SHADER_FLEX_WEIGHTS = 1024,
  136. VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT = 512,
  137. };
  138. #define VERTEX_SHADER_BONE_TRANSFORM( k ) ( VERTEX_SHADER_MODEL + 3 * (k) )
  139. //-----------------------------------------------------------------------------
  140. // Standard vertex shader constants
  141. //-----------------------------------------------------------------------------
  142. enum
  143. {
  144. // Standard vertex shader constants
  145. VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST = 0,
  146. VERTEX_SHADER_LIGHT_ENABLE_BOOL_CONST_COUNT = 4,
  147. VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_0 = 4,
  148. VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_1 = 5,
  149. VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_2 = 6,
  150. VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_3 = 7,
  151. VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_4 = 8,
  152. VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_5 = 9,
  153. VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_6 = 10,
  154. VERTEX_SHADER_SHADER_SPECIFIC_BOOL_CONST_7 = 11,
  155. };
  156. //-----------------------------------------------------------------------------
  157. // The public methods exposed by each shader
  158. //-----------------------------------------------------------------------------
  159. abstract_class IShader
  160. {
  161. public:
  162. // Returns the shader name
  163. virtual char const* GetName( ) const = 0;
  164. // returns the shader fallbacks
  165. virtual char const* GetFallbackShader( IMaterialVar** params ) const = 0;
  166. // Shader parameters
  167. virtual int GetParamCount( ) const = 0;
  168. virtual const ShaderParamInfo_t& GetParamInfo( int paramIndex ) const = 0;
  169. // These functions must be implemented by the shader
  170. virtual void InitShaderParams( IMaterialVar** ppParams, const char *pMaterialName ) = 0;
  171. virtual void InitShaderInstance( IMaterialVar** ppParams, IShaderInit *pShaderInit, const char *pMaterialName, const char *pTextureGroupName ) = 0;
  172. virtual void DrawElements( IMaterialVar **params, int nModulationFlags,
  173. IShaderShadow* pShaderShadow, IShaderDynamicAPI* pShaderAPI,
  174. VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr, CBasePerInstanceContextData** pInstanceDataPtr ) = 0;
  175. virtual void ExecuteFastPath( int * vsDynIndex, int *psDynIndex, IMaterialVar** params,
  176. IShaderDynamicAPI * pShaderAPI, VertexCompressionType_t vertexCompression, CBasePerMaterialContextData **pContextDataPtr,
  177. BOOL bCSMEnabled )
  178. {
  179. *vsDynIndex = -1;
  180. *psDynIndex = -1;
  181. }
  182. // FIXME: Figure out a better way to do this?
  183. virtual int ComputeModulationFlags( IMaterialVar** params, IShaderDynamicAPI* pShaderAPI ) = 0;
  184. virtual bool NeedsPowerOfTwoFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame = true ) const = 0;
  185. virtual bool NeedsFullFrameBufferTexture( IMaterialVar **params, bool bCheckSpecificToThisFrame ) const = 0;
  186. virtual bool IsTranslucent( IMaterialVar **params ) const = 0;
  187. virtual int GetFlags() const = 0;
  188. virtual void SetPPParams( IMaterialVar **params ) = 0;
  189. virtual void SetModulationFlags( int modulationFlags ) = 0;
  190. };
  191. //-----------------------------------------------------------------------------
  192. // Shader dictionaries defined in DLLs
  193. //-----------------------------------------------------------------------------
  194. enum PrecompiledShaderType_t
  195. {
  196. PRECOMPILED_VERTEX_SHADER = 0,
  197. PRECOMPILED_PIXEL_SHADER,
  198. PRECOMPILED_SHADER_TYPE_COUNT,
  199. };
  200. //-----------------------------------------------------------------------------
  201. // Flags field of PrecompiledShader_t
  202. //-----------------------------------------------------------------------------
  203. enum
  204. {
  205. // runtime flags
  206. SHADER_IS_ASM = 0x1,
  207. SHADER_FAILED_LOAD = 0x2,
  208. };
  209. #endif // ISHADER_H