//////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2011, Computer Graphics Group RWTH Aachen University // // All rights reserved. // //////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include using namespace ACGL::Utils; using namespace ACGL::GLUtils; using namespace ACGL::GLUtils::Tools; using namespace ACGL::Resource; bool Shader::setFromFile(const std::string& _filename) { std::string line = ""; std::string fileContent = ""; std::ifstream fileStream(_filename.c_str(), std::ifstream::in); if(fileStream.is_open()) { while (fileStream.good()) { std::getline(fileStream,line); fileContent += line + "\n"; } fileStream.close(); } else { error() << "Failed to open file: " << _filename << std::endl; return false; } return setSource(fileContent); } bool Shader::setSource(const std::string& _source) { return compile(_source.c_str()); } bool Shader::compile(const char* _pProgramText) const { glShaderSource(mContext, 1, &_pProgramText, NULL); openGLRareError(); glCompileShader(mContext); if ( openGLCommonErrorOccured() ) { return false; } // check for shader compile errors: GLint shaderError; glGetShaderiv(mContext, GL_COMPILE_STATUS, &shaderError); if(shaderError != GL_TRUE) { // yes, errors error() << "Shader compile error: " << std::endl; } GLsizei length = 0; glGetShaderiv(mContext, GL_INFO_LOG_LENGTH, &length); if(length > 1) { // a compile log can get produced even if there were no errors, but warnings! GLchar* pInfo = new char[length + 1]; glGetShaderInfoLog(mContext, length, &length, pInfo); error() << "Compile log: " << std::string(pInfo) << std::endl; delete[] pInfo; } return (shaderError == GL_TRUE); // return true if we encountered no errors }