[Fix] (MG_Backend/DirectGLES): Fix incorrect active texture unit when binding not dirty.

This commit is contained in:
BZLZHH
2026-02-04 17:51:56 +08:00
parent d13a19126b
commit 07638b8577
+13 -5
View File
@@ -335,10 +335,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
#ifdef TRACY_ENABLE #ifdef TRACY_ENABLE
ZoneScopedC(TRACY_ZONECOLOR_BACKEND); ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
#endif #endif
if (g_activeTextureUnit != unit) {
ActivateTextureUnit(unit);
}
auto targetN = static_cast<SizeT>(MG_Util::ConvertGLEnumToTextureTarget(target)); auto targetN = static_cast<SizeT>(MG_Util::ConvertGLEnumToTextureTarget(target));
if (this == g_boundTexturesCache[unit][targetN]) return; if (this == g_boundTexturesCache[unit][targetN]) return;
ActivateTextureUnit(unit);
MG_External::GLES::glBindTexture(target, m_backendTextureId); MG_External::GLES::glBindTexture(target, m_backendTextureId);
g_boundTexturesCache[unit][targetN] = this; g_boundTexturesCache[unit][targetN] = this;
} }
@@ -760,10 +763,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
} }
void UnbindTexture(Uint unit, GLenum target) { // Active unit will be modified void UnbindTexture(Uint unit, GLenum target) { // Active unit will be modified
if (unit != g_activeTextureUnit) {
ActivateTextureUnit(unit);
}
auto targetN = static_cast<SizeT>(MG_Util::ConvertGLEnumToTextureTarget(target)); auto targetN = static_cast<SizeT>(MG_Util::ConvertGLEnumToTextureTarget(target));
if (g_boundTexturesCache[unit][targetN] == nullptr) return; if (g_boundTexturesCache[unit][targetN] == nullptr) return;
ActivateTextureUnit(unit);
MG_External::GLES::glBindTexture(target, 0); MG_External::GLES::glBindTexture(target, 0);
g_boundTexturesCache[unit][targetN] = nullptr; g_boundTexturesCache[unit][targetN] = nullptr;
} }
@@ -922,11 +928,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
GLenum BackendFramebufferObject::GetBackendAttachmentType(FramebufferAttachmentType frontendAtt) const { GLenum BackendFramebufferObject::GetBackendAttachmentType(FramebufferAttachmentType frontendAtt) const {
GLenum glBackendReadBuffer = GL_NONE; GLenum glBackendReadBuffer = GL_NONE;
auto it = std::find(m_frontendDrawBuffers, auto it = std::find(m_frontendDrawBuffers, m_frontendDrawBuffers + FramebufferObject::MAX_DRAW_BUFFERS,
m_frontendDrawBuffers + FramebufferObject::MAX_DRAW_BUFFERS, frontendAtt); frontendAtt);
Bool notFound = (it == m_frontendDrawBuffers + FramebufferObject::MAX_DRAW_BUFFERS); Bool notFound = (it == m_frontendDrawBuffers + FramebufferObject::MAX_DRAW_BUFFERS);
if (notFound) { if (notFound) {
MGLOG_D("%s: frontendAtt not found in draw buffer (probably not remapped), just use the same as frontend", __func__); MGLOG_D(
"%s: frontendAtt not found in draw buffer (probably not remapped), just use the same as frontend",
__func__);
glBackendReadBuffer = MG_Util::ConvertFramebufferAttachmentTypeToGLEnum(frontendAtt); glBackendReadBuffer = MG_Util::ConvertFramebufferAttachmentTypeToGLEnum(frontendAtt);
} else { } else {
MGLOG_D("%s: frontendAtt found in draw buffer, keep it consistent as in read buffers", __func__); MGLOG_D("%s: frontendAtt found in draw buffer, keep it consistent as in read buffers", __func__);