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.9 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef ITEXTURE_H
  9. #define ITEXTURE_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "tier0/platform.h"
  14. #include "bitmap/imageformat.h" // ImageFormat defn.
  15. #include "materialsystem/imaterialsystem.h"
  16. class IVTFTexture;
  17. class ITexture;
  18. struct Rect_t;
  19. #ifdef _X360
  20. enum RTMultiSampleCount360_t
  21. {
  22. RT_MULTISAMPLE_NONE = 0,
  23. RT_MULTISAMPLE_2_SAMPLES = 2,
  24. RT_MULTISAMPLE_4_SAMPLES = 4,
  25. RT_MULTISAMPLE_MATCH_BACKBUFFER
  26. };
  27. #endif
  28. struct AsyncTextureContext_t
  29. {
  30. ITexture *m_pTexture;
  31. // snapshot at the point of async start
  32. // used to resolve disparity at moment of latent async arrival
  33. unsigned int m_nInternalFlags;
  34. int m_nDesiredTempDimensionLimit;
  35. int m_nActualDimensionLimit;
  36. // Keeps track of the VTF texture in case the shader api texture gets
  37. // created the next frame. Generating the texture from the file can
  38. // then be split in multiple parts across frames.
  39. IVTFTexture *m_pVTFTexture;
  40. };
  41. //-----------------------------------------------------------------------------
  42. // This will get called on procedural textures to re-fill the textures
  43. // with the appropriate bit pattern. Calling Download() will also
  44. // cause this interface to be called. It will also be called upon
  45. // mode switch, or on other occasions where the bits are discarded.
  46. //-----------------------------------------------------------------------------
  47. abstract_class ITextureRegenerator
  48. {
  49. public:
  50. // This will be called when the texture bits need to be regenerated.
  51. // Use the VTFTexture interface, which has been set up with the
  52. // appropriate texture size + format
  53. // The rect specifies which part of the texture needs to be updated
  54. // You can choose to update all of the bits if you prefer
  55. virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect ) = 0;
  56. // This will be called when the regenerator needs to be deleted
  57. // which will happen when the texture is destroyed
  58. virtual void Release() = 0;
  59. virtual bool HasPreallocatedScratchTexture() const { return false; }
  60. virtual IVTFTexture *GetPreallocatedScratchTexture() { return NULL; }
  61. };
  62. abstract_class ITexture
  63. {
  64. public:
  65. // Various texture polling methods
  66. virtual const char *GetName( void ) const = 0;
  67. virtual int GetMappingWidth() const = 0;
  68. virtual int GetMappingHeight() const = 0;
  69. virtual int GetActualWidth() const = 0;
  70. virtual int GetActualHeight() const = 0;
  71. virtual int GetNumAnimationFrames() const = 0;
  72. virtual bool IsTranslucent() const = 0;
  73. virtual bool IsMipmapped() const = 0;
  74. virtual void GetLowResColorSample( float s, float t, float *color ) const = 0;
  75. // Gets texture resource data of the specified type.
  76. // Params:
  77. // eDataType type of resource to retrieve.
  78. // pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined
  79. // Returns:
  80. // pointer to the resource data, or NULL
  81. virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const = 0;
  82. // Methods associated with reference count
  83. virtual void IncrementReferenceCount( void ) = 0;
  84. virtual void DecrementReferenceCount( void ) = 0;
  85. inline void AddRef() { IncrementReferenceCount(); }
  86. inline void Release() { DecrementReferenceCount(); }
  87. // Used to modify the texture bits (procedural textures only)
  88. virtual void SetTextureRegenerator( ITextureRegenerator *pTextureRegen, bool releaseExisting = true ) = 0;
  89. // Reconstruct the texture bits in HW memory
  90. // If rect is not specified, reconstruct all bits, otherwise just
  91. // reconstruct a subrect.
  92. virtual void Download( Rect_t *pRect = 0, int nAdditionalCreationFlags = 0 ) = 0;
  93. // Uses for stats. . .get the approximate size of the texture in it's current format.
  94. virtual int GetApproximateVidMemBytes( void ) const = 0;
  95. // Returns true if the texture data couldn't be loaded.
  96. virtual bool IsError() const = 0;
  97. // NOTE: Stuff after this is added after shipping HL2.
  98. // For volume textures
  99. virtual bool IsVolumeTexture() const = 0;
  100. virtual int GetMappingDepth() const = 0;
  101. virtual int GetActualDepth() const = 0;
  102. virtual ImageFormat GetImageFormat() const = 0;
  103. // Various information about the texture
  104. virtual bool IsRenderTarget() const = 0;
  105. virtual bool IsCubeMap() const = 0;
  106. virtual bool IsNormalMap() const = 0;
  107. virtual bool IsProcedural() const = 0;
  108. virtual bool IsDefaultPool() const = 0;
  109. virtual void DeleteIfUnreferenced() = 0;
  110. #if defined( _X360 )
  111. virtual bool ClearTexture( int r, int g, int b, int a ) = 0;
  112. virtual bool CreateRenderTargetSurface( int width, int height, ImageFormat format, bool bSameAsTexture, RTMultiSampleCount360_t multiSampleCount = RT_MULTISAMPLE_NONE ) = 0;
  113. #endif
  114. // swap everything except the name with another texture
  115. virtual void SwapContents( ITexture *pOther ) = 0;
  116. // Retrieve the vtf flags mask
  117. virtual unsigned int GetFlags( void ) const = 0;
  118. // Force LOD override (automatically downloads the texture)
  119. virtual void ForceLODOverride( int iNumLodsOverrideUpOrDown ) = 0;
  120. // Force exclude override (automatically downloads the texture)
  121. virtual void ForceExcludeOverride( int iExcludeOverride ) = 0;
  122. //swap out the active texture surface, only valid for MultiRenderTarget textures
  123. virtual void AddDownsizedSubTarget( const char *szName, int iDownsizePow2, MaterialRenderTargetDepth_t depth ) = 0;
  124. virtual void SetActiveSubTarget( const char *szName ) = 0; //NULL to return to base target
  125. virtual int GetReferenceCount() const = 0;
  126. virtual bool IsTempExcluded() const = 0;
  127. virtual bool CanBeTempExcluded() const = 0;
  128. virtual bool FinishAsyncDownload( AsyncTextureContext_t *pContext, void *pData, int nNumReadBytes, bool bAbort, float flMaxTimeMs ) = 0;
  129. virtual bool IsForceExcluded() const = 0;
  130. virtual bool ClearForceExclusion() = 0;
  131. };
  132. inline bool IsErrorTexture( ITexture *pTex )
  133. {
  134. return !pTex || pTex->IsError();
  135. }
  136. #endif // ITEXTURE_H