From e3f73291e9332228aa99d16d68c19a26fd221993 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Fri, 21 Nov 2025 22:24:47 +0800 Subject: [PATCH] [Fix] (MG_Impl/GL_Program): fix GetUniform_State for mat3 alignment issues --- MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp b/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp index 1ca67fb5..607282de 100644 --- a/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp +++ b/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp @@ -423,7 +423,19 @@ namespace MobileGL { auto offset = programObject->GetUniformOffset(location); auto size = programObject->GetUniformSizesInBytes(location); char* pUBO = (char*)programObject->MapUBO(); - memcpy(params, pUBO + offset, size); + auto* ttype = programObject->GetUniformTType(location); + + if (!ttype->isMatrix() || ttype->getMatrixCols() != 3) + memcpy(params, pUBO + offset, size); + else { + // TODO: we only deal with mat3 yet, deal with other types later + // assuming float here, which may not be the case + auto* pBase = pUBO + offset; + for (int i = 0; i < ttype->getMatrixRows(); i++) { + memcpy((char*)params + ttype->getMatrixCols() * sizeof(float) * i, pBase + 4 * sizeof(float) * i, + ttype->getMatrixCols() * sizeof(float)); + } + } } // TODO: handle 1i variant as texture unit }