From 777d756d1b0beb31f8edc7ff4b97f168132af163 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 5 May 2026 17:23:57 +0800 Subject: [PATCH] [Fix] (MG_Impl/GL_Texture): properly unbind texture when texture name == 0 --- MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp index 31a9b221..71d881fc 100644 --- a/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp +++ b/MobileGL/MG_Impl/GLImpl/Texture/GL_Texture.cpp @@ -1292,15 +1292,23 @@ namespace MobileGL::MG_Impl::GLImpl { } void BindTexture_State(GLenum target, GLuint texture) { - // TODO: deal with condition where texture == 0 MGLOG_D("BindTexture_State called with target: 0x%X, texture: %u", target, texture); // ======================= Converting ================================ TextureTarget textureTarget = MG_Util::ConvertGLEnumToTextureTarget(target); // ===================== Error Checking ============================== - if (!TextureImpl::ValidateTextureName(texture, true)) return; if (!TextureImpl::ValidateTextureTarget(textureTarget)) return; + // Name 0 unbinds the current target from the active texture unit. + if (texture == 0) { + auto& currentUnit = MG_State::pGLContext->GetTextureUnitObject(MG_State::pGLContext->GetActiveTextureUnit()); + auto& bindingSlot = currentUnit.GetBindingSlot(textureTarget); + bindingSlot.Bind(nullptr); + return; + } + + if (!TextureImpl::ValidateTextureName(texture, true)) return; + // ======================= Processing ================================ Bool doesTextureExist = MG_State::pGLContext->ValidateTextureObject(texture); if (!doesTextureExist) {