//////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2011, Computer Graphics Group RWTH Aachen University // // All rights reserved. // //////////////////////////////////////////////////////////////////////////////// #include #include #include using namespace ACGL::OpenGL; using namespace ACGL::Base; using namespace ACGL::Utils; bool ShaderProgram::link(void) const { glLinkProgram(mObjectName); #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(mObjectName, GL_LINK_STATUS, &programError); if (programError != GL_TRUE) { // yes, errors :-( error() << "Program could not get linked:" << std::endl; } GLsizei length = 0; glGetProgramiv(mObjectName, GL_INFO_LOG_LENGTH, &length); if (length > 1) { // error log or warnings: GLchar* pInfo = new char[length + 1]; glGetProgramInfoLog(mObjectName, 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; } void ShaderProgram::setAttributeLocationsByVAO( const SharedVertexArrayObject& _vao ) { bool needsRelink = false; // search through all attributes of _vao VertexArrayObject::AttributeVec vaoAttributes = _vao->getAttributes(); for(VertexArrayObject::AttributeVec::size_type i = 0; i < vaoAttributes.size(); ++i) { if(vaoAttributes[i].location == -1) continue; // find the name of the current attribute in its ArrayBuffer std::string arrayBufferAttributeName = vaoAttributes[i].arrayBuffer->getAttributes()[vaoAttributes[i].attributeID].name; // find out whether an attribute with a matching name exists in this ShaderProgram GLint attribLocation = getAttributeLocation(arrayBufferAttributeName); if(attribLocation != -1 // attribute with that name exists? && attribLocation != vaoAttributes[i].location) // attribute with that name not already bound correctly? { bindAttributeLocation(arrayBufferAttributeName, vaoAttributes[i].location); needsRelink = true; } } // re-link the program only if necessary if(needsRelink) link(); }