//-------------------------------------------------------------- void ofShader::checkShaderInfoLog(GLuint shader, GLenum type, ofLogLevel logLevel) { GLsizei infoLength; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLength); if (infoLength > 1) { GLchar* infoBuffer = new GLchar[infoLength]; glGetShaderInfoLog(shader, infoLength, &infoLength, infoBuffer); ofLog(logLevel, "ofShader: %s shader reports:\n%s", nameForType(type).c_str(), infoBuffer); if (shaderSource.find(type) != shaderSource.end()) { // The following regexp should match shader compiler error messages by Nvidia and ATI. // Unfortunately, each vendor's driver formats error messages slightly different. std::regex nvidia_ati("^.*[(:]{1}(\\d+)[:)]{1}.*"); std::regex intel("^[0-9]+:([0-9]+)\\([0-9]+\\):.*$"); std::smatch matches; string infoString = (infoBuffer != nullptr) ? ofTrim(infoBuffer): ""; if (std::regex_search(infoString, matches, intel) || std::regex_search(infoString, matches, nvidia_ati)){ ofBuffer buf = shaderSource[type]; ofBuffer::Line line = buf.getLines().begin(); int offendingLineNumber = ofToInt(matches[1]); ostringstream msg; msg << "ofShader: " + nameForType(type) + ", offending line " << offendingLineNumber << " :"<< endl; for(int i=0; line != buf.getLines().end(); line++, i++ ){ string s = *line; if ( i >= offendingLineNumber -3 && i < offendingLineNumber + 2 ){ msg << "\t" << setw(5) << (i+1) << "\t" << s << endl; } } ofLog(logLevel) << msg.str(); }else{ ofLog(logLevel) << shaderSource[type]; } } delete [] infoBuffer; } }
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; }
//-------------------------------------------------------------- void ofShader::checkShaderInfoLog(GLuint shader, GLenum type, ofLogLevel logLevel) { GLsizei infoLength; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLength); if (infoLength > 1) { GLchar* infoBuffer = new GLchar[infoLength]; glGetShaderInfoLog(shader, infoLength, &infoLength, infoBuffer); ofLog(logLevel, "ofShader: %s shader reports:\n%s", nameForType(type).c_str(), infoBuffer); if (shaderSource.find(type) != shaderSource.end()) { // The following regexp should match shader compiler error messages by Nvidia and ATI. // Unfortunately, each vendor's driver formats error messages slightly different. Poco::RegularExpression re("^.*[(:]{1}(\\d+)[:)]{1}.*"); Poco::RegularExpression::MatchVec matches; string infoString = (infoBuffer != NULL) ? string(infoBuffer): ""; re.match(infoString, 0, matches); ofBuffer buf = shaderSource[type]; ofBuffer::Line line = buf.getLines().begin(); if (!matches.empty()){ int offendingLineNumber = ofToInt(infoString.substr(matches[1].offset, matches[1].length)); ostringstream msg; msg << "ofShader: " + nameForType(type) + ", offending line " << offendingLineNumber << " :"<< endl; for(int i=0; line != buf.getLines().end(); line++, i++ ){ string s = *line; if ( i >= offendingLineNumber -3 && i < offendingLineNumber + 2 ){ msg << "\t" << setw(5) << (i+1) << "\t" << s << endl; } } ofLog(logLevel) << msg.str(); } } delete [] infoBuffer; } }
//-------------------------------------------------------------- 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::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 ofxShader::linkProgram() { if(shaders.empty()) { ofLog(OF_LOG_ERROR, "Trying to link GLSL program, but no shaders created yet"); } else { checkAndCreateProgram(); for(map<GLenum, GLuint>::const_iterator it = shaders.begin(); it != shaders.end(); ++it){ GLuint shader = it->second; if(shader) { ofLog(OF_LOG_VERBOSE, "Attaching shader of type " + nameForType(it->first)); glAttachShader(program, shader); } } glLinkProgram(program); for(map<GLenum, GLuint>::const_iterator it = shaders.begin(); it != shaders.end(); ++it){ GLuint shader = it->second; if(shader) { checkShaderLinkStatus(shader, it->first); } } checkProgramInfoLog(program); bLoaded = true; } }
//-------------------------------------------------------------- void ofShader::checkProgramInfoLog(GLuint program) { GLsizei infoLength; glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLength); if (infoLength > 1) { GLchar* infoBuffer = new GLchar[infoLength]; glGetProgramInfoLog(program, infoLength, &infoLength, infoBuffer); string msg = "ofShader: program reports:\n"; #ifdef TARGET_RASPBERRYPI if (shaderSource.find(GL_FRAGMENT_SHADER) != shaderSource.end()) { Poco::RegularExpression re(",.line.([^\\)]*)"); Poco::RegularExpression::MatchVec matches; string infoString = (infoBuffer != NULL) ? string(infoBuffer): ""; re.match(infoString, 0, matches); ofBuffer buf = shaderSource[GL_FRAGMENT_SHADER]; ofBuffer::Line line = buf.getLines().begin(); if (!matches.empty()){ int offendingLineNumber = ofToInt(infoString.substr(matches[1].offset, matches[1].length)); ostringstream msg; msg << "ofShader: " + nameForType(GL_FRAGMENT_SHADER) + ", offending line " << offendingLineNumber << " :"<< endl; for(int i=0; line != buf.getLines().end(); line++, i++ ){ string s = *line; if ( i >= offendingLineNumber -3 && i < offendingLineNumber + 2 ){ msg << "\t" << setw(5) << (i+1) << "\t" << s << endl; } } ofLogError("ofShader") << msg.str(); } } #endif ofLogError("ofShader", msg + infoBuffer); delete [] infoBuffer; } }
//-------------------------------------------------------------- string ofShader::getShaderSource(GLenum type) const{ if (shaderSource.find(type) != shaderSource.end()) { return shaderSource[type]; } else { ofLogError("ofShader") << "No shader source for shader of type: " << nameForType(type); return ""; } }
bool ofxShader::setupShaderFromFile(GLenum type, string filename) { ofBuffer buffer; if(ofReadFile(filename, buffer)) { return setupShaderFromSource(type, buffer.getBuffer()); } else { ofLog(OF_LOG_ERROR, "Could not load shader of type " + nameForType(type) + " from file " + filename); return false; } }
//-------------------------------------------------------------- string ofShader::getShaderSource(GLenum type) const { unordered_map<GLenum,string>::const_iterator source = shaderSource.find(type); if ( source != shaderSource.end()) { return source->second; } else { ofLogError("ofShader") << "No shader source for shader of type: " << nameForType(type); return ""; } }
void ofxShader::checkShaderInfoLog(GLuint shader, GLenum type) { GLsizei infoLength; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLength); if (infoLength > 1) { GLchar* infoBuffer = new GLchar[infoLength]; glGetShaderInfoLog(shader, infoLength, &infoLength, infoBuffer); ofLog(OF_LOG_ERROR, nameForType(type) + " shader reports:\n" + infoBuffer); delete [] infoBuffer; } }
//-------------------------------------------------------------- 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; }
void htmlLinkOut(char *db, struct altSpliceSite *as, FILE *out) { fprintf(out,"<tr><td><a target=\"browser\" " "href=\"http://hgwdev-sugnet.gi.ucsc.edu/cgi-bin/hgTracks?db=%s&position=%s:%d-%d&altGraphXCon=full\">", db, as->chrom, as->chromStart-50, maxInArray(as->altStarts, as->altCount)+50); fprintf(out,"%s (%d)</a></td>", as->agName, as->altCount-1); fprintf(out,"<td>%s</td>", nameForType(as)); if(as->altCount == 2) fprintf(out,"<td>%d</td></tr>\n", as->altBpEnds[1] - as->altBpStarts[1]); else fprintf(out,"<td>N/A</td></tr>\n"); }
//-------------------------------------------------------------- bool ofShader::setupShaderFromFile(GLenum type, string filename) { ofBuffer buffer = ofBufferFromFile(filename); // we need to make absolutely sure to have an absolute path here, so that any #includes // within the shader files have a root directory to traverse from. string absoluteFilePath = ofFilePath::getAbsolutePath(filename, true); string sourceDirectoryPath = ofFilePath::getEnclosingDirectory(absoluteFilePath,false); if(buffer.size()) { return setupShaderFromSource(type, buffer.getText(), sourceDirectoryPath); } else { ofLogError("ofShader") << "setupShaderFromFile(): couldn't load " << nameForType(type) << " shader " << " from \"" << filename << "\""; return false; } }
bool TrackItem::operator <(QTreeWidgetItem const &cmp) const { auto otherTrack = static_cast<TrackItem const &>(cmp).m_track; auto column = treeWidget()->sortColumn(); return 1 == column ? m_track->nameForType() < otherTrack->nameForType() : 2 == column ? m_track->m_codec < otherTrack->m_codec : 3 == column ? m_track->m_language < otherTrack->m_language : (m_track->m_id >= 0) && (otherTrack->m_id >= 0) ? m_track->m_id < otherTrack->m_id : (m_track->m_id < 0) && (otherTrack->m_id < 0) ? m_track->m_codec < otherTrack->m_codec : m_track->m_id >= 0; }
//-------------------------------------------------------------- void ofShader::checkAndCreateProgram() { #ifndef TARGET_OPENGLES if(GL_ARB_shader_objects) { #else if(ofIsGLProgrammableRenderer()){ #endif if(program == 0) { ofLogVerbose("ofShader") << "checkAndCreateProgram(): creating GLSL program"; program = glCreateProgram(); retainProgram(program); } } else { ofLogError("ofShader") << "sorry, it looks like you can't run 'ARB_shader_objects'"; ofLogError("ofShader") << "please check the capabilites of your graphics card: http://www.ozone3d.net/gpu_caps_viewer"; } } //-------------------------------------------------------------- bool ofShader::linkProgram() { if(shaders.empty()) { ofLogError("ofShader") << "linkProgram(): trying to link GLSL program, but no shaders created yet"; } else { checkAndCreateProgram(); for(unordered_map<GLenum, GLuint>::const_iterator it = shaders.begin(); it != shaders.end(); ++it){ GLuint shader = it->second; if(shader) { ofLogVerbose("ofShader") << "linkProgram(): attaching " << nameForType(it->first) << " shader to program " << program; glAttachShader(program, shader); } } glLinkProgram(program); checkProgramLinkStatus(program); // bLoaded means we have loaded shaders onto the graphics card; // it doesn't necessarily mean that these shaders have compiled and linked successfully. bLoaded = true; } return bLoaded; } void ofShader::bindAttribute(GLuint location, const string & name) const{ glBindAttribLocation(program,location,name.c_str()); }
QVariant FlameGraphModel::lookup(const FlameGraphData &stats, int role) const { switch (role) { case TypeIdRole: return stats.typeIndex; case NoteRole: { QString ret; if (!m_typeIdsWithNotes.contains(stats.typeIndex)) return ret; QmlProfilerNotesModel *notes = m_modelManager->notesModel(); foreach (const QVariant &item, notes->byTypeId(stats.typeIndex)) { if (ret.isEmpty()) ret = notes->text(item.toInt()); else ret += QChar::LineFeed + notes->text(item.toInt()); } return ret; } case DurationRole: return stats.duration; case CallCountRole: return stats.calls; case TimePerCallRole: return stats.duration / stats.calls; case TimeInPercentRole: return stats.duration * 100 / m_stackBottom.duration; case AllocationsRole: return stats.allocations; case MemoryRole: return stats.memory; default: break; } if (stats.typeIndex != -1) { const QVector<QmlEventType> &typeList = m_modelManager->qmlModel()->eventTypes(); const QmlEventType &type = typeList[stats.typeIndex]; switch (role) { case FilenameRole: return type.location().filename(); case LineRole: return type.location().line(); case ColumnRole: return type.location().column(); case TypeRole: return nameForType(type.rangeType()); case RangeTypeRole: return type.rangeType(); case DetailsRole: return type.data().isEmpty() ? FlameGraphModel::tr("Source code not available") : type.data(); case LocationRole: return type.displayName(); default: return QVariant(); } } else { return QVariant(); } }
void UIWizard::sltCustomButtonClicked(int iId) { /* Handle 1st button: */ if (iId == CustomButton1) { /* Cleanup: */ cleanup(); /* Compose wizard's name: */ QString strWizardName = nameForType(m_type); /* Load mode settings: */ QStringList wizards = vboxGlobal().virtualBox().GetExtraDataStringList(GUI_HideDescriptionForWizards); /* Switch mode: */ switch (m_mode) { case UIWizardMode_Basic: { m_mode = UIWizardMode_Expert; if (!wizards.contains(strWizardName)) wizards << strWizardName; break; } case UIWizardMode_Expert: { m_mode = UIWizardMode_Basic; if (wizards.contains(strWizardName)) wizards.removeAll(strWizardName); break; } default: { AssertMsgFailed(("Invalid mode: %d", m_mode)); break; } } /* Save mode settings: */ vboxGlobal().virtualBox().SetExtraDataStringList(GUI_HideDescriptionForWizards, wizards); /* Prepare: */ prepare(); } }
//-------------------------------------------------------------- void ofShader::unload() { if(bLoaded) { for(unordered_map<GLenum, GLuint>::const_iterator it = shaders.begin(); it != shaders.end(); ++it) { GLuint shader = it->second; if(shader) { ofLogVerbose("ofShader") << "unload(): detaching and deleting " << nameForType(it->first) << " shader from program " << program; releaseShader(program,shader); } } if (program) { releaseProgram(program); program = 0; } shaders.clear(); } bLoaded = false; }
//-------------------------------------------------------------- void ofShader::unload() { if(bLoaded) { for(map<GLenum, GLuint>::const_iterator it = shaders.begin(); it != shaders.end(); ++it) { GLuint shader = it->second; if(shader) { ofLog(OF_LOG_VERBOSE, "Detaching and deleting shader of type " + nameForType(it->first)); releaseShader(program,shader); } } if (program) { releaseProgram(program); program = 0; } shaders.clear(); } bLoaded = false; }
//-------------------------------------------------------------- bool ofShader::linkProgram() { if(shaders.empty()) { ofLog(OF_LOG_ERROR, "Trying to link GLSL program, but no shaders created yet"); } else { checkAndCreateProgram(); for(map<GLenum, GLuint>::const_iterator it = shaders.begin(); it != shaders.end(); ++it){ GLuint shader = it->second; if(shader) { ofLog(OF_LOG_VERBOSE, "Attaching shader of type " + nameForType(it->first)); glAttachShader(program, shader); } } glLinkProgram(program); checkProgramLinkStatus(program); // bLoaded means we have loaded shaders onto the graphics card; // it doesn't necessarily mean that these shaders have compiled and linked successfully. bLoaded = true; } return bLoaded; }