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.

176 lines
5.1 KiB

  1. //===== Copyright � 1996-2005, 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. class Vector;
  16. enum Sampler_t;
  17. class IFileList;
  18. enum RenderTargetType_t
  19. {
  20. NO_RENDER_TARGET = 0,
  21. // GR - using shared depth buffer
  22. RENDER_TARGET = 1,
  23. // GR - using own depth buffer
  24. RENDER_TARGET_WITH_DEPTH = 2,
  25. // GR - no depth buffer
  26. RENDER_TARGET_NO_DEPTH = 3,
  27. // only cares about depth buffer
  28. RENDER_TARGET_ONLY_DEPTH = 4,
  29. };
  30. abstract_class ITextureInternal : public ITexture
  31. {
  32. public:
  33. virtual void Bind( Sampler_t sampler, TextureBindFlags_t nBindFlags ) = 0;
  34. virtual void Bind( Sampler_t sampler1, TextureBindFlags_t nBindFlags, int nFrame, Sampler_t sampler2 = SHADER_SAMPLER_INVALID ) = 0;
  35. virtual void GetReflectivity( Vector& reflectivity ) = 0;
  36. // Set this as the render target, return false for failure
  37. virtual bool SetRenderTarget( int nRenderTargetID ) = 0;
  38. // Releases the texture's hw memory
  39. virtual void Release() = 0;
  40. // Called before Download() on restore. Gives render targets a change to change whether or
  41. // not they force themselves to have a separate depth buffer due to AA.
  42. virtual void OnRestore() = 0;
  43. // Resets the texture's filtering and clamping mode
  44. virtual void SetFilteringAndClampingMode() = 0;
  45. // Used by tools.... loads up the non-fallback information about the texture
  46. virtual void Precache() = 0;
  47. // Stretch blit the framebuffer into this texture.
  48. virtual void CopyFrameBufferToMe( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
  49. virtual void CopyMeToFrameBuffer( int nRenderTargetID = 0, Rect_t *pSrcRect = NULL, Rect_t *pDstRect = NULL ) = 0;
  50. virtual ITexture *GetEmbeddedTexture( int nIndex ) = 0;
  51. // Get the shaderapi texture handle associated w/ a particular frame
  52. virtual ShaderAPITextureHandle_t GetTextureHandle( int nFrame, int nTextureChannel =0 ) = 0;
  53. virtual ~ITextureInternal()
  54. {
  55. }
  56. virtual ImageFormat GetImageFormat() const = 0;
  57. // Creates a new texture
  58. static ITextureInternal *CreateFileTexture( const char *pFileName, const char *pTextureGroupName );
  59. static ITextureInternal *CreateProceduralTexture(
  60. const char *pTextureName,
  61. const char *pTextureGroupName,
  62. int w,
  63. int h,
  64. int d,
  65. ImageFormat fmt,
  66. int nFlags );
  67. static ITextureInternal *CreateRenderTarget(
  68. const char *pRTName, // NULL for an auto-generated name.
  69. int w,
  70. int h,
  71. RenderTargetSizeMode_t sizeMode,
  72. ImageFormat fmt,
  73. RenderTargetType_t type,
  74. unsigned int textureFlags,
  75. unsigned int renderTargetFlags,
  76. bool bMultipleTargets );
  77. static void ChangeRenderTarget(
  78. ITextureInternal *pTexture,
  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 ITextureInternal *CreateReferenceTextureFromHandle(
  87. const char *pTextureName,
  88. const char *pTextureGroupName,
  89. ShaderAPITextureHandle_t hTexture );
  90. static void Destroy( ITextureInternal *pTexture );
  91. // Set this as the render target, return false for failure
  92. virtual bool SetRenderTarget( int nRenderTargetID, ITexture* pDepthTexture ) = 0;
  93. // Bind this to a vertex texture sampler
  94. virtual void BindVertexTexture( VertexTextureSampler_t sampler, int frameNum = 0 ) = 0;
  95. virtual void MarkAsPreloaded( bool bSet ) = 0;
  96. virtual bool IsPreloaded() const = 0;
  97. virtual void MarkAsExcluded( bool bSet, int nDimensionsLimit, bool bMarkAsTrumpedExclude = false ) = 0;
  98. virtual bool UpdateExcludedState() = 0;
  99. virtual bool IsTempRenderTarget( void ) const = 0;
  100. // Reload any files the texture is responsible for.
  101. virtual void ReloadFilesInList( IFileList *pFilesToReload ) = 0;
  102. virtual bool IsMultiRenderTarget( void ) = 0;
  103. #ifdef _PS3
  104. virtual void Ps3gcmRawBufferAlias( char const *pRTName ) = 0;
  105. #endif
  106. virtual bool MarkAsTempExcluded( bool bSet, int nExcludedDimensionLimit ) = 0;
  107. virtual bool IsForceExcluded() const = 0;
  108. virtual bool ClearForceExclusion() = 0;
  109. virtual bool IsAsyncDone() const = 0;
  110. };
  111. inline bool IsTextureInternalEnvCubemap( const ITextureInternal *pTexture )
  112. {
  113. return ( pTexture == ( ITextureInternal * )-1 );
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Ensures that caller provided names are consistent to the dictionary
  117. //-----------------------------------------------------------------------------
  118. inline char *NormalizeTextureName( const char *pName, char *pOutName, int nOutNameSize )
  119. {
  120. // hdr textures have an ldr version and need to resolve correctly
  121. int nLen = Q_strlen( pName ) + 1;
  122. if ( nLen <= 5 || Q_stricmp( pName + nLen - 5, ".hdr" ) )
  123. {
  124. // strip any non .hdr extension
  125. Q_StripExtension( pName, pOutName, nOutNameSize );
  126. }
  127. else
  128. {
  129. // keep .hdr extension
  130. Q_strncpy( pOutName, pName, nOutNameSize );
  131. }
  132. Q_strlower( pOutName );
  133. Q_FixSlashes( pOutName, '/' );
  134. return pOutName;
  135. }
  136. #endif // ITEXTUREINTERNAL_H