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) {