From c664815fee19ec904504e552c77b7ce22da8eb6d Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sat, 15 Nov 2025 23:23:45 +0800 Subject: [PATCH] [Fix] (MG_Backend/DirectGLES): Do not upload junk data for texture. --- MobileGL/MG_Backend/DirectGLES/Managers.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index 15e042f8..234309ba 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -288,10 +288,13 @@ namespace MobileGL::MG_Backend::DirectGLES { for (SizeT level = 0; level < mipmaps.size(); ++level) { const auto& mipmap = mipmaps[level]; + BufferImpl::BackendBufferBindingProtector pixelUnpackProtector = + BufferImpl::BackendBufferBindingProtector(GL_PIXEL_UNPACK_BUFFER); + MG_External::GLES::glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); MG_External::GLES::glTexImage2D(GL_TEXTURE_2D, static_cast(level), glInternalFormat, static_cast(mipmap.size.x()), static_cast(mipmap.size.y()), 0, glFormat, glType, - mipmap.data.data()); + mipmap.hasData ? mipmap.data.data() : nullptr); MGLOG_D("Regenerated mipmap level %d for texture with ID: %u", level, m_backendTextureId); stateTextureObject->UnmarkMipmapDirty(level); @@ -360,9 +363,13 @@ namespace MobileGL::MG_Backend::DirectGLES { continue; } - MG_External::GLES::glTexSubImage2D( - GL_TEXTURE_2D, static_cast(mipmap.level), 0, 0, static_cast(mipmap.size.x()), - static_cast(mipmap.size.y()), glFormat, glType, mipmap.data.data()); + BufferImpl::BackendBufferBindingProtector pixelUnpackProtector = + BufferImpl::BackendBufferBindingProtector(GL_PIXEL_UNPACK_BUFFER); + MG_External::GLES::glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); + MG_External::GLES::glTexSubImage2D(GL_TEXTURE_2D, static_cast(mipmap.level), 0, 0, + static_cast(mipmap.size.x()), + static_cast(mipmap.size.y()), glFormat, glType, + mipmap.hasData ? mipmap.data.data() : nullptr); stateTextureObject->UnmarkMipmapDirty(mipmap.level); } }