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:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user