From 4439162fea40ac151e493dd5e1f86f6e3acc266c Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 2 Jul 2026 19:22:39 +0800 Subject: [PATCH] [Fix] (MG_Impl/GLImpl): refresh generated mipmap storage [skip ci] --- .../MG_Backend/DirectVulkan/DirectVulkan.cpp | 4 +++- MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp b/MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp index 2e3f0463..790e11b0 100644 --- a/MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp @@ -614,7 +614,9 @@ namespace MobileGL::MG_Backend::DirectVulkan { srcWidth, srcHeight, srcDepth); } void GenerateMipmap(GLenum target) { - MOBILEGL_ASSERT(pVulkanRenderer, "DirectVulkan::GenerateMipmap called with null VulkanRenderer"); + if (!pVulkanRenderer) { + return; + } MOBILEGL_ASSERT(MG_State::pGLContext, "DirectVulkan::GenerateMipmap called with null GL context"); pVulkanRenderer->GenerateMipmap(target); } diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 1906fa19..23de86d5 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -233,7 +233,7 @@ namespace MobileGL::MG_Impl::GLImpl { const SizeT bytesPerTexel = baseByteSize / baseTexelCount; const Uint requiredLevelCount = ComputeFullMipmapLevelCount(baseTexelSize); - for (Uint level = existingLevelCount; level < requiredLevelCount; ++level) { + for (Uint level = 1; level < requiredLevelCount; ++level) { const IntVec3 levelTexelSize = ComputeMipmapTexelSize(baseTexelSize, level); const SizeT levelByteSize = bytesPerTexel * static_cast(levelTexelSize.x()) * static_cast(levelTexelSize.y()) * @@ -244,6 +244,12 @@ namespace MobileGL::MG_Impl::GLImpl { return true; } + void EnsureGeneratedMipmapStorageAllocated(MG_State::GLState::TextureObjectMipmap& texture) { + for (const TextureUploadTarget uploadTarget : texture.GetUploadTargets()) { + EnsureGeneratedMipmapStorageAllocated(texture, uploadTarget); + } + } + Bool IsMultisampleTextureTarget(TextureTarget target) { return target == TextureTarget::Texture2DMultisample || target == TextureTarget::Texture2DMultisampleArray; @@ -3043,6 +3049,7 @@ namespace MobileGL::MG_Impl::GLImpl { if (textureObject) { auto* mipmapTexture = dynamic_cast(textureObject.get()); MOBILEGL_ASSERT(mipmapTexture != nullptr, "GenerateMipmap requires mipmap texture storage."); + EnsureGeneratedMipmapStorageAllocated(*mipmapTexture); } GenerateMipmap_Backend(target); } @@ -3053,7 +3060,13 @@ namespace MobileGL::MG_Impl::GLImpl { auto* mipmapTexture = dynamic_cast(textureObject.get()); MOBILEGL_ASSERT(mipmapTexture != nullptr, "GenerateTextureMipmap requires mipmap texture storage."); } - WithTemporarilyBoundNamedTexture(textureObject, [&](GLenum target) { GenerateMipmap_Backend(target); }); + WithTemporarilyBoundNamedTexture(textureObject, [&](GLenum target) { + if (textureObject) { + auto* mipmapTexture = dynamic_cast(textureObject.get()); + EnsureGeneratedMipmapStorageAllocated(*mipmapTexture); + } + GenerateMipmap_Backend(target); + }); } void GetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid* pixels) {