Permalink
Browse files

Added fine grained checking for GL errors in the GLObjectVisitor so t…

…hat the OSG's default pre compile stage provides better feesback on any GL errors.
  • Loading branch information...
robertosfield committed Dec 6, 2017
1 parent d82a7e7 commit d313184cd029542fd984f9e4f117a27861c5aab1
Showing with 36 additions and 11 deletions.
  1. +13 −5 include/osgUtil/GLObjectsVisitor
  2. +23 −6 src/osgUtil/GLObjectsVisitor.cpp
@@ -91,6 +91,12 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
return _renderInfo;
}
/** Set whether and how often OpenGL errors should be checked for, defaults to osg::State::ONCE_PER_ATTRIBUTE. */
void setCheckForGLErrors(osg::State::CheckForGLErrors check) { _checkGLErrors = check; }
/** Get whether and how often OpenGL errors should be checked for.*/
osg::State::CheckForGLErrors getCheckForGLErrors() const { return _checkGLErrors; }
/** Simply traverse using standard NodeVisitor traverse method.*/
virtual void apply(osg::Node& node);
@@ -105,11 +111,13 @@ class OSGUTIL_EXPORT GLObjectsVisitor : public osg::NodeVisitor
typedef std::set<osg::Drawable*> DrawableAppliedSet;
typedef std::set<osg::StateSet*> StatesSetAppliedSet;
Mode _mode;
osg::RenderInfo _renderInfo;
DrawableAppliedSet _drawablesAppliedSet;
StatesSetAppliedSet _stateSetAppliedSet;
osg::ref_ptr<osg::Program> _lastCompiledProgram;
Mode _mode;
osg::RenderInfo _renderInfo;
osg::State::CheckForGLErrors _checkGLErrors;
DrawableAppliedSet _drawablesAppliedSet;
StatesSetAppliedSet _stateSetAppliedSet;
osg::ref_ptr<osg::Program> _lastCompiledProgram;
};
@@ -28,7 +28,7 @@ GLObjectsVisitor::GLObjectsVisitor(Mode mode)
setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
_mode = mode;
_checkGLErrors = osg::State::ONCE_PER_ATTRIBUTE;
}
void GLObjectsVisitor::apply(osg::Node& node)
@@ -57,8 +57,15 @@ void GLObjectsVisitor::apply(osg::Drawable& drawable)
{
if (_drawablesAppliedSet.count(&drawable)!=0) return;
if (_checkGLErrors==osg::State::ONCE_PER_ATTRIBUTE) _renderInfo.getState()->checkGLErrors("start of Drawable::apply(osg::Drawable& drawable)");
_drawablesAppliedSet.insert(&drawable);
if (drawable.getStateSet())
{
apply(*(drawable.getStateSet()));
}
if (_mode&SWITCH_OFF_DISPLAY_LISTS)
{
drawable.setUseDisplayList(false);
@@ -82,30 +89,34 @@ void GLObjectsVisitor::apply(osg::Drawable& drawable)
if (_mode&COMPILE_DISPLAY_LISTS && _renderInfo.getState() &&
(drawable.getUseDisplayList() || drawable.getUseVertexBufferObjects()))
{
drawable.compileGLObjects(_renderInfo);
if (_checkGLErrors==osg::State::ONCE_PER_ATTRIBUTE) _renderInfo.getState()->checkGLErrors("after drawable.compileGLObjects() call in Drawable::apply(osg::Drawable& drawable) ");
}
if (_mode&RELEASE_DISPLAY_LISTS)
{
drawable.releaseGLObjects(_renderInfo.getState());
}
if (drawable.getStateSet())
{
apply(*(drawable.getStateSet()));
}
}
void GLObjectsVisitor::apply(osg::StateSet& stateset)
{
if (_stateSetAppliedSet.count(&stateset)!=0) return;
if (_checkGLErrors==osg::State::ONCE_PER_ATTRIBUTE) _renderInfo.getState()->checkGLErrors("start of GLObjectsVisitor::apply(osg::StateSet& stateset)");
_stateSetAppliedSet.insert(&stateset);
if (_mode & COMPILE_STATE_ATTRIBUTES && _renderInfo.getState())
{
stateset.compileGLObjects(*_renderInfo.getState());
if (_checkGLErrors==osg::State::ONCE_PER_ATTRIBUTE) _renderInfo.getState()->checkGLErrors("after stateset.compileGLObjects in GLObjectsVisitor::apply(osg::StateSet& stateset)");
osg::Program* program = dynamic_cast<osg::Program*>(stateset.getAttribute(osg::StateAttribute::PROGRAM));
if (program) {
if( program->isFixedFunction() )
@@ -129,6 +140,8 @@ void GLObjectsVisitor::apply(osg::StateSet& stateset)
++itr)
{
pcp->apply(*(itr->second.first));
if (_checkGLErrors==osg::State::ONCE_PER_ATTRIBUTE) _renderInfo.getState()->checkGLErrors(std::string("after pcp->apply(Unfiorm&) in GLObjectsVisitor::apply(osg::StateSet& stateset), unifrom name: ")+(itr->second.first)->getName());
}
}
}
@@ -151,6 +164,8 @@ void GLObjectsVisitor::apply(osg::StateSet& stateset)
{
stateset.checkValidityOfAssociatedModes(*_renderInfo.getState());
}
if (_checkGLErrors==osg::State::ONCE_PER_ATTRIBUTE) _renderInfo.getState()->checkGLErrors("after GLObjectsVisitor::apply(osg::StateSet& stateset)");
}
void GLObjectsVisitor::compile(osg::Node& node)
@@ -166,6 +181,8 @@ void GLObjectsVisitor::compile(osg::Node& node)
extensions->glUseProgram(0);
_renderInfo.getState()->setLastAppliedProgramObject(0);
}
if (_checkGLErrors!=osg::State::NEVER_CHECK_GL_ERRORS) _renderInfo.getState()->checkGLErrors("after GLObjectsVisitor::compile(osg::Node& node)");
}
}

0 comments on commit d313184

Please sign in to comment.