From e5c3a6beba19b3bfd197ebca6f8823d1367d7be0 Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Wed, 31 Dec 2025 19:52:01 +0800 Subject: [PATCH] [Feat] (MG_Backend/DirectGLES): Add cache for backend RBO. --- MobileGL/MG_Backend/DirectGLES/Managers.cpp | 23 ++++++++++++++++----- MobileGL/MG_Backend/DirectGLES/Managers.h | 4 ++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index ba9131c8..e9390b3b 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -1048,18 +1048,31 @@ namespace MobileGL::MG_Backend::DirectGLES { MGLOG_D("Syncing RBO with backend ID %u to backend for state ID %u", m_backendRBOId, stateRBOObject->GetExternalIndex()); + if (m_isInitialized && m_cacheInternalFormat == stateRBOObject->GetInternalFormat() && + m_cacheWidth == stateRBOObject->GetWidth() && m_cacheHeight == stateRBOObject->GetHeight()) { + MGLOG_D("RBO %u already initialized with matching parameters, skipping re-allocation.", + stateRBOObject->GetExternalIndex()); + return; + } + Bind(); // Allocate storage + TextureInternalFormat internalFormat = stateRBOObject->GetInternalFormat(); + Int width = static_cast(stateRBOObject->GetWidth()); + Int height = static_cast(stateRBOObject->GetHeight()); GLenum glInternalFormat, glType, glFormat; - TextureImpl::GenerateTextureFormatInfo(stateRBOObject->GetInternalFormat(), &glInternalFormat, &glType, - &glFormat); + TextureImpl::GenerateTextureFormatInfo(internalFormat, &glInternalFormat, &glType, &glFormat); - MG_External::GLES::glRenderbufferStorage(GL_RENDERBUFFER, glInternalFormat, - static_cast(stateRBOObject->GetWidth()), - static_cast(stateRBOObject->GetHeight())); + MG_External::GLES::glRenderbufferStorage(GL_RENDERBUFFER, glInternalFormat, static_cast(width), + static_cast(height)); + + m_cacheInternalFormat = internalFormat; + m_cacheWidth = width; + m_cacheHeight = height; m_isInitialized = true; + MGLOG_D("RBO %u sync completed. backend ID %u", stateRBOObject->GetExternalIndex(), m_backendRBOId); } UnorderedMap, SharedPtr> diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.h b/MobileGL/MG_Backend/DirectGLES/Managers.h index 97dab147..458c9bac 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.h +++ b/MobileGL/MG_Backend/DirectGLES/Managers.h @@ -9,6 +9,7 @@ #include #include "DirectGLES.h" #include "MG_State/GLState/SamplerState/SamplerObject.h" +#include "MG_State/GLState/TextureState/TextureEnum.h" #include #include @@ -185,6 +186,9 @@ namespace MobileGL::MG_Backend::DirectGLES { private: Uint m_backendRBOId = 0; Bool m_isInitialized = false; + TextureInternalFormat m_cacheInternalFormat = TextureInternalFormat::Unknown; + Int m_cacheWidth = 0; + Int m_cacheHeight = 0; }; extern UnorderedMap, SharedPtr>