From 56c6d731857eeec1da2f4807665442d0a1107781 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Mon, 27 Oct 2025 15:45:36 +0800 Subject: [PATCH] [Feat] (MG_State/ProgramObject, MG_Backend/DirectGLES): bind texture to uniform in backend --- MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp | 11 +++++++++++ MobileGL/MG_Backend/DirectGLES/Managers.cpp | 3 --- .../MG_State/GLState/ProgramState/ProgramObject.cpp | 2 +- .../MG_State/GLState/ProgramState/ProgramObject.h | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp b/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp index 2f5d08f0..e6f65dc1 100644 --- a/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp +++ b/MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp @@ -302,6 +302,17 @@ namespace MobileGL::MG_Backend::DirectGLES { MG_External::GLES::glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, backendProgramIt->second->GetBackendGlobalUBOId()); + + // Sampler unit binding + auto maxUniformLoc = currentProgram->GetMaxUniformLocation(); + for (int loc = 0; loc < maxUniformLoc; ++loc) { + auto unit = currentProgram->GetUniformSamplerOrImageUnitIndex(loc); + if (unit == -1) + continue; + auto& name = currentProgram->GetUniformName(loc); + auto locAtBackend = MG_External::GLES::glGetUniformLocation(backendProgramIt->second->GetBackendProgramId(), name.c_str()); + MG_External::GLES::glUniform1i(locAtBackend, unit); + } } else { MG_External::GLES::glUseProgram(0); } diff --git a/MobileGL/MG_Backend/DirectGLES/Managers.cpp b/MobileGL/MG_Backend/DirectGLES/Managers.cpp index 384be06f..5eca0e85 100644 --- a/MobileGL/MG_Backend/DirectGLES/Managers.cpp +++ b/MobileGL/MG_Backend/DirectGLES/Managers.cpp @@ -530,9 +530,6 @@ namespace MobileGL::MG_Backend::DirectGLES { GL_STREAM_DRAW); MG_External::GLES::glBindBuffer(GL_UNIFORM_BUFFER, 0); - // Bind samplers - - m_isInitialized = true; MGLOG_D("Program sync completed. Backend ID: %u", m_backendProgramId); } diff --git a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp index f51eb45a..d9dff9da 100644 --- a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp +++ b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.cpp @@ -92,7 +92,7 @@ namespace MobileGL { // Be aware, there could be gaps in between these vectors // Locations can be not sequential m_uniformIndexInTProgram.resize(m_maxUniformLocation + 1, 4095); - m_uniformSamplerOrImageUnitIndex.resize(m_maxUniformLocation + 1, 0); + m_uniformSamplerOrImageUnitIndex.resize(m_maxUniformLocation + 1, -1); Vector unallocatedUniformIndex; diff --git a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h index 3e2bf16d..c0f7ec11 100644 --- a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h +++ b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h @@ -66,7 +66,7 @@ namespace MobileGL { m_uniformSamplerOrImageUnitIndex[location] = unit; } - Int SetUniformSamplerOrImageUnitIndex(Uint location) const { + Int GetUniformSamplerOrImageUnitIndex(Uint location) const { return m_uniformSamplerOrImageUnitIndex[location]; }