diff --git a/Source/Engine/Graphics/Textures/StreamingTexture.cpp b/Source/Engine/Graphics/Textures/StreamingTexture.cpp index 54063f536..7637e67f0 100644 --- a/Source/Engine/Graphics/Textures/StreamingTexture.cpp +++ b/Source/Engine/Graphics/Textures/StreamingTexture.cpp @@ -110,6 +110,14 @@ bool StreamingTexture::Create(const TextureHeader& header) // That's one of the main advantages of the current resources streaming system. _header = header; _isBlockCompressed = PixelFormatExtensions::IsCompressed(_header.Format); + if (_isBlockCompressed) + { + // Ensure that streaming doesn't go too low because the hardware expects the texture to be min in size of compressed texture block + int32 lastMip = header.MipLevels - 1; + while (header.Width >> lastMip < 4 && header.Height >> lastMip < 4) + lastMip--; + _minMipCountBlockCompressed = header.MipLevels - lastMip + 1; + } // Request resource streaming #if GPU_ENABLE_TEXTURES_STREAMING diff --git a/Source/Engine/Graphics/Textures/StreamingTexture.h b/Source/Engine/Graphics/Textures/StreamingTexture.h index 2317c52db..324040baf 100644 --- a/Source/Engine/Graphics/Textures/StreamingTexture.h +++ b/Source/Engine/Graphics/Textures/StreamingTexture.h @@ -12,6 +12,7 @@ class FLAXENGINE_API StreamingTexture : public Object, public StreamableResource { friend class TextureBase; + friend class TexturesStreamingHandler; friend class StreamTextureMipTask; friend class StreamTextureResizeTask; protected: @@ -20,6 +21,7 @@ protected: GPUTexture* _texture; TextureHeader _header; volatile mutable int64 _streamingTasksCount; + int32 _minMipCountBlockCompressed; bool _isBlockCompressed; public: @@ -122,14 +124,6 @@ public: return &_header; } - /// - /// Gets a boolean indicating whether this is a using a block compress format (BC1, BC2, BC3, BC4, BC5, BC6H, BC7). - /// - FORCE_INLINE bool IsBlockCompressed() const - { - return _isBlockCompressed; - } - public: /// diff --git a/Source/Engine/Streaming/StreamingHandlers.cpp b/Source/Engine/Streaming/StreamingHandlers.cpp index 2fb4cd840..169d94c10 100644 --- a/Source/Engine/Streaming/StreamingHandlers.cpp +++ b/Source/Engine/Streaming/StreamingHandlers.cpp @@ -57,10 +57,10 @@ int32 TexturesStreamingHandler::CalculateResidency(StreamableResource* resource, #endif } - if (mipLevels > 0 && mipLevels < 3 && totalMipLevels > 1 && texture.IsBlockCompressed()) + if (mipLevels > 0 && mipLevels < texture._minMipCountBlockCompressed && texture._isBlockCompressed) { - // Block compressed textures require minimum size of 4 (3 mips or more) - mipLevels = 3; + // Block compressed textures require minimum size of 4 + mipLevels = texture._minMipCountBlockCompressed; } return Math::Clamp(mipLevels, 0, totalMipLevels);