//-------------------------------------------------------------- bool ofShader::setupShaderFromSource(GLenum type, string source, string sourceDirectoryPath) { unload(); // create program if it doesn't exist already checkAndCreateProgram(); GLuint clearErrors = glGetError(); //needed for some users to clear gl errors if( clearErrors != GL_NO_ERROR ) { ofLogVerbose("ofShader") << "setupShaderFromSource(): OpenGL error after checkAndCreateProgram() (probably harmless): error " << clearErrors; } // create shader GLuint shader = glCreateShader(type); if(shader == 0) { ofLogError("ofShader") << "setupShaderFromSource(): failed creating " << nameForType(type) << " shader"; return false; } // parse for includes string src = parseForIncludes( source , sourceDirectoryPath); // store source code (that's the expanded source with all includes copied in) shaderSource[type] = src; // compile shader const char* sptr = src.c_str(); int ssize = src.size(); glShaderSource(shader, 1, &sptr, &ssize); glCompileShader(shader); // check compile status GLint status = GL_FALSE; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); GLuint err = glGetError(); if (err != GL_NO_ERROR) { ofLogError("ofShader") << "setupShaderFromSource(): OpenGL generated error " << err << " trying to get the compile status for a " << nameForType(type) << " shader, does your video card support this?"; return false; } if(status == GL_TRUE) { ofLogVerbose("ofShader") << "setupShaderFromSource(): " << nameForType(type) + " shader compiled"; #ifdef TARGET_EMSCRIPTEN checkShaderInfoLog(shader, type, OF_LOG_VERBOSE); #else checkShaderInfoLog(shader, type, OF_LOG_WARNING); #endif } else if (status == GL_FALSE) { ofLogError("ofShader") << "setupShaderFromSource(): " << nameForType(type) + " shader failed to compile"; checkShaderInfoLog(shader, type, OF_LOG_ERROR); return false; } shaders[type] = shader; retainShader(shader); return true; }
bool ofxShader::setupShaderFromSource(GLenum type, string source) { // create program if it doesn't exist already checkAndCreateProgram(); // create shader GLuint shader = glCreateShader(type); if(shader == 0) { ofLog(OF_LOG_ERROR, "Failed creating shader of type " + nameForType(type)); return false; } // compile shader const char* sptr = source.c_str(); int ssize = source.size(); glShaderSource(shader, 1, &sptr, &ssize); glCompileShader(shader); // check compile status GLint status = GL_FALSE; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); if(status == GL_TRUE) ofLog(OF_LOG_VERBOSE, nameForType(type) + " shader compiled."); else if (status == GL_FALSE) { ofLog(OF_LOG_ERROR, nameForType(type) + " shader failed to compile"); checkShaderInfoLog(shader, type); return false; } shaders[type] = shader; return true; }
bool ofxShader::checkShaderLinkStatus(GLuint shader, GLenum type) { GLint status; glGetProgramiv(shader, GL_LINK_STATUS, &status); if(status == GL_TRUE) ofLog(OF_LOG_VERBOSE, nameForType(type) + " shader linked."); else if (status == GL_FALSE) { ofLog(OF_LOG_ERROR, nameForType(type) + " shader failed to link."); checkShaderInfoLog(shader, type); return false; } return true; }
//-------------------------------------------------------------- bool ofShader::setupShaderFromSource(GLenum type, string source) { // create program if it doesn't exist already checkAndCreateProgram(); // create shader GLuint shader = glCreateShader(type); if(shader == 0) { ofLog(OF_LOG_ERROR, "Failed creating shader of type " + nameForType(type)); return false; } // compile shader const char* sptr = source.c_str(); int ssize = source.size(); glShaderSource(shader, 1, &sptr, &ssize); glCompileShader(shader); // check compile status GLint status = GL_FALSE; glGetShaderiv(shader, GL_COMPILE_STATUS, &status); GLuint err = glGetError(); if (err != GL_NO_ERROR){ ofLog( OF_LOG_ERROR, "OpenGL generated error " + ofToString(err) + " trying to get the compile status for " + nameForType(type) + " shader. Does your video card support this?" ); return false; } if(status == GL_TRUE) ofLog(OF_LOG_VERBOSE, nameForType(type) + " shader compiled."); else if (status == GL_FALSE) { ofLog(OF_LOG_ERROR, nameForType(type) + " shader failed to compile"); checkShaderInfoLog(shader, type); return false; } shaders[type] = shader; retainShader(shader); return true; }