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.

110 lines
3.6 KiB

  1. //========= Copyright (c) 1996-2005, 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. SHADER_PARAM( RELOADZCULL, SHADER_PARAM_TYPE_INTEGER, "0", "special shader to reload Zcull memory on ps3" )
  19. END_SHADER_PARAMS
  20. SHADER_INIT_PARAMS()
  21. {
  22. }
  23. SHADER_FALLBACK
  24. {
  25. return 0;
  26. }
  27. SHADER_INIT
  28. {
  29. if ( !params[CLEARALPHA]->IsDefined() )
  30. {
  31. params[CLEARALPHA]->SetIntValue( -1 );
  32. }
  33. }
  34. SHADER_DRAW
  35. {
  36. bool bEnableColorWrites = params[CLEARCOLOR]->GetIntValue() != 0;
  37. bool bEnableAlphaWrites = (params[CLEARALPHA]->GetIntValue() >= 0) ? (params[CLEARALPHA]->GetIntValue() != 0) : bEnableColorWrites;
  38. bool bUsesColor = bEnableColorWrites || bEnableAlphaWrites;
  39. bool bReloadZcull = ( IsPS3() && params[RELOADZCULL]->GetIntValue() != 0 ) ? true : false;
  40. SHADOW_STATE
  41. {
  42. pShaderShadow->DepthFunc( bReloadZcull ? SHADER_DEPTHFUNC_NEARER : 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 );
  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_COMBO( RELOADZCULL, bReloadZcull );
  58. SET_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
  59. }
  60. else
  61. {
  62. DECLARE_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
  63. SET_STATIC_PIXEL_SHADER_COMBO( RELOADZCULL, bReloadZcull );
  64. SET_STATIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
  65. }
  66. }
  67. }
  68. DYNAMIC_STATE
  69. {
  70. DECLARE_DYNAMIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
  71. SET_DYNAMIC_VERTEX_SHADER( bufferclearobeystencil_vs20 );
  72. //avoid setting a pixel shader when only doing depth/stencil operations, as recommended by PIX
  73. if( bUsesColor || g_pHardwareConfig->PlatformRequiresNonNullPixelShaders() )
  74. {
  75. if( g_pHardwareConfig->SupportsPixelShaders_2_b() )
  76. {
  77. DECLARE_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
  78. SET_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20b );
  79. }
  80. else
  81. {
  82. DECLARE_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
  83. SET_DYNAMIC_PIXEL_SHADER( bufferclearobeystencil_ps20 );
  84. }
  85. }
  86. }
  87. Draw( );
  88. }
  89. END_SHADER