From e51c7f158768f8dfa09ebc96366f0a672547087f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Mar 2003 15:25:49 +0000 Subject: [PATCH] Added support for AbortRendering flag pointer in osg::State which is used by osgUtil::RenderLeaf to test if any abort state has been set, if so it doesn't do any further drawing. The osgProducer::Viewer has been set up to set the osg::State's it manages with their AbortRendering flag pointers set to the osgProducer::Viewer::_done memeber varaible. Now when escape is pressed the rendering is aborted early. --- include/osg/State | 11 ++++++++++- src/osg/State.cpp | 3 ++- src/osgProducer/KeyboardMouseCallback.cpp | 5 +++++ src/osgProducer/Viewer.cpp | 6 ++++++ src/osgUtil/RenderLeaf.cpp | 6 ++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/osg/State b/include/osg/State index bf8453c54..1cc17ba15 100644 --- a/include/osg/State +++ b/include/osg/State @@ -565,6 +565,14 @@ class SG_EXPORT State : public Referenced typedef std::vector ValueVec; + /** Set flag for early termination of the draw traversal.*/ + void setAbortRenderingPtr(bool* abortPtr) { _abortRenderingPtr = abortPtr; } + + /** Get flag for early termination of the draw traversal, + * if true steps should be taken to complete rendering early.*/ + bool getAbortRendering() const { return _abortRenderingPtr!=0?(*_abortRenderingPtr):false; } + + void setReportGLErrors(bool flag) { _reportGLErrors = flag; } bool getReportGLErrors() const { return _reportGLErrors; } @@ -572,6 +580,7 @@ class SG_EXPORT State : public Referenced bool checkGLErrors(StateAttribute::GLMode mode) const; bool checkGLErrors(const StateAttribute* attribute) const; + protected: virtual ~State(); @@ -585,7 +594,7 @@ class SG_EXPORT State : public Referenced ref_ptr _displaySettings; - + bool* _abortRenderingPtr; bool _reportGLErrors; struct ModeStack diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 8317d8171..f240bb9bf 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -23,7 +23,8 @@ State::State() _identity = new osg::RefMatrix(); // default RefMatrix constructs to identity. _projection = _identity; _modelView = _identity; - + + _abortRenderingPtr = false; _reportGLErrors = true; _currentActiveTextureUnit=0; diff --git a/src/osgProducer/KeyboardMouseCallback.cpp b/src/osgProducer/KeyboardMouseCallback.cpp index 2a778dfbd..3ed89537e 100644 --- a/src/osgProducer/KeyboardMouseCallback.cpp +++ b/src/osgProducer/KeyboardMouseCallback.cpp @@ -26,6 +26,11 @@ void KeyboardMouseCallback::keyPress( Producer::KeySymbol key ) #endif } + if (_done) + { + // need to contact the viewer so pass on the abort.. + } + osg::ref_ptr event = new EventAdapter; event->adaptKeyPress(getTime(),key); diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index f1f74e72a..2456fdac2 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -187,6 +187,12 @@ void Viewer::realize( ThreadingModel thread_model) OsgCameraGroup::realize( thread_model ); + // set up osg::State objects with a the _done prt to allow early termination of + // draw traversal. + for(SceneHandlerList::iterator p=_shvec.begin(); p!=_shvec.end(); p++ ) + { + (*p)->getState()->setAbortRenderingPtr(&_done); + } } diff --git a/src/osgUtil/RenderLeaf.cpp b/src/osgUtil/RenderLeaf.cpp index 47db78e62..91209f238 100644 --- a/src/osgUtil/RenderLeaf.cpp +++ b/src/osgUtil/RenderLeaf.cpp @@ -18,6 +18,12 @@ using namespace osgUtil; void RenderLeaf::render(State& state,RenderLeaf* previous) { + // don't draw this leaf if the abort rendering flag has been set. + if (state.getAbortRendering()) + { + //cout << "early abort"<