From 4c4c6e8f038cdcb6033fc0947b4f1b70fde1b115 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 8 Nov 2021 00:25:20 +0100 Subject: [PATCH] Add setter for `ResidentMipLevels` on GPU Texture for C# scripting --- Source/Engine/Graphics/Textures/GPUTexture.cpp | 6 +++--- Source/Engine/Graphics/Textures/GPUTexture.h | 18 ++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Source/Engine/Graphics/Textures/GPUTexture.cpp b/Source/Engine/Graphics/Textures/GPUTexture.cpp index e8c6ddbe1..4656081d8 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.cpp +++ b/Source/Engine/Graphics/Textures/GPUTexture.cpp @@ -792,9 +792,9 @@ Task* GPUTexture::DownloadDataAsync(TextureData& result) void GPUTexture::SetResidentMipLevels(int32 count) { - ASSERT(IsRegularTexture() && IsAllocated()); - ASSERT(Math::IsInRange(count, 0, MipLevels())); - + count = Math::Clamp(count, 0, MipLevels()); + if (_residentMipLevels == count || !IsRegularTexture()) + return; _residentMipLevels = count; onResidentMipsChanged(); } diff --git a/Source/Engine/Graphics/Textures/GPUTexture.h b/Source/Engine/Graphics/Textures/GPUTexture.h index 82171182b..71f31f390 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.h +++ b/Source/Engine/Graphics/Textures/GPUTexture.h @@ -153,7 +153,7 @@ public: } /// - /// Gets the number of resident mipmap levels in the texture. (already uploaded to the GPU). + /// Gets the number of resident mipmap levels in the texture (already uploaded to the GPU). /// API_PROPERTY() FORCE_INLINE int32 ResidentMipLevels() const { @@ -283,27 +283,24 @@ public: } /// - /// Checks if texture contains sRGB colors data + /// Checks if texture contains sRGB colors data. /// - /// True if texture contains sRGB colors data, otherwise false FORCE_INLINE bool IsSRGB() const { return _sRGB; } /// - /// Checks if texture is normal texture asset (not render target or unordered access or depth buffer or sth else) + /// Checks if texture is normal texture asset (not render target or unordered access or depth buffer or sth else). /// - /// True if it is a regular texture, otherwise false FORCE_INLINE bool IsRegularTexture() const { return _desc.Flags == GPUTextureFlags::ShaderResource; } /// - /// Checks if texture is a staging buffer (supports direct CPU access) + /// Checks if texture is a staging buffer (supports direct CPU access). /// - /// True if texture is a staging buffer (supports direct CPU access), otherwise false FORCE_INLINE bool IsStaging() const { return _desc.Usage == GPUResourceUsage::StagingUpload || _desc.Usage == GPUResourceUsage::StagingReadback; @@ -554,9 +551,10 @@ public: /// True if failed, otherwise false. virtual bool GetData(int32 arrayOrDepthSliceIndex, int32 mipMapIndex, TextureMipData& data, uint32 mipRowPitch = 0) = 0; -public: - - void SetResidentMipLevels(int32 count); + /// + /// Sets the number of resident mipmap levels in the texture (already uploaded to the GPU). + /// + API_PROPERTY() void SetResidentMipLevels(int32 count); protected: