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.

213 lines
7.8 KiB

  1. //========= Copyright 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. #include "tier1/interface.h"
  14. //-----------------------------------------------------------------------------
  15. // GL helpers
  16. //-----------------------------------------------------------------------------
  17. FORCEINLINE bool IsEmulatingGL()
  18. {
  19. static bool bIsEmulatingGL = ( Plat_GetCommandLineA() ) ? ( strstr( Plat_GetCommandLineA(), "-r_emulate_gl" ) != NULL ) : false;
  20. return bIsEmulatingGL;
  21. }
  22. FORCEINLINE bool IsOpenGL( void )
  23. {
  24. return IsPlatformOpenGL() || IsEmulatingGL();
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Material system interface version
  28. //-----------------------------------------------------------------------------
  29. #define MATERIALSYSTEM_HARDWARECONFIG_INTERFACE_VERSION "MaterialSystemHardwareConfig012"
  30. // HDRFIXME NOTE: must match common_ps_fxc.h
  31. enum HDRType_t
  32. {
  33. HDR_TYPE_NONE,
  34. HDR_TYPE_INTEGER,
  35. HDR_TYPE_FLOAT,
  36. };
  37. // For now, vertex compression is simply "on or off" (for the sake of simplicity
  38. // and MeshBuilder perf.), but later we may support multiple flavours.
  39. enum VertexCompressionType_t
  40. {
  41. // This indicates an uninitialized VertexCompressionType_t value
  42. VERTEX_COMPRESSION_INVALID = 0xFFFFFFFF,
  43. // 'VERTEX_COMPRESSION_NONE' means that no elements of a vertex are compressed
  44. VERTEX_COMPRESSION_NONE = 0,
  45. // Currently (more stuff may be added as needed), 'VERTEX_COMPRESSION_ON' means:
  46. // - if a vertex contains VERTEX_ELEMENT_NORMAL, this is compressed
  47. // (see CVertexBuilder::CompressedNormal3f)
  48. // - if a vertex contains VERTEX_ELEMENT_USERDATA4 (and a normal - together defining a tangent
  49. // frame, with the binormal reconstructed in the vertex shader), this is compressed
  50. // (see CVertexBuilder::CompressedUserData)
  51. // - if a vertex contains VERTEX_ELEMENT_BONEWEIGHTSx, this is compressed
  52. // (see CVertexBuilder::CompressedBoneWeight3fv)
  53. VERTEX_COMPRESSION_ON = 1
  54. };
  55. // use DEFCONFIGMETHOD to define time-critical methods that we want to make just return constants
  56. // on the 360, so that the checks will happen at compile time. Not all methods are defined this way
  57. // - just the ones that I perceive as being called often in the frame interval.
  58. #ifdef _X360
  59. #define DEFCONFIGMETHOD( ret_type, method, xbox_return_value ) \
  60. FORCEINLINE ret_type method const \
  61. { \
  62. return xbox_return_value; \
  63. }
  64. #else
  65. #define DEFCONFIGMETHOD( ret_type, method, xbox_return_value ) \
  66. virtual ret_type method const = 0;
  67. #endif
  68. //-----------------------------------------------------------------------------
  69. // Material system configuration
  70. //-----------------------------------------------------------------------------
  71. class IMaterialSystemHardwareConfig
  72. {
  73. public:
  74. // on xbox, some methods are inlined to return constants
  75. DEFCONFIGMETHOD( bool, HasDestAlphaBuffer(), true );
  76. DEFCONFIGMETHOD( bool, HasStencilBuffer(), true );
  77. virtual int GetFrameBufferColorDepth() const = 0;
  78. virtual int GetSamplerCount() const = 0;
  79. virtual bool HasSetDeviceGammaRamp() const = 0;
  80. DEFCONFIGMETHOD( bool, SupportsCompressedTextures(), true );
  81. virtual VertexCompressionType_t SupportsCompressedVertices() const = 0;
  82. virtual bool SupportsNormalMapCompression() const { return false; }
  83. DEFCONFIGMETHOD( bool, SupportsVertexAndPixelShaders(), true );
  84. DEFCONFIGMETHOD( bool, SupportsPixelShaders_1_4(), true );
  85. DEFCONFIGMETHOD( bool, SupportsStaticControlFlow(), true );
  86. DEFCONFIGMETHOD( bool, SupportsPixelShaders_2_0(), true );
  87. DEFCONFIGMETHOD( bool, SupportsVertexShaders_2_0(), true );
  88. virtual int MaximumAnisotropicLevel() const = 0; // 0 means no anisotropic filtering
  89. virtual int MaxTextureWidth() const = 0;
  90. virtual int MaxTextureHeight() const = 0;
  91. virtual int TextureMemorySize() const = 0;
  92. virtual bool SupportsOverbright() const = 0;
  93. virtual bool SupportsCubeMaps() const = 0;
  94. virtual bool SupportsMipmappedCubemaps() const = 0;
  95. virtual bool SupportsNonPow2Textures() const = 0;
  96. // The number of texture stages represents the number of computations
  97. // we can do in the fixed-function pipeline, it is *not* related to the
  98. // simultaneous number of textures we can use
  99. virtual int GetTextureStageCount() const = 0;
  100. virtual int NumVertexShaderConstants() const = 0;
  101. virtual int NumPixelShaderConstants() const = 0;
  102. virtual int MaxNumLights() const = 0;
  103. virtual bool SupportsHardwareLighting() const = 0;
  104. virtual int MaxBlendMatrices() const = 0;
  105. virtual int MaxBlendMatrixIndices() const = 0;
  106. virtual int MaxTextureAspectRatio() const = 0;
  107. virtual int MaxVertexShaderBlendMatrices() const = 0;
  108. virtual int MaxUserClipPlanes() const = 0;
  109. virtual bool UseFastClipping() const = 0;
  110. // This here should be the major item looked at when checking for compat
  111. // from anywhere other than the material system shaders
  112. DEFCONFIGMETHOD( int, GetDXSupportLevel(), 98 );
  113. virtual const char *GetShaderDLLName() const = 0;
  114. virtual bool ReadPixelsFromFrontBuffer() const = 0;
  115. // Are dx dynamic textures preferred?
  116. virtual bool PreferDynamicTextures() const = 0;
  117. DEFCONFIGMETHOD( bool, SupportsHDR(), true );
  118. virtual bool HasProjectedBumpEnv() const = 0;
  119. virtual bool SupportsSpheremapping() const = 0;
  120. virtual bool NeedsAAClamp() const = 0;
  121. virtual bool NeedsATICentroidHack() const = 0;
  122. virtual bool SupportsColorOnSecondStream() const = 0;
  123. virtual bool SupportsStaticPlusDynamicLighting() const = 0;
  124. // Does our card have a hard time with fillrate
  125. // relative to other cards w/ the same dx level?
  126. virtual bool PreferReducedFillrate() const = 0;
  127. // This is the max dx support level supported by the card
  128. virtual int GetMaxDXSupportLevel() const = 0;
  129. // Does the card specify fog color in linear space when sRGBWrites are enabled?
  130. virtual bool SpecifiesFogColorInLinearSpace() const = 0;
  131. // Does the card support sRGB reads/writes?
  132. DEFCONFIGMETHOD( bool, SupportsSRGB(), true );
  133. DEFCONFIGMETHOD( bool, FakeSRGBWrite(), false );
  134. DEFCONFIGMETHOD( bool, CanDoSRGBReadFromRTs(), true );
  135. virtual bool SupportsGLMixedSizeTargets() const = 0;
  136. virtual bool IsAAEnabled() const = 0; // Is antialiasing being used?
  137. // NOTE: Anything after this was added after shipping HL2.
  138. virtual int GetVertexTextureCount() const = 0;
  139. virtual int GetMaxVertexTextureDimension() const = 0;
  140. virtual int MaxTextureDepth() const = 0;
  141. virtual HDRType_t GetHDRType() const = 0;
  142. virtual HDRType_t GetHardwareHDRType() const = 0;
  143. DEFCONFIGMETHOD( bool, SupportsPixelShaders_2_b(), true );
  144. virtual bool SupportsStreamOffset() const = 0;
  145. virtual int StencilBufferBits() const = 0;
  146. virtual int MaxViewports() const = 0;
  147. virtual void OverrideStreamOffsetSupport( bool bOverrideEnabled, bool bEnableSupport ) = 0;
  148. virtual int GetShadowFilterMode() const = 0;
  149. virtual int NeedsShaderSRGBConversion() const = 0;
  150. DEFCONFIGMETHOD( bool, UsesSRGBCorrectBlending(), true );
  151. virtual bool SupportsShaderModel_3_0() const = 0;
  152. virtual bool HasFastVertexTextures() const = 0;
  153. virtual int MaxHWMorphBatchCount() const = 0;
  154. // Does the board actually support this?
  155. DEFCONFIGMETHOD( bool, ActuallySupportsPixelShaders_2_b(), true );
  156. virtual bool SupportsHDRMode( HDRType_t nHDRMode ) const = 0;
  157. virtual bool GetHDREnabled( void ) const = 0;
  158. virtual void SetHDREnabled( bool bEnable ) = 0;
  159. virtual bool SupportsBorderColor( void ) const = 0;
  160. virtual bool SupportsFetch4( void ) const = 0;
  161. virtual bool CanStretchRectFromTextures( void ) const = 0;
  162. inline bool ShouldAlwaysUseShaderModel2bShaders() const { return IsOpenGL(); }
  163. inline bool PlatformRequiresNonNullPixelShaders() const { return IsOpenGL(); }
  164. };
  165. #endif // IMATERIALSYSTEMHARDWARECONFIG_H