//////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2011, Computer Graphics Group RWTH Aachen University // // All rights reserved. // //////////////////////////////////////////////////////////////////////////////// #include #include #include using namespace ACGL::GLUtils; using namespace ACGL::GLUtils::Tools; using namespace ACGL::Utils; using namespace ACGL::Resource; void ShaderProgram::bindAttributeLocations() const { for (SharedShaderVec::size_type i = 0; i < mShaders.size(); ++i) { const Shader::AttributeVec& attribs = mShaders[i]->getAttributes(); for (Shader::AttributeVec::size_type k = 0; k < attribs.size(); ++k) { glBindAttribLocation(mContext, k, attribs[k].c_str()); } } } bool ShaderProgram::link(void) const { bindAttributeLocations(); glLinkProgram(mContext); if ( openGLRareErrorOccured() ) { // it's uncommon that this fails, compile errors (the most common errors) // are not checked here! return false; } // check for shader compile errors: GLint error; glGetProgramiv(mContext, GL_LINK_STATUS, &error); if (error != GL_TRUE) { // yes, errors :-( GLsizei length = 0; glGetProgramiv(mContext, GL_INFO_LOG_LENGTH, &length); if (length > 1) { GLchar* pInfo = new char[length + 1]; glGetProgramInfoLog(mContext, length, &length, pInfo); openGLRareError(); message() << "Linker Error: " << std::string(pInfo) << std::endl; delete[] pInfo; return false; } } return true; }