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.

135 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef VERTEXSHADERDX8_H
  9. #define VERTEXSHADERDX8_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "shaderapi/ishaderapi.h"
  14. #include "locald3dtypes.h"
  15. // uncomment to get dynamic compilation for HLSL shaders
  16. // X360 NOTE: By default, the system looks for a shared folder named "stdshaders" on the host machine and is completely compatible with -dvd. Ensure that the share is writable if you plan on generating UPDB's.
  17. //#define DYNAMIC_SHADER_COMPILE
  18. // Uncomment to use remoteshadercompiler.exe as a shader compile server
  19. // Must also set mat_remoteshadercompile to remote shader compile machine name
  20. //#define REMOTE_DYNAMIC_SHADER_COMPILE
  21. // uncomment to get spew about what combos are being compiled.
  22. //#define DYNAMIC_SHADER_COMPILE_VERBOSE
  23. // Uncomment to use remoteshadercompiler.exe as a shader compile server
  24. // Must also set mat_remoteshadercompile to remote shader compile machine name
  25. //#define REMOTE_DYNAMIC_SHADER_COMPILE
  26. // uncomment and fill in with a path to use a specific set of shader source files. Meant for network use.
  27. // PC path format is of style "\\\\somemachine\\sourcetreeshare\\materialsystem\\stdshaders"
  28. // Xbox path format is of style "net:\\smb\\somemachine\\sourcetreeshare\\materialsystem\\stdshaders"
  29. // - Xbox dynamic compiles without a custom path default to look directly for "stdshaders" share on host pc
  30. //#define DYNAMIC_SHADER_COMPILE_CUSTOM_PATH ""
  31. // uncomment to get disassembled (asm) shader code in your game dir as *.asm
  32. //#define DYNAMIC_SHADER_COMPILE_WRITE_ASSEMBLY
  33. // uncomment to get disassembled (asm) shader code in your game dir as *.asm
  34. //#define WRITE_ASSEMBLY
  35. enum VertexShaderLightTypes_t
  36. {
  37. LIGHT_NONE = -1,
  38. LIGHT_SPOT = 0,
  39. LIGHT_POINT = 1,
  40. LIGHT_DIRECTIONAL = 2,
  41. LIGHT_STATIC = 3,
  42. LIGHT_AMBIENTCUBE = 4,
  43. };
  44. //-----------------------------------------------------------------------------
  45. // Vertex + pixel shader manager
  46. //-----------------------------------------------------------------------------
  47. abstract_class IShaderManager
  48. {
  49. protected:
  50. // The current vertex and pixel shader index
  51. int m_nVertexShaderIndex;
  52. int m_nPixelShaderIndex;
  53. public:
  54. // Initialize, shutdown
  55. virtual void Init() = 0;
  56. virtual void Shutdown() = 0;
  57. // Compiles vertex shaders
  58. virtual IShaderBuffer *CompileShader( const char *pProgram, size_t nBufLen, const char *pShaderVersion ) = 0;
  59. // New version of these methods [dx10 port]
  60. virtual VertexShaderHandle_t CreateVertexShader( IShaderBuffer* pShaderBuffer ) = 0;
  61. virtual void DestroyVertexShader( VertexShaderHandle_t hShader ) = 0;
  62. virtual PixelShaderHandle_t CreatePixelShader( IShaderBuffer* pShaderBuffer ) = 0;
  63. virtual void DestroyPixelShader( PixelShaderHandle_t hShader ) = 0;
  64. // Creates vertex, pixel shaders
  65. virtual VertexShader_t CreateVertexShader( const char *pVertexShaderFile, int nStaticVshIndex = 0, char *debugLabel = NULL ) = 0;
  66. virtual PixelShader_t CreatePixelShader( const char *pPixelShaderFile, int nStaticPshIndex = 0, char *debugLabel = NULL ) = 0;
  67. // Sets which dynamic version of the vertex + pixel shader to use
  68. FORCEINLINE void SetVertexShaderIndex( int vshIndex );
  69. FORCEINLINE void SetPixelShaderIndex( int pshIndex );
  70. // Sets the vertex + pixel shader render state
  71. virtual void SetVertexShader( VertexShader_t shader ) = 0;
  72. virtual void SetPixelShader( PixelShader_t shader ) = 0;
  73. // Resets the vertex + pixel shader state
  74. virtual void ResetShaderState() = 0;
  75. // Returns the current vertex + pixel shaders
  76. virtual void *GetCurrentVertexShader() = 0;
  77. virtual void *GetCurrentPixelShader() = 0;
  78. virtual void ClearVertexAndPixelShaderRefCounts() = 0;
  79. virtual void PurgeUnusedVertexAndPixelShaders() = 0;
  80. // The low-level dx call to set the vertex shader state
  81. virtual void BindVertexShader( VertexShaderHandle_t shader ) = 0;
  82. virtual void BindPixelShader( PixelShaderHandle_t shader ) = 0;
  83. #if defined( _X360 )
  84. virtual const char *GetActiveVertexShaderName() = 0;
  85. virtual const char *GetActivePixelShaderName() = 0;
  86. #endif
  87. #if defined( DX_TO_GL_ABSTRACTION )
  88. virtual void DoStartupShaderPreloading() = 0;
  89. #endif
  90. };
  91. //-----------------------------------------------------------------------------
  92. //
  93. // Methods related to setting vertex + pixel shader state
  94. //
  95. //-----------------------------------------------------------------------------
  96. FORCEINLINE void IShaderManager::SetVertexShaderIndex( int vshIndex )
  97. {
  98. m_nVertexShaderIndex = vshIndex;
  99. }
  100. FORCEINLINE void IShaderManager::SetPixelShaderIndex( int pshIndex )
  101. {
  102. m_nPixelShaderIndex = pshIndex;
  103. }
  104. #endif // VERTEXSHADERDX8_H