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.

143 lines
4.8 KiB

  1. //========= Copyright 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. class IVTFTexture;
  16. class ITexture;
  17. struct Rect_t;
  18. //-----------------------------------------------------------------------------
  19. // This will get called on procedural textures to re-fill the textures
  20. // with the appropriate bit pattern. Calling Download() will also
  21. // cause this interface to be called. It will also be called upon
  22. // mode switch, or on other occasions where the bits are discarded.
  23. //-----------------------------------------------------------------------------
  24. abstract_class ITextureRegenerator
  25. {
  26. public:
  27. // This will be called when the texture bits need to be regenerated.
  28. // Use the VTFTexture interface, which has been set up with the
  29. // appropriate texture size + format
  30. // The rect specifies which part of the texture needs to be updated
  31. // You can choose to update all of the bits if you prefer
  32. virtual void RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pRect ) = 0;
  33. // This will be called when the regenerator needs to be deleted
  34. // which will happen when the texture is destroyed
  35. virtual void Release() = 0;
  36. // (erics): This should have a virtual destructor, but would be ABI breaking (non-versioned interface implemented
  37. // by the game)
  38. // virtual ~ITextureRegenerator(){}
  39. };
  40. abstract_class ITexture
  41. {
  42. public:
  43. // Various texture polling methods
  44. virtual const char *GetName( void ) const = 0;
  45. virtual int GetMappingWidth() const = 0;
  46. virtual int GetMappingHeight() const = 0;
  47. virtual int GetActualWidth() const = 0;
  48. virtual int GetActualHeight() const = 0;
  49. virtual int GetNumAnimationFrames() const = 0;
  50. virtual bool IsTranslucent() const = 0;
  51. virtual bool IsMipmapped() const = 0;
  52. virtual void GetLowResColorSample( float s, float t, float *color ) const = 0;
  53. // Gets texture resource data of the specified type.
  54. // Params:
  55. // eDataType type of resource to retrieve.
  56. // pnumBytes on return is the number of bytes available in the read-only data buffer or is undefined
  57. // Returns:
  58. // pointer to the resource data, or NULL
  59. virtual void *GetResourceData( uint32 eDataType, size_t *pNumBytes ) const = 0;
  60. // Methods associated with reference count
  61. virtual void IncrementReferenceCount( void ) = 0;
  62. virtual void DecrementReferenceCount( void ) = 0;
  63. inline void AddRef() { IncrementReferenceCount(); }
  64. inline void Release() { DecrementReferenceCount(); }
  65. // Used to modify the texture bits (procedural textures only)
  66. virtual void SetTextureRegenerator( ITextureRegenerator *pTextureRegen ) = 0;
  67. // Reconstruct the texture bits in HW memory
  68. // If rect is not specified, reconstruct all bits, otherwise just
  69. // reconstruct a subrect.
  70. virtual void Download( Rect_t *pRect = 0, int nAdditionalCreationFlags = 0 ) = 0;
  71. // Uses for stats. . .get the approximate size of the texture in it's current format.
  72. virtual int GetApproximateVidMemBytes( void ) const = 0;
  73. // Returns true if the texture data couldn't be loaded.
  74. virtual bool IsError() const = 0;
  75. // NOTE: Stuff after this is added after shipping HL2.
  76. // For volume textures
  77. virtual bool IsVolumeTexture() const = 0;
  78. virtual int GetMappingDepth() const = 0;
  79. virtual int GetActualDepth() const = 0;
  80. virtual ImageFormat GetImageFormat() const = 0;
  81. virtual NormalDecodeMode_t GetNormalDecodeMode() const = 0;
  82. // Various information about the texture
  83. virtual bool IsRenderTarget() const = 0;
  84. virtual bool IsCubeMap() const = 0;
  85. virtual bool IsNormalMap() const = 0;
  86. virtual bool IsProcedural() const = 0;
  87. virtual void DeleteIfUnreferenced() = 0;
  88. #if defined( _X360 )
  89. virtual bool ClearTexture( int r, int g, int b, int a ) = 0;
  90. virtual bool CreateRenderTargetSurface( int width, int height, ImageFormat format, bool bSameAsTexture ) = 0;
  91. #endif
  92. // swap everything except the name with another texture
  93. virtual void SwapContents( ITexture *pOther ) = 0;
  94. // Retrieve the vtf flags mask
  95. virtual unsigned int GetFlags( void ) const = 0;
  96. // Force LOD override (automatically downloads the texture)
  97. virtual void ForceLODOverride( int iNumLodsOverrideUpOrDown ) = 0;
  98. // Save texture to a file.
  99. virtual bool SaveToFile( const char *fileName ) = 0;
  100. // Copy this texture, which must be a render target or a renderable texture, to the destination texture,
  101. // which must have been created with the STAGING bit.
  102. virtual void CopyToStagingTexture( ITexture* pDstTex ) = 0;
  103. // Set that this texture should return true for the call "IsError"
  104. virtual void SetErrorTexture( bool bIsErrorTexture ) = 0;
  105. };
  106. inline bool IsErrorTexture( ITexture *pTex )
  107. {
  108. return !pTex || pTex->IsError();
  109. }
  110. #endif // ITEXTURE_H