Browse Source

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().
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
57ae567a36
  1. 20
      src/AbstractShaderProgram.cpp
  2. 7
      src/AbstractShaderProgram.h

20
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<GLuint, string>::const_iterator it = attributes.begin(); it != attributes.end(); ++it)
if(it->second == name) return false;
attributes.insert(pair<GLuint, string>(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<GLuint, string>::const_iterator it = attributes.begin(); it != attributes.end(); ++it)
glBindAttribLocation(program, it->first, it->second.c_str());
/* Link shader program */
glLinkProgram(program);

7
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<GLuint, std::string> attributes;
};
}

Loading…
Cancel
Save