From 57ae567a36fc935aa2fcb342bc39e06ff03db113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 27 Mar 2012 23:19:59 +0200 Subject: [PATCH] Simplified attribute binding in AbstractShaderProgram. Removed another old overdone code, the attributes are now bound directly, without saving the data to some temporary location and then binding everything at once in link(). --- src/AbstractShaderProgram.cpp | 20 ++------------------ src/AbstractShaderProgram.h | 7 ++----- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/AbstractShaderProgram.cpp b/src/AbstractShaderProgram.cpp index 8dc1b631a..46eb356e3 100644 --- a/src/AbstractShaderProgram.cpp +++ b/src/AbstractShaderProgram.cpp @@ -50,35 +50,19 @@ bool AbstractShaderProgram::attachShader(Shader* shader) { return true; } -bool AbstractShaderProgram::bindAttribute(GLuint location, const string& name) { +void AbstractShaderProgram::bindAttribute(GLuint location, const string& name) { if(state != Initialized) { Error() << "AbstractShaderProgram: attribute cannot be bound after linking."; assert(0); - return false; } - /* Check whether given id already exists */ - if(attributes.find(location) != attributes.end()) return false; - - /* Check whether given name already exists */ - for(map::const_iterator it = attributes.begin(); it != attributes.end(); ++it) - if(it->second == name) return false; - - attributes.insert(pair(location, name)); - return true; + glBindAttribLocation(program, location, name.c_str()); } void AbstractShaderProgram::link() { /* Already compiled or failed, exit */ if(state != Initialized) return; - /* Set state to failed if anything goes wrong */ - state = Failed; - - /* Bind attributes to specified locations */ - for(map::const_iterator it = attributes.begin(); it != attributes.end(); ++it) - glBindAttribLocation(program, it->first, it->second.c_str()); - /* Link shader program */ glLinkProgram(program); diff --git a/src/AbstractShaderProgram.h b/src/AbstractShaderProgram.h index 9841a3cb9..167d059a3 100644 --- a/src/AbstractShaderProgram.h +++ b/src/AbstractShaderProgram.h @@ -126,15 +126,13 @@ class MAGNUM_EXPORT AbstractShaderProgram { * @brief Bind attribute to given location * @param location Location * @param name Attribute name - * @return False if the location or name is already bound, true - * otherwise. * - * Binds attribute to the location which can be used later when binding + * Binds attribute to location which is be used later for binding * vertex buffers. * @note This function should be called between loadShader() calls * and link(). */ - bool bindAttribute(GLuint location, const std::string& name); + void bindAttribute(GLuint location, const std::string& name); /** * @brief Link the shader @@ -207,7 +205,6 @@ class MAGNUM_EXPORT AbstractShaderProgram { GLuint program; State state; - std::map attributes; }; }