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.

258 lines
9.0 KiB

  1. //===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #ifndef IMATERIALSYSTEMHARDWARECONFIG_H
  9. #define IMATERIALSYSTEMHARDWARECONFIG_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #if defined( DX_TO_GL_ABSTRACTION )
  14. #define IsPlatformOpenGL() true
  15. #else
  16. #define IsPlatformOpenGL() false
  17. #endif
  18. #include "tier1/interface.h"
  19. //#include "tier2/tier2.h"
  20. #include "bitmap/imageformat.h"
  21. #include "imaterialsystem.h"
  22. //-----------------------------------------------------------------------------
  23. // Material system interface version
  24. //-----------------------------------------------------------------------------
  25. FORCEINLINE bool IsOpenGL( void )
  26. {
  27. return IsPlatformOpenGL();
  28. }
  29. //-----------------------------------------------------------------------------
  30. // Material system interface version
  31. //-----------------------------------------------------------------------------
  32. // For now, vertex compression is simply "on or off" (for the sake of simplicity
  33. // and MeshBuilder perf.), but later we may support multiple flavours.
  34. enum VertexCompressionType_t
  35. {
  36. // This indicates an uninitialized VertexCompressionType_t value
  37. VERTEX_COMPRESSION_INVALID = 0xFFFFFFFF,
  38. // 'VERTEX_COMPRESSION_NONE' means that no elements of a vertex are compressed
  39. VERTEX_COMPRESSION_NONE = 0,
  40. // Currently (more stuff may be added as needed), 'VERTEX_COMPRESSION_ON' means:
  41. // - if a vertex contains VERTEX_ELEMENT_NORMAL, this is compressed
  42. // (see CVertexBuilder::CompressedNormal3f)
  43. // - if a vertex contains VERTEX_ELEMENT_USERDATA4 (and a normal - together defining a tangent
  44. // frame, with the binormal reconstructed in the vertex shader), this is compressed
  45. // (see CVertexBuilder::CompressedUserData)
  46. // - if a vertex contains VERTEX_ELEMENT_BONEWEIGHTSx, this is compressed
  47. // (see CVertexBuilder::CompressedBoneWeight3fv)
  48. VERTEX_COMPRESSION_ON = 1
  49. };
  50. // use DEFCONFIGMETHOD to define time-critical methods that we want to make just return constants
  51. // on the 360, so that the checks will happen at compile time. Not all methods are defined this way
  52. // - just the ones that I perceive as being called often in the frame interval.
  53. #ifdef _GAMECONSOLE
  54. #define DEFCONFIGMETHOD( ret_type, method, xbox_return_value ) \
  55. FORCEINLINE ret_type method const \
  56. { \
  57. return xbox_return_value; \
  58. }
  59. #else
  60. #define DEFCONFIGMETHOD( ret_type, method, xbox_return_value ) \
  61. virtual ret_type method const = 0;
  62. #endif
  63. //-----------------------------------------------------------------------------
  64. // Shadow filter types
  65. // Important notes: These enums directly correspond to combo indices.
  66. // If you change these, make the corresponding change in common_ps_fxc.h
  67. // Cheap ones are at the end on purpose, and are only run on ps2b
  68. // SHADOWFILTERMODE_DEFAULT must be 0.
  69. //-----------------------------------------------------------------------------
  70. enum ShadowFilterMode_t
  71. {
  72. SHADOWFILTERMODE_DEFAULT = 0,
  73. NVIDIA_PCF = 0,
  74. ATI_NO_PCF_FETCH4 = 1,
  75. NVIDIA_PCF_CHEAP = 2,
  76. ATI_NOPCF = 3,
  77. // Game consoles use a different set of combo indices to control shadow filtering.
  78. GAMECONSOLE_NINE_TAP_PCF = 0,
  79. GAMECONSOLE_SINGLE_TAP_PCF = 1,
  80. // All modes >= SHADOWFILTERMODE_FIRST_CHEAP_MODE are considered the "cheap" modes.
  81. #if defined( _GAMECONSOLE )
  82. SHADOWFILTERMODE_FIRST_CHEAP_MODE = GAMECONSOLE_SINGLE_TAP_PCF,
  83. #else
  84. SHADOWFILTERMODE_FIRST_CHEAP_MODE = NVIDIA_PCF_CHEAP,
  85. #endif
  86. };
  87. //-----------------------------------------------------------------------------
  88. //
  89. //-----------------------------------------------------------------------------
  90. enum CSMQualityMode_t
  91. {
  92. CSMQUALITY_VERY_LOW,
  93. CSMQUALITY_LOW,
  94. CSMQUALITY_MEDIUM,
  95. CSMQUALITY_HIGH,
  96. CSMQUALITY_TOTAL_MODES
  97. };
  98. // CSMShaderMode_t must match the CSM_MODE static combo in the pixel shaders
  99. enum CSMShaderMode_t
  100. {
  101. CSMSHADERMODE_LOW_OR_VERY_LOW = 0,
  102. CSMSHADERMODE_MEDIUM = 1,
  103. CSMSHADERMODE_HIGH = 2,
  104. CSMSHADERMODE_ATIFETCH4 = 3,
  105. CSMSHADERMODE_TOTAL_MODES
  106. };
  107. //-----------------------------------------------------------------------------
  108. // Material system configuration
  109. //-----------------------------------------------------------------------------
  110. class IMaterialSystemHardwareConfig
  111. {
  112. public:
  113. virtual int GetFrameBufferColorDepth() const = 0;
  114. virtual int GetSamplerCount() const = 0;
  115. virtual bool HasSetDeviceGammaRamp() const = 0;
  116. DEFCONFIGMETHOD( bool, SupportsStaticControlFlow(), true );
  117. virtual VertexCompressionType_t SupportsCompressedVertices() const = 0;
  118. virtual int MaximumAnisotropicLevel() const = 0; // 0 means no anisotropic filtering
  119. virtual int MaxTextureWidth() const = 0;
  120. virtual int MaxTextureHeight() const = 0;
  121. virtual int TextureMemorySize() const = 0;
  122. virtual bool SupportsMipmappedCubemaps() const = 0;
  123. virtual int NumVertexShaderConstants() const = 0;
  124. virtual int NumPixelShaderConstants() const = 0;
  125. virtual int MaxNumLights() const = 0;
  126. virtual int MaxTextureAspectRatio() const = 0;
  127. virtual int MaxVertexShaderBlendMatrices() const = 0;
  128. virtual int MaxUserClipPlanes() const = 0;
  129. virtual bool UseFastClipping() const = 0;
  130. // This here should be the major item looked at when checking for compat
  131. // from anywhere other than the material system shaders
  132. DEFCONFIGMETHOD( int, GetDXSupportLevel(), 98 );
  133. virtual const char *GetShaderDLLName() const = 0;
  134. virtual bool ReadPixelsFromFrontBuffer() const = 0;
  135. // Are dx dynamic textures preferred?
  136. virtual bool PreferDynamicTextures() const = 0;
  137. DEFCONFIGMETHOD( bool, SupportsHDR(), true );
  138. virtual bool NeedsAAClamp() const = 0;
  139. virtual bool NeedsATICentroidHack() const = 0;
  140. // This is the max dx support level supported by the card
  141. virtual int GetMaxDXSupportLevel() const = 0;
  142. // Does the card specify fog color in linear space when sRGBWrites are enabled?
  143. virtual bool SpecifiesFogColorInLinearSpace() const = 0;
  144. // Does the card support sRGB reads/writes?
  145. DEFCONFIGMETHOD( bool, SupportsSRGB(), true );
  146. DEFCONFIGMETHOD( bool, FakeSRGBWrite(), false );
  147. DEFCONFIGMETHOD( bool, CanDoSRGBReadFromRTs(), true );
  148. virtual bool SupportsGLMixedSizeTargets() const = 0;
  149. virtual bool IsAAEnabled() const = 0; // Is antialiasing being used?
  150. // NOTE: Anything after this was added after shipping HL2.
  151. virtual int GetVertexSamplerCount() const = 0;
  152. virtual int GetMaxVertexTextureDimension() const = 0;
  153. virtual int MaxTextureDepth() const = 0;
  154. virtual HDRType_t GetHDRType() const = 0;
  155. virtual HDRType_t GetHardwareHDRType() const = 0;
  156. virtual bool SupportsStreamOffset() const = 0;
  157. virtual int StencilBufferBits() const = 0;
  158. virtual int MaxViewports() const = 0;
  159. virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) = 0;
  160. virtual ShadowFilterMode_t GetShadowFilterMode( bool bForceLowQualityShadows, bool bPS30 ) const = 0;
  161. virtual int NeedsShaderSRGBConversion() const = 0;
  162. DEFCONFIGMETHOD( bool, UsesSRGBCorrectBlending(), IsX360() );
  163. virtual bool HasFastVertexTextures() const = 0;
  164. virtual int MaxHWMorphBatchCount() const = 0;
  165. virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const = 0;
  166. virtual bool GetHDREnabled( void ) const = 0;
  167. virtual void SetHDREnabled( bool bEnable ) = 0;
  168. virtual bool SupportsBorderColor( void ) const = 0;
  169. virtual bool SupportsFetch4( void ) const = 0;
  170. virtual float GetShadowDepthBias() const = 0;
  171. virtual float GetShadowSlopeScaleDepthBias() const = 0;
  172. virtual bool PreferZPrepass() const = 0;
  173. virtual bool SuppressPixelShaderCentroidHackFixup() const = 0;
  174. virtual bool PreferTexturesInHWMemory() const = 0;
  175. virtual bool PreferHardwareSync() const = 0;
  176. virtual bool ActualHasFastVertexTextures() const = 0;
  177. virtual bool SupportsShadowDepthTextures( void ) const = 0;
  178. virtual ImageFormat GetShadowDepthTextureFormat( void ) const = 0;
  179. virtual ImageFormat GetHighPrecisionShadowDepthTextureFormat( void ) const = 0;
  180. virtual ImageFormat GetNullTextureFormat( void ) const = 0;
  181. virtual int GetMinDXSupportLevel() const = 0;
  182. virtual bool IsUnsupported() const = 0;
  183. virtual float GetLightMapScaleFactor() const = 0;
  184. virtual bool SupportsCascadedShadowMapping() const = 0;
  185. virtual CSMQualityMode_t GetCSMQuality() const = 0;
  186. virtual bool SupportsBilinearPCFSampling() const = 0;
  187. virtual CSMShaderMode_t GetCSMShaderMode( CSMQualityMode_t nQualityLevel ) const = 0;
  188. virtual bool GetCSMAccurateBlending( void ) const = 0;
  189. virtual void SetCSMAccurateBlending( bool bEnable ) = 0;
  190. virtual bool SupportsResolveDepth() const = 0;
  191. virtual bool HasFullResolutionDepthTexture() const = 0;
  192. // Backward compat for stdshaders
  193. #if defined ( STDSHADER_DBG_DLL_EXPORT ) || defined( STDSHADER_DX9_DLL_EXPORT )
  194. inline bool SupportsPixelShaders_2_b() const { return GetDXSupportLevel() >= 92; }
  195. inline bool SupportsPixelShaders_3_0() const { return GetDXSupportLevel() >= 95; }
  196. #endif
  197. inline bool ShouldAlwaysUseShaderModel2bShaders() const { return IsOpenGL(); }
  198. inline bool PlatformRequiresNonNullPixelShaders() const { return IsOpenGL(); }
  199. };
  200. #endif // IMATERIALSYSTEMHARDWARECONFIG_H