From 77a2d2cb3cd4249280a66cc2d25ebc64e5825c6f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 29 Jan 2026 14:52:17 -0500 Subject: [PATCH] Add call for post hoc binding. --- Outputs/OpenGL/Primitives/Shader.cpp | 52 +++++++++++++++------------- Outputs/OpenGL/Primitives/Shader.hpp | 7 ++++ 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Outputs/OpenGL/Primitives/Shader.cpp b/Outputs/OpenGL/Primitives/Shader.cpp index 65b302330..1d48bf6f5 100644 --- a/Outputs/OpenGL/Primitives/Shader.cpp +++ b/Outputs/OpenGL/Primitives/Shader.cpp @@ -111,30 +111,7 @@ void Shader::init( test_gl(glAttachShader, shader_program_, fragment); for(const auto &binding : attribute_bindings) { - test_gl(glBindAttribLocation, shader_program_, binding.index, binding.name.c_str()); - - if constexpr (Logger::ErrorsEnabled) { - const auto error = glGetError(); - switch(error) { - case 0: break; - case GL_INVALID_VALUE: - Logger::error().append( - "GL_INVALID_VALUE when attempting to bind %s to index %d " - "(i.e. index is greater than or equal to GL_MAX_VERTEX_ATTRIBS)", - binding.name.c_str(), binding.index); - break; - case GL_INVALID_OPERATION: - Logger::error().append( - "GL_INVALID_OPERATION when attempting to bind %s to index %d " - "(i.e. name begins with gl_)", - binding.name.c_str(), binding.index); - break; - default: - Logger::error().append( - "Error %d when attempting to bind %s to index %d", error, binding.name.c_str(), binding.index); - break; - } - } + bind_attrib_location(binding.name, binding.index); } test_gl(glLinkProgram, shader_program_); @@ -189,6 +166,33 @@ void Shader::unbind() { test_gl(glUseProgram, 0); } +void Shader::bind_attrib_location(const std::string &name, const GLuint index) { + test_gl(glBindAttribLocation, shader_program_, index, name.c_str()); + + if constexpr (Logger::ErrorsEnabled) { + const auto error = glGetError(); + switch(error) { + case 0: break; + case GL_INVALID_VALUE: + Logger::error().append( + "GL_INVALID_VALUE when attempting to bind %s to index %d " + "(i.e. index is greater than or equal to GL_MAX_VERTEX_ATTRIBS)", + name.c_str(), index); + break; + case GL_INVALID_OPERATION: + Logger::error().append( + "GL_INVALID_OPERATION when attempting to bind %s to index %d " + "(i.e. name begins with gl_)", + name.c_str(), index); + break; + default: + Logger::error().append( + "Error %d when attempting to bind %s to index %d", error, name.c_str(), index); + break; + } + } +} + GLint Shader::get_attrib_location(const std::string &name) const { return glGetAttribLocation(shader_program_, name.c_str()); } diff --git a/Outputs/OpenGL/Primitives/Shader.hpp b/Outputs/OpenGL/Primitives/Shader.hpp index a313d4f9e..fc4da9917 100644 --- a/Outputs/OpenGL/Primitives/Shader.hpp +++ b/Outputs/OpenGL/Primitives/Shader.hpp @@ -84,6 +84,13 @@ public: */ static void unbind(); + /*! + Performs a @c glBindAttribLocation call. + @param name The name of the attribute to bind. + @param index The index to bind to. + */ + void bind_attrib_location(const std::string &name, GLuint index); + /*! Performs a @c glGetAttribLocation call. @param name The name of the attribute to locate.