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.

195 lines
5.0 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef SHADERSHADOWDX8_H
  9. #define SHADERSHADOWDX8_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "togl/rendermechanism.h"
  14. #include "locald3dtypes.h"
  15. #include "shaderapi/ishadershadow.h"
  16. class IShaderAPIDX8;
  17. //-----------------------------------------------------------------------------
  18. // Important enumerations
  19. //-----------------------------------------------------------------------------
  20. enum
  21. {
  22. MAX_SAMPLERS = 16,
  23. MAX_VERTEX_SAMPLERS = 4,
  24. };
  25. //-----------------------------------------------------------------------------
  26. // A structure maintaining the shadowed board state
  27. //-----------------------------------------------------------------------------
  28. struct SamplerShadowState_t
  29. {
  30. bool m_TextureEnable : 1;
  31. bool m_SRGBReadEnable : 1;
  32. bool m_Fetch4Enable : 1;
  33. #if ( defined ( POSIX ) )
  34. bool m_ShadowFilterEnable : 1;
  35. #endif
  36. };
  37. struct DepthTestState_t
  38. {
  39. // assumes D3DCMPFUNC and D3DZBUFFER TYPE fit in a byte
  40. uint8 m_ZFunc;
  41. uint8 m_ZEnable;
  42. uint8 m_ColorWriteEnable;
  43. unsigned char m_ZWriteEnable:1;
  44. unsigned char m_ZBias:2;
  45. typedef uint32 UIntAlias;
  46. FORCEINLINE void Check( void ) const { COMPILE_TIME_ASSERT( sizeof( *this ) == sizeof( UIntAlias ) ); }
  47. };
  48. struct AlphaTestAndMiscState_t
  49. {
  50. uint8 m_AlphaFunc;
  51. uint8 m_AlphaRef;
  52. // Fill mode
  53. uint8 m_FillMode;
  54. unsigned char m_AlphaTestEnable:1;
  55. unsigned char m_EnableAlphaToCoverage:1;
  56. // Cull State?
  57. unsigned char m_CullEnable:1;
  58. typedef uint32 UIntAlias;
  59. FORCEINLINE void Check( void ) const { COMPILE_TIME_ASSERT( sizeof( *this ) == sizeof( UIntAlias ) ); }
  60. };
  61. struct FogAndMiscState_t
  62. {
  63. uint8 m_FogMode;
  64. unsigned char m_bVertexFogEnable:1;
  65. unsigned char m_bDisableFogGammaCorrection:1;
  66. // Auto-convert from linear to gamma upon writing to the frame buffer?
  67. unsigned char m_SRGBWriteEnable:1;
  68. typedef uint16 UIntAlias;
  69. FORCEINLINE ShaderFogMode_t FogMode( void ) const { return ( ShaderFogMode_t ) m_FogMode; }
  70. FORCEINLINE void Check( void ) const { COMPILE_TIME_ASSERT( sizeof( *this ) == sizeof( UIntAlias ) ); }
  71. };
  72. struct AlphaBlendState_t
  73. {
  74. // Alpha state
  75. uint8 m_SrcBlend;
  76. uint8 m_DestBlend;
  77. uint8 m_BlendOp;
  78. // Separate alpha blend state
  79. uint8 m_SrcBlendAlpha;
  80. uint8 m_DestBlendAlpha;
  81. uint8 m_BlendOpAlpha;
  82. unsigned char m_AlphaBlendEnable:1;
  83. unsigned char m_AlphaBlendEnabledForceOpaque:1; // alpha blending enabled for this batch, but return false for IsTranslucent() so object can be rendered with opaques
  84. // Seperate Alpha Blend?
  85. unsigned char m_SeparateAlphaBlendEnable:1;
  86. uint8 m_nPad00;
  87. typedef uint64 UIntAlias;
  88. FORCEINLINE void Check( void ) const { COMPILE_TIME_ASSERT( sizeof( *this ) == sizeof( UIntAlias ) ); }
  89. };
  90. struct ShadowState_t
  91. {
  92. // Depth buffering state
  93. union
  94. {
  95. DepthTestState_t m_DepthTestState;
  96. DepthTestState_t::UIntAlias m_nDepthTestStateAsInt;
  97. };
  98. union
  99. {
  100. AlphaTestAndMiscState_t m_AlphaTestAndMiscState;
  101. AlphaTestAndMiscState_t::UIntAlias m_nAlphaTestAndMiscStateAsInt;
  102. };
  103. union
  104. {
  105. FogAndMiscState_t m_FogAndMiscState;
  106. FogAndMiscState_t::UIntAlias m_nFogAndMiscStateAsInt;
  107. };
  108. union
  109. {
  110. AlphaBlendState_t m_AlphaBlendState;
  111. AlphaBlendState_t::UIntAlias m_nAlphaBlendStateAsInt;
  112. };
  113. // Sampler state. encoded as ints so we can do mask operations for fast change detection
  114. uint32 m_nFetch4Enable;
  115. #if ( defined ( PLATFORM_OPENGL ) )
  116. uint32 m_nShadowFilterEnable;
  117. #endif
  118. };
  119. //-----------------------------------------------------------------------------
  120. // These are part of the "shadow" since they describe the shading algorithm
  121. // but aren't actually captured in the state transition table
  122. // because it would produce too many transitions
  123. //-----------------------------------------------------------------------------
  124. struct ShadowShaderState_t
  125. {
  126. // The vertex + pixel shader group to use...
  127. VertexShader_t m_VertexShader;
  128. PixelShader_t m_PixelShader;
  129. // The static vertex + pixel shader indices
  130. int m_nStaticVshIndex;
  131. int m_nStaticPshIndex;
  132. // Vertex data used by this snapshot
  133. // Note that the vertex format actually used will be the
  134. // aggregate of the vertex formats used by all snapshots in a material
  135. VertexFormat_t m_VertexUsage;
  136. };
  137. //-----------------------------------------------------------------------------
  138. // The shader setup API
  139. //-----------------------------------------------------------------------------
  140. abstract_class IShaderShadowDX8 : public IShaderShadow
  141. {
  142. public:
  143. // Initializes it
  144. virtual void Init() = 0;
  145. // Gets at the shadow state
  146. virtual ShadowState_t const& GetShadowState() = 0;
  147. virtual ShadowShaderState_t const& GetShadowShaderState() = 0;
  148. // This must be called right before taking a snapshot
  149. virtual void ComputeAggregateShadowState( ) = 0;
  150. // Class factory methods
  151. static IShaderShadowDX8* Create( IShaderAPIDX8* pShaderAPIDX8 );
  152. static void Destroy( IShaderShadowDX8* pShaderShadow );
  153. };
  154. extern IShaderShadowDX8 *g_pShaderShadowDx8;
  155. #endif // SHADERSHADOWDX8_H