From 311b95b9fc83eebfb8652652aaaff7fea34bb618 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Mon, 14 Feb 2022 14:37:04 +0100 Subject: [PATCH] Add support for using mipmaps with 3D textures --- Source/Engine/Graphics/Textures/GPUTexture.cpp | 5 ----- Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp | 4 +++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Graphics/Textures/GPUTexture.cpp b/Source/Engine/Graphics/Textures/GPUTexture.cpp index 6a8da9b68..a49b97070 100644 --- a/Source/Engine/Graphics/Textures/GPUTexture.cpp +++ b/Source/Engine/Graphics/Textures/GPUTexture.cpp @@ -431,11 +431,6 @@ bool GPUTexture::Init(const GPUTextureDescription& desc) LOG(Warning, "Cannot create texture. Only 2D Texture can be used as a Depth Stencil. Description: {0}", desc.ToString()); return true; } - if (desc.MipLevels != 1) - { - LOG(Warning, "Cannot create texture. Volume texture cannot have more than 1 mip level. Description: {0}", desc.ToString()); - return true; - } if (desc.ArraySize != 1) { LOG(Warning, "Cannot create texture. Volume texture cannot create array of volume textures. Description: {0}", desc.ToString()); diff --git a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp index f558152f1..37d4a663f 100644 --- a/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp +++ b/Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp @@ -732,7 +732,9 @@ void GPUContextDX11::UpdateTexture(GPUTexture* texture, int32 arrayIndex, int32 auto textureDX11 = static_cast(texture); const int32 subresourceIndex = RenderToolsDX::CalcSubresourceIndex(mipIndex, arrayIndex, texture->MipLevels()); - const uint32 depthPitch = texture->IsVolume() ? slicePitch / texture->Depth() : slicePitch; + uint32 depthPitch = slicePitch; + if (texture->IsVolume()) + depthPitch /= Math::Max(1, texture->Depth() >> mipIndex); _context->UpdateSubresource(textureDX11->GetResource(), subresourceIndex, nullptr, data, (UINT)rowPitch, (UINT)depthPitch); //D3D11_MAPPED_SUBRESOURCE mapped;