[Fix] (MG_Impl/GL_Texture): properly unbind texture when texture name == 0

This commit is contained in:
2026-05-05 17:23:57 +08:00
parent 7716a8e05d
commit 777d756d1b
+10 -2
View File
@@ -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) {