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.

190 lines
5.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ITEXTUREINTERNAL_H
  9. #define ITEXTUREINTERNAL_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "materialsystem/itexture.h"
  14. #include "shaderapi/ishaderapi.h"
  15. #include "tier1/utlmap.h"
  16. class Vector;
  17. enum Sampler_t;
  18. class IFileList;
  19. enum RenderTargetType_t
  20. {
  21. NO_RENDER_TARGET = 0,
  22. // GR - using shared depth buffer
  23. RENDER_TARGET = 1,
  24. // GR - using own depth buffer
  25. RENDER_TARGET_WITH_DEPTH = 2,
  26. // GR - no depth buffer
  27. RENDER_TARGET_NO_DEPTH = 3,
  28. // only cares about depth buffer
  29. RENDER_TARGET_ONLY_DEPTH = 4,
  30. };
  31. enum ResidencyType_t
  32. {
  33. RESIDENT_NONE,
  34. RESIDENT_PARTIAL,
  35. RESIDENT_FULL
  36. };
  37. abstract_class ITextureInternal : public ITexture
  38. {
  39. public:
  40. virtual void Bind( Sampler_t sampler ) = 0;
  41. virtual void Bind( Sampler_t sampler1, int nFrame, Sampler_t sampler2 = (Sampler_t) -1 ) = 0;
  42. // Methods associated with reference counting
  43. virtual int GetReferenceCount() = 0;
  44. virtual void GetReflectivity( Vector& reflectivity ) = 0;
  45. // Set this as the render target, return false for failure
  46. virtual bool SetRenderTarget( int nRenderTargetID ) = 0;
  47. // Releases the texture's hw memory
  48. virtual void ReleaseMemory() = 0;
  49. // Called before Download() on restore. Gives render targets a change to change whether or
  50. // not they force themselves to have a separate depth buffer due to AA.
  51. virtual void OnRestore() = 0;
  52. // Resets the texture's filtering and clamping mode
  53. virtual void SetFilteringAndClampingMode( bool bOnlyLodValues = false ) = 0;
  54. // Used by tools.... loads up the non-fallback information about the texture
  55. virtual void Precache() = 0;
  56. // Stretch blit the framebuffer into this texture.
  57. virtual void CopyFrameBufferToMe( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
  58. virtual void CopyMeToFrameBuffer( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
  59. virtual ITexture *GetEmbeddedTexture( int nIndex ) = 0;
  60. // Get the shaderapi texture handle associated w/ a particular frame
  61. virtual ShaderAPITextureHandle_t GetTextureHandle( int nFrame, int nTextureChannel =0 ) = 0;
  62. virtual ~ITextureInternal()
  63. {
  64. }
  65. virtual ImageFormat GetImageFormat() const = 0;
  66. // Creates a new texture
  67. static ITextureInternal *CreateFileTexture( const char *pFileName, const char *pTextureGroupName );
  68. static ITextureInternal *CreateProceduralTexture(
  69. const char *pTextureName,
  70. const char *pTextureGroupName,
  71. int w,
  72. int h,
  73. int d,
  74. ImageFormat fmt,
  75. int nFlags,
  76. ITextureRegenerator *generator = NULL);
  77. static ITextureInternal *CreateRenderTarget(
  78. const char *pRTName, // NULL for an auto-generated name.
  79. int w,
  80. int h,
  81. RenderTargetSizeMode_t sizeMode,
  82. ImageFormat fmt,
  83. RenderTargetType_t type,
  84. unsigned int textureFlags,
  85. unsigned int renderTargetFlags );
  86. static void ChangeRenderTarget(
  87. ITextureInternal *pTexture,
  88. int w,
  89. int h,
  90. RenderTargetSizeMode_t sizeMode,
  91. ImageFormat fmt,
  92. RenderTargetType_t type,
  93. unsigned int textureFlags,
  94. unsigned int renderTargetFlags );
  95. static ITextureInternal *CreateReferenceTextureFromHandle(
  96. const char *pTextureName,
  97. const char *pTextureGroupName,
  98. ShaderAPITextureHandle_t hTexture );
  99. static void Destroy( ITextureInternal *pTexture, bool bSkipTexMgrCheck = false );
  100. // Set this as the render target, return false for failure
  101. virtual bool SetRenderTarget( int nRenderTargetID, ITexture* pDepthTexture ) = 0;
  102. // Bind this to a vertex texture sampler
  103. virtual void BindVertexTexture( VertexTextureSampler_t sampler, int frameNum = 0 ) = 0;
  104. virtual void MarkAsPreloaded( bool bSet ) = 0;
  105. virtual bool IsPreloaded() const = 0;
  106. virtual void MarkAsExcluded( bool bSet, int nDimensionsLimit ) = 0;
  107. virtual bool UpdateExcludedState( void ) = 0;
  108. virtual bool IsTempRenderTarget( void ) const = 0;
  109. // Reload any files the texture is responsible for.
  110. virtual void ReloadFilesInList( IFileList *pFilesToReload ) = 0;
  111. virtual bool AsyncReadTextureFromFile( IVTFTexture* pVTFTexture, unsigned int nAdditionalCreationFlags ) = 0;
  112. virtual void AsyncCancelReadTexture() = 0;
  113. // Map and unmap. These can fail. And can cause a very significant perf penalty. Be very careful with them.
  114. virtual void Map( void** pOutDst, int* pOutPitch ) = 0;
  115. virtual void Unmap() = 0;
  116. // Texture streaming!
  117. virtual ResidencyType_t GetCurrentResidence() const = 0;
  118. virtual ResidencyType_t GetTargetResidence() const = 0;
  119. virtual bool MakeResident( ResidencyType_t newResidence ) = 0;
  120. virtual void UpdateLodBias() = 0;
  121. };
  122. inline bool IsTextureInternalEnvCubemap( const ITextureInternal *pTexture )
  123. {
  124. return ( pTexture == ( ITextureInternal * )-1 );
  125. }
  126. //-----------------------------------------------------------------------------
  127. // Ensures that caller provided names are consistent to the dictionary
  128. //-----------------------------------------------------------------------------
  129. inline char *NormalizeTextureName( const char *pName, char *pOutName, int nOutNameSize )
  130. {
  131. // hdr textures have an ldr version and need to resolve correctly
  132. int nLen = Q_strlen( pName ) + 1;
  133. if ( nLen <= 5 || Q_stricmp( pName + nLen - 5, ".hdr" ) )
  134. {
  135. // strip any non .hdr extension
  136. Q_StripExtension( pName, pOutName, nOutNameSize );
  137. }
  138. else
  139. {
  140. // keep .hdr extension
  141. Q_strncpy( pOutName, pName, nOutNameSize );
  142. }
  143. Q_strlower( pOutName );
  144. Q_FixSlashes( pOutName, '/' );
  145. return pOutName;
  146. }
  147. extern ConVar mat_texture_tracking;
  148. extern CUtlMap<ITexture*, CInterlockedInt> *g_pTextureRefList;
  149. #endif // ITEXTUREINTERNAL_H