From a072c2fc7069bb8b8ed02a81025ee04d1f4181f6 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Sat, 16 Aug 2025 23:10:12 +0800 Subject: [PATCH] [Feat] (MG_State/Program): GetAttribLocation --- MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp | 9 ++++++++- MobileGL/MG_State/GLState/ProgramState/ProgramObject.h | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp b/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp index 1ec29ee4..14242442 100644 --- a/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp +++ b/MobileGL/MG_Impl/GLImpl/Program/GL_Program.cpp @@ -215,7 +215,14 @@ namespace MobileGL { } GLint GetAttribLocation_State(GLuint program, const GLchar* name) { - THROW_UNIMPL_EXCEPTION; + auto programObject = TryToGetProgramObject(program); + if (!programObject) + return -1; + if (strncmp(name, "gl_", 3) == 0) + return -1; + if (!programObject->GetLinkStatus()) + return -1; + return programObject->GetAttributeLocation(name); } void GetProgramiv_State(GLuint program, GLenum pname, GLint* params) { diff --git a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h index 9947c633..31a1d920 100644 --- a/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h +++ b/MobileGL/MG_State/GLState/ProgramState/ProgramObject.h @@ -33,6 +33,11 @@ namespace MobileGL { return m_uniformNames[index]; } + Int GetAttributeLocation(const String& name) { + const auto it = std::find(m_attribs.begin(), m_attribs.end(), name); + return (it == m_attribs.end()) ? -1 : std::distance(m_attribs.begin(), it); + } + Bool GetDeleteStatus() const { return m_deleteStatus; } Bool GetLinkStatus() const { return m_linkStatus; } Bool GetValidateStatus() const { return m_validateStatus; } @@ -76,7 +81,7 @@ namespace MobileGL { String m_infoLog; Bool m_deleteStatus = false; - Bool m_linkStatus = true; + Bool m_linkStatus = false; Bool m_validateStatus = true; }; } // namespace GLState