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.

112 lines
3.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Clears color/depth, but obeys stencil while doing so
  4. //
  5. //=============================================================================//
  6. #include "BaseVSShader.h"
  7. #include "bufferclearobeystencil_vs20.inc"
  8. #include "bufferclearobeystencil_ps20.inc"
  9. #include "bufferclearobeystencil_ps20b.inc"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include "tier0/memdbgon.h"
  12. DEFINE_FALLBACK_SHADER( BufferClearObeyStencil, BufferClearObeyStencil_DX9 )
  13. BEGIN_VS_SHADER_FLAGS( BufferClearObeyStencil_DX9, "", SHADER_NOT_EDITABLE )
  14. BEGIN_SHADER_PARAMS
  15. SHADER_PARAM( CLEARCOLOR, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of color" )
  16. SHADER_PARAM( CLEARALPHA, SHADER_PARAM_TYPE_INTEGER, "-1", "activates clearing of alpha. -1 == copy CLEARCOLOR setting" )
  17. SHADER_PARAM( CLEARDEPTH, SHADER_PARAM_TYPE_INTEGER, "1", "activates clearing of depth" )
  18. END_SHADER_PARAMS
  19. SHADER_INIT_PARAMS()
  20. {
  21. }
  22. SHADER_FALLBACK
  23. {
  24. if ( g_pHardwareConfig->GetDXSupportLevel() < 90 )
  25. {
  26. return "BufferClearObeyStencil_DX8";
  27. }
  28. return 0;
  29. }
  30. SHADER_INIT
  31. {
  32. if ( !params[CLEARALPHA]->IsDefined() )
  33. params[CLEARALPHA]->SetIntValue( -1 );
  34. }
  35. SHADER_DRAW
  36. {
  37. bool bEnableColorWrites = params[CLEARCOLOR]->GetIntValue() != 0;
  38. bool bEnableAlphaWrites = (params[CLEARALPHA]->GetIntValue() >= 0) ? (params[CLEARALPHA]->GetIntValue() != 0) : bEnableColorWrites;
  39. bool bUsesColor = bEnableColorWrites || bEnableAlphaWrites;
  40. SHADOW_STATE
  41. {
  42. pShaderShadow->DepthFunc( SHADER_DEPTHFUNC_ALWAYS );
  43. bool bEnableDepthWrites = params[CLEARDEPTH]->GetIntValue() != 0;
  44. pShaderShadow->EnableDepthWrites( bEnableDepthWrites );
  45. pShaderShadow->EnableColorWrites( bEnableColorWrites );
  46. pShaderShadow->EnableAlphaWrites( bEnableAlphaWrites );
  47. pShaderShadow->VertexShaderVertexFormat( VERTEX_POSITION | VERTEX_COLOR, 1, NULL, 0 );
  48. DECLARE_STATIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
  49. SET_STATIC_VERTEX_SHADER_COMBO( USESCOLOR, bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() );
  50. SET_STATIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
  51. //avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX
  52. if( bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() )
  53. {
  54. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  55. {
  56. DECLARE_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
  57. SET_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
  58. }
  59. else
  60. {
  61. DECLARE_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
  62. SET_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
  63. }
  64. }
  65. pShaderShadow->EnableBlending( true );
  66. pShaderShadow->BlendFunc( SHADER_BLEND_ONE, SHADER_BLEND_ZERO );
  67. pShaderShadow->EnableAlphaTest( true );
  68. pShaderShadow->AlphaFunc( SHADER_ALPHAFUNC_ALWAYS, 0 );
  69. }
  70. DYNAMIC_STATE
  71. {
  72. DECLARE_DYNAMIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
  73. SET_DYNAMIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
  74. //avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX
  75. if( bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() )
  76. {
  77. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  78. {
  79. DECLARE_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
  80. SET_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
  81. }
  82. else
  83. {
  84. DECLARE_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
  85. SET_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
  86. }
  87. }
  88. }
  89. Draw( );
  90. }
  91. END_SHADER