//////////////////////////////////////////////////////////////////////////////// // 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); #ifdef ACGL_CHECK_CRITICAL_GL_ERRORS if ( openGLRareErrorOccured() ) { // it's uncommon that glLinkProgram creates errors, // linking errors create no gl errors but a GL_LINK_STATUS of GL_FALSE return false; } // check for program link errors: GLint programError; glGetProgramiv(mContext, GL_LINK_STATUS, &programError); if (programError != GL_TRUE) { // yes, errors :-( error() << "Program could not get linked:" << std::endl; } GLsizei length = 0; glGetProgramiv(mContext, GL_INFO_LOG_LENGTH, &length); if (length > 1) { // error log or warnings: GLchar* pInfo = new char[length + 1]; glGetProgramInfoLog(mContext, length, &length, pInfo); openGLRareError(); warning() << "Linker log: " << std::string(pInfo) << std::endl; delete[] pInfo; return (programError == GL_TRUE); // if the log contains only warnings we return true } #endif return true; }