From 2534394df302f7de60c75dda47e11878eb52f9ce Mon Sep 17 00:00:00 2001 From: BZLZHH Date: Sat, 15 Nov 2025 21:31:34 +0800 Subject: [PATCH] [Improvement] (MG_Backend/DirectGLES): Better buffer sync. --- MobileGL/MG_Backend/DirectGLES/Managers.cpp | 29 ++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index bedcbdea..9941b47a 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -1,16 +1,15 @@ #include "Managers.h" #include "MG_Backend/Backends.h" -#include "MG_State/GLState/ProgramState/ShaderObject.h" #include "MG_Util/Types.h" #include "Utils.h" #include "DirectGLES.h" -#include "MG_Util/Converters/GLToMG/FramebufferEnumConverter.h" #include #include #include #include #include #include +#include #include #include @@ -93,8 +92,12 @@ namespace MobileGL::MG_Backend::DirectGLES { MGLOG_D("Syncing buffer sub-data (glBufferSubData) for object with ID : %u", m_backendBufferId); const void* data = stateBufferObject->GetDataReadOnly()->data(); - const auto& range = stateBufferObject->GetDirtyRange(); // dirty range: [range.start, range.end) + const auto& range = stateBufferObject->GetDirtyRange(); + if (range.end == 0) { + MGLOG_D("No dirty range to sync for buffer with ID: %u", m_backendBufferId); + return; + } MG_External::GLES::glBindBuffer(TempBufferTarget, m_backendBufferId); MG_External::GLES::glBufferSubData(TempBufferTarget, range.start, range.end - range.start, @@ -107,8 +110,12 @@ namespace MobileGL::MG_Backend::DirectGLES { MGLOG_D("Syncing buffer map (glMapBuffer) for object with ID : %u", m_backendBufferId); MGLOG_D("Mapping buffer with ID: %u", m_backendBufferId); - MG_External::GLES::glBindBuffer(TempBufferTarget, m_backendBufferId); const auto& range = stateBufferObject->GetDirtyRange(); + if (range.end == 0) { + MGLOG_D("No dirty range to sync for buffer with ID: %u", m_backendBufferId); + return; + } + MG_External::GLES::glBindBuffer(TempBufferTarget, m_backendBufferId); void* mappedData = MG_External::GLES::glMapBufferRange(TempBufferTarget, range.start, range.end - range.start, (invalidate ? GL_MAP_INVALIDATE_BUFFER_BIT : 0) | GL_MAP_WRITE_BIT); @@ -661,11 +668,15 @@ namespace MobileGL::MG_Backend::DirectGLES { } // Create global UBO - MG_External::GLES::glGenBuffers(1, &m_backendGlobalUBOId); - MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER, m_backendGlobalUBOId); - MG_External::GLES::glBufferData(GL_UNIFORM_BUFFER, stateProgramObject->GetUBOSize(), nullptr, - GL_STREAM_DRAW); - MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER, 0); + if (stateProgramObject->GetUBOSize() > 0) { + MG_External::GLES::glGenBuffers(1, &m_backendGlobalUBOId); + MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER, m_backendGlobalUBOId); + MG_External::GLES::glBufferData(GL_UNIFORM_BUFFER, stateProgramObject->GetUBOSize(), nullptr, + GL_STREAM_DRAW); + MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER, 0); + } else { + m_backendGlobalUBOId = 0; + } m_isInitialized = true; MGLOG_D("Program sync completed. backend ID %u", m_backendProgramId);