1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-03-13 02:42:08 +00:00

Add call for post hoc binding.

This commit is contained in:
Thomas Harte
2026-01-29 14:52:17 -05:00
parent 5f0ab48ec1
commit 77a2d2cb3c
2 changed files with 35 additions and 24 deletions

View File

@@ -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());
}

View File

@@ -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.