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.

180 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Header: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #ifndef TEXTUREMANAGER_H
  9. #define TEXTUREMANAGER_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "itextureinternal.h"
  14. class ITexture;
  15. class ITextureInternal;
  16. class IVTFTexture;
  17. enum
  18. {
  19. COLOR_CORRECTION_MAX_TEXTURES = 4,
  20. COLOR_CORRECTION_TEXTURE_SIZE = 32
  21. };
  22. class CTextureCompositorTemplate;
  23. //-----------------------------------------------------------------------------
  24. // Texture manager interface
  25. //-----------------------------------------------------------------------------
  26. abstract_class ITextureManager
  27. {
  28. public:
  29. // Initialization + shutdown
  30. virtual void Init( int nFlags ) = 0;
  31. virtual void Shutdown() = 0;
  32. // Allocate, free standard render target textures
  33. virtual void AllocateStandardRenderTargets( ) = 0;
  34. virtual void FreeStandardRenderTargets() = 0;
  35. //Some render targets are managed by code outside of the materialsystem but are used by the materialsystem all the time.
  36. virtual void CacheExternalStandardRenderTargets() = 0;
  37. // Creates a procedural texture
  38. // NOTE: Passing in NULL as a texture name will cause it to not
  39. // be able to be looked up by name using FindOrLoadTexture.
  40. // Also, you may not get a texture with the requested size or format;
  41. // you'll get something close though.
  42. virtual ITextureInternal *CreateProceduralTexture(
  43. const char *pTextureName,
  44. const char *pTextureGroupName,
  45. int w,
  46. int h,
  47. int d,
  48. ImageFormat fmt,
  49. int nFlags,
  50. ITextureRegenerator *generator = NULL) = 0;
  51. // Creates a texture which is a render target
  52. virtual ITextureInternal *CreateRenderTargetTexture(
  53. const char *pRTName, // NULL for auto-generated name
  54. int w,
  55. int h,
  56. RenderTargetSizeMode_t sizeMode,
  57. ImageFormat fmt,
  58. RenderTargetType_t type,
  59. unsigned int textureFlags,
  60. unsigned int renderTargetFlags ) = 0;
  61. // Loads a texture from disk
  62. virtual ITextureInternal *FindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName, int nAdditionalCreationFlags = 0 ) = 0;
  63. // Call this to reset the filtering state
  64. virtual void ResetTextureFilteringState() = 0;
  65. // Reload all textures
  66. virtual void ReloadTextures( void ) = 0;
  67. // These two are used when we lose our video memory due to a mode switch etc
  68. virtual void ReleaseTextures( void ) = 0;
  69. virtual void RestoreRenderTargets( void ) = 0;
  70. virtual void RestoreNonRenderTargetTextures( void ) = 0;
  71. // Suspend or resume texture streaming requests
  72. virtual void SuspendTextureStreaming( void ) = 0;
  73. virtual void ResumeTextureStreaming( void ) = 0;
  74. // delete any texture that has a refcount <= 0
  75. virtual void RemoveUnusedTextures( void ) = 0;
  76. virtual void DebugPrintUsedTextures( void ) = 0;
  77. // Request a texture ID
  78. virtual int RequestNextTextureID() = 0;
  79. // Get at a couple standard textures
  80. virtual ITextureInternal *ErrorTexture() = 0;
  81. virtual ITextureInternal *NormalizationCubemap() = 0;
  82. virtual ITextureInternal *SignedNormalizationCubemap() = 0;
  83. virtual ITextureInternal *ColorCorrectionTexture( int index ) = 0;
  84. virtual ITextureInternal *ShadowNoise2D() = 0;
  85. virtual ITextureInternal *IdentityLightWarp() = 0;
  86. virtual ITextureInternal *FullFrameDepthTexture() = 0;
  87. virtual ITextureInternal *DebugLuxels2D() = 0;
  88. // Generates an error texture pattern
  89. virtual void GenerateErrorTexture( ITexture *pTexture, IVTFTexture *pVTFTexture ) = 0;
  90. // Updates the color correction state
  91. virtual void SetColorCorrectionTexture( int i, ITextureInternal *pTexture ) = 0;
  92. virtual void ForceAllTexturesIntoHardware( void ) = 0;
  93. virtual bool IsTextureLoaded( const char *pTextureName ) = 0;
  94. // Mark a texture as now-unreferenced, so it can be checked for removal at a later (and thread-safe) time.
  95. virtual void MarkUnreferencedTextureForCleanup( ITextureInternal *pTexture ) = 0;
  96. virtual void RemoveTexture( ITextureInternal *pTexture ) = 0;
  97. // start with -1, list terminates with -1
  98. virtual int FindNext( int iIndex, ITextureInternal **ppTexture ) = 0;
  99. virtual void AddTextureAlias( const char *pAlias, const char *pRealName ) = 0;
  100. virtual void RemoveTextureAlias( const char *pAlias ) = 0;
  101. virtual void SetExcludedTextures( const char *pScriptName ) = 0;
  102. virtual void UpdateExcludedTextures( void ) = 0;
  103. //Releases texture memory bits for temporary render targets, does NOT destroy the CTexture entirely
  104. virtual void ReleaseTempRenderTargetBits( void ) = 0;
  105. // See CL_HandlePureServerWhitelist for a description of the pure server stuff.
  106. virtual void ReloadFilesInList( IFileList *pFilesToReload ) = 0;
  107. // Called once per frame by material system "somewhere."
  108. virtual void Update( ) = 0;
  109. // Load a texture asynchronously and then call the provided callback.
  110. virtual void AsyncFindOrLoadTexture( const char *pTextureName, const char *pTextureGroupName, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs, bool bComplain, int nAdditionalCreationFlags ) = 0;
  111. // Stream a render target back to system memory, perform format conversion to the specified destination format,
  112. virtual void AsyncCreateTextureFromRenderTarget( ITexture* pSrcRt, const char* pDstName, ImageFormat dstFmt, bool bGenMips, int nAdditionalCreationFlags, IAsyncTextureOperationReceiver* pRecipient, void* pExtraArgs ) = 0;
  113. virtual void WarmTextureCache() = 0;
  114. virtual void CoolTextureCache() = 0;
  115. virtual void RequestAllMipmaps( ITextureInternal* pTex ) = 0;
  116. virtual void EvictAllTextures() = 0;
  117. virtual void UpdatePostAsync() = 0;
  118. virtual void ReleaseAsyncScratchVTF( IVTFTexture* pScratchVTF ) = 0;
  119. virtual bool ThreadInAsyncLoadThread() const = 0;
  120. virtual bool ThreadInAsyncReadThread() const = 0;
  121. virtual bool HasPendingTextureDestroys() const = 0;
  122. virtual bool AddTextureCompositorTemplate( const char* pName, KeyValues* pTmplDesc ) = 0;
  123. virtual bool VerifyTextureCompositorTemplates() = 0;
  124. virtual CTextureCompositorTemplate* FindTextureCompositorTemplate( const char* pName ) = 0;
  125. };
  126. //-----------------------------------------------------------------------------
  127. // Singleton instance
  128. //-----------------------------------------------------------------------------
  129. inline ITextureManager *TextureManager()
  130. {
  131. extern ITextureManager *g_pTextureManager;
  132. return g_pTextureManager;
  133. }
  134. #endif // TEXTUREMANAGER_H