// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "ITextureOwner.h" #include "Engine/Streaming/StreamableResource.h" #include "Types.h" /// /// GPU texture object which can change it's resolution (quality) at runtime. /// class FLAXENGINE_API StreamingTexture : public Object, public StreamableResource { friend class TextureBase; friend class TexturesStreamingHandler; friend class StreamTextureMipTask; friend class StreamTextureResizeTask; protected: ITextureOwner* _owner; GPUTexture* _texture; TextureHeader _header; int32 _minMipCountBlockCompressed; bool _isBlockCompressed; Array> _streamingTasks; public: StreamingTexture(ITextureOwner* owner, const String& name); ~StreamingTexture(); public: /// /// Gets the owner. /// FORCE_INLINE ITextureOwner* GetOwner() const { return _owner; } /// /// Gets texture object handle. /// FORCE_INLINE GPUTexture* GetTexture() const { return _texture; } /// /// Gets texture size of Float2::Zero if not loaded. /// Float2 Size() const; /// /// Gets a value indicating whether this instance is initialized. /// FORCE_INLINE bool IsInitialized() const { return _header.MipLevels > 0; } /// /// Gets total texture width (in texels) /// FORCE_INLINE int32 TotalWidth() const { return _header.Width; } /// /// Gets total texture height (in texels) /// FORCE_INLINE int32 TotalHeight() const { return _header.Height; } /// /// Gets total texture array size /// FORCE_INLINE int32 TotalArraySize() const { return IsCubeMap() ? 6 : 1; } /// /// Gets total texture mip levels count /// FORCE_INLINE int32 TotalMipLevels() const { return _header.MipLevels; } /// /// Returns texture format type /// FORCE_INLINE TextureFormatType GetFormatType() const { return _header.Type; } /// /// Returns true if it's a cube map texture /// FORCE_INLINE bool IsCubeMap() const { return _header.IsCubeMap; } /// /// Returns true if texture cannot be used during GPU resources streaming system /// FORCE_INLINE bool NeverStream() const { return _header.NeverStream; } /// /// Gets the texture header. /// FORCE_INLINE const TextureHeader* GetHeader() const { return &_header; } public: /// /// Converts allocated texture mip index to the absolute mip map index. /// /// Index of the texture mip. /// The index of the mip map. int32 TextureMipIndexToTotalIndex(int32 textureMipIndex) const; /// /// Converts absolute mip map index to the allocated texture mip index. /// /// Index of the texture mip. /// The index of the mip map. int32 TotalIndexToTextureMipIndex(int32 mipIndex) const; public: /// /// Creates new texture /// /// Texture header /// True if cannot create texture, otherwise false bool Create(const TextureHeader& header); /// /// Release texture /// void UnloadTexture(); /// /// Gets the total memory usage that texture may have in use (if loaded to the maximum quality). /// Exact value may differ due to memory alignment and resource allocation policy. /// /// The amount of bytes. uint64 GetTotalMemoryUsage() const; public: FORCE_INLINE GPUTexture* operator->() const { return _texture; } public: // [Object] String ToString() const override; // [StreamableResource] int32 GetMaxResidency() const override; int32 GetCurrentResidency() const override; int32 GetAllocatedResidency() const override; bool CanBeUpdated() const override; Task* UpdateAllocation(int32 residency) override; Task* CreateStreamingTask(int32 residency) override; void CancelStreamingTasks() override; };