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.

131 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ISHADERUTIL_H
  9. #define ISHADERUTIL_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "materialsystem/imaterial.h"
  14. #include "appframework/IAppSystem.h"
  15. #include "shaderapi/ishaderapi.h"
  16. //-----------------------------------------------------------------------------
  17. // forward declarations
  18. //-----------------------------------------------------------------------------
  19. class ITexture;
  20. struct MaterialSystem_Config_t;
  21. struct ImageFormatInfo_t;
  22. enum Sampler_t;
  23. enum VertexTextureSampler_t;
  24. enum StandardTextureId_t;
  25. class CPrimList;
  26. struct ShaderColorCorrectionInfo_t;
  27. #define SHADER_UTIL_INTERFACE_VERSION "VShaderUtil001"
  28. enum shaderthreadevent_t
  29. {
  30. SHADER_THREAD_RELEASE_RESOURCES = 1,
  31. SHADER_THREAD_ACQUIRE_RESOURCES = 2,
  32. SHADER_THREAD_DEVICE_LOST = 3,
  33. SHADER_THREAD_EVICT_RESOURCES = 4,
  34. SHADER_THREAD_OTHER_APP_START = 5,
  35. SHADER_THREAD_OTHER_APP_END = 6,
  36. SHADER_THREAD_RESET_RENDER_STATE = 7,
  37. };
  38. abstract_class IShaderUtil : public IAppSystem
  39. {
  40. public:
  41. // Method to allow clients access to the MaterialSystem_Config
  42. virtual MaterialSystem_Config_t& GetConfig() = 0;
  43. // Allows us to convert image formats
  44. virtual bool ConvertImageFormat( unsigned char *src, enum ImageFormat srcImageFormat,
  45. unsigned char *dst, enum ImageFormat dstImageFormat,
  46. int width, int height, int srcStride = 0, int dstStride = 0 ) = 0;
  47. // Figures out the amount of memory needed by a bitmap
  48. virtual int GetMemRequired( int width, int height, int depth, ImageFormat format, bool mipmap ) = 0;
  49. // Gets image format info
  50. virtual const ImageFormatInfo_t& ImageFormatInfo( ImageFormat fmt ) const = 0;
  51. // Bind standard textures
  52. virtual void BindStandardTexture( Sampler_t sampler, StandardTextureId_t id ) = 0;
  53. // What are the lightmap dimensions?
  54. virtual void GetLightmapDimensions( int *w, int *h ) = 0;
  55. // These methods are called when the shader must eject + restore HW memory
  56. virtual void ReleaseShaderObjects() = 0;
  57. virtual void RestoreShaderObjects( CreateInterfaceFn shaderFactory, int nChangeFlags = 0 ) = 0;
  58. // Used to prevent meshes from drawing.
  59. virtual bool IsInStubMode() = 0;
  60. virtual bool InFlashlightMode() const = 0;
  61. // For the shader API to shove the current version of aniso level into the
  62. // "definitive" place (g_config) when the shader API decides to change it.
  63. // Eventually, we should have a better system of who owns the definitive
  64. // versions of config vars.
  65. virtual void NoteAnisotropicLevel( int currentLevel ) = 0;
  66. // NOTE: Stuff after this is added after shipping HL2.
  67. // Are we rendering through the editor?
  68. virtual bool InEditorMode() const = 0;
  69. // Gets the bound morph's vertex format; returns 0 if no morph is bound
  70. virtual MorphFormat_t GetBoundMorphFormat() = 0;
  71. virtual ITexture *GetRenderTargetEx( int nRenderTargetID ) = 0;
  72. // Tells the material system to draw a buffer clearing quad
  73. virtual void DrawClearBufferQuad( unsigned char r, unsigned char g, unsigned char b, unsigned char a, bool bClearColor, bool bClearAlpha, bool bClearDepth ) = 0;
  74. #if defined( _X360 )
  75. virtual void ReadBackBuffer( Rect_t *pSrcRect, Rect_t *pDstRect, unsigned char *pData, ImageFormat dstFormat, int nDstStride ) = 0;
  76. #endif
  77. // Calls from meshes to material system to handle queing/threading
  78. virtual bool OnDrawMesh( IMesh *pMesh, int firstIndex, int numIndices ) = 0;
  79. virtual bool OnDrawMesh( IMesh *pMesh, CPrimList *pLists, int nLists ) = 0;
  80. virtual bool OnSetFlexMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) = 0;
  81. virtual bool OnSetColorMesh( IMesh *pStaticMesh, IMesh *pMesh, int nVertexOffsetInBytes ) = 0;
  82. virtual bool OnSetPrimitiveType( IMesh *pMesh, MaterialPrimitiveType_t type ) = 0;
  83. virtual bool OnFlushBufferedPrimitives() = 0;
  84. virtual void SyncMatrices() = 0;
  85. virtual void SyncMatrix( MaterialMatrixMode_t ) = 0;
  86. virtual void BindStandardVertexTexture( VertexTextureSampler_t sampler, StandardTextureId_t id ) = 0;
  87. virtual void GetStandardTextureDimensions( int *pWidth, int *pHeight, StandardTextureId_t id ) = 0;
  88. virtual int MaxHWMorphBatchCount() const = 0;
  89. // Interface for mat system to tell shaderapi about color correction
  90. virtual void GetCurrentColorCorrection( ShaderColorCorrectionInfo_t* pInfo ) = 0;
  91. // received an event while not in owning thread, handle this outside
  92. virtual void OnThreadEvent( uint32 threadEvent ) = 0;
  93. virtual MaterialThreadMode_t GetThreadMode( ) = 0;
  94. virtual bool IsRenderThreadSafe( ) = 0;
  95. // Remove any materials from memory that aren't in use as determined
  96. // by the IMaterial's reference count.
  97. virtual void UncacheUnusedMaterials( bool bRecomputeStateSnapshots = false ) = 0;
  98. };
  99. #endif // ISHADERUTIL_H