diff --git a/applications/present3D/present3D.cpp b/applications/present3D/present3D.cpp index 80620ada6..cab9fbafc 100644 --- a/applications/present3D/present3D.cpp +++ b/applications/present3D/present3D.cpp @@ -865,7 +865,7 @@ int main( int argc, char **argv ) { osg::Timer_t startFrameTick = osg::Timer::instance()->tick(); - if (viewer.getRunFrameScheme()!=osgViewer::ViewerBase::ON_DEMAND || viewer.checkNeedToDoFrame()) + if (viewer.getRunFrameScheme()!=osgViewer::ViewerBase::ON_DEMAND || seh->checkNeedToDoFrame()) { // do the normal frame. diff --git a/include/osgPresentation/SlideEventHandler b/include/osgPresentation/SlideEventHandler index aa27edeb4..6f41310dd 100644 --- a/include/osgPresentation/SlideEventHandler +++ b/include/osgPresentation/SlideEventHandler @@ -344,6 +344,7 @@ public: osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); } + enum WhichPosition { FIRST_POSITION = 0, @@ -405,6 +406,8 @@ public: double getReferenceTime() const { return _referenceTime; } + virtual bool checkNeedToDoFrame(); + protected: ~SlideEventHandler() {} diff --git a/include/osgViewer/ViewerBase b/include/osgViewer/ViewerBase index e221e9581..9e31a4492 100644 --- a/include/osgViewer/ViewerBase +++ b/include/osgViewer/ViewerBase @@ -224,7 +224,7 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object /** check to see if the new frame is required, called by run(..) when FrameScheme is set to ON_DEMAND.*/ virtual bool checkNeedToDoFrame() = 0; - + /** check to see if events have been received, return true if events are now available.*/ virtual bool checkEvents() = 0; @@ -277,7 +277,11 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object /** Get the keyboard and mouse usage of this viewer.*/ virtual void getUsage(osg::ApplicationUsage& usage) const = 0; - protected: + bool getRequestRedraw() const { return _requestRedraw; } + + bool getRequestContinousUpdate() const { return _requestContinousUpdate; } + +protected: void viewerBaseInit(); @@ -335,9 +339,9 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object osg::ref_ptr _incrementalCompileOperation; osg::observer_ptr _currentContext; - + private: - + // Define private copy constructor // otherwsie VS2015 will construct it's own which will call the private copy operator from osg::Object resulting in an compile error. ViewerBase& operator = (const ViewerBase&) { return *this; } diff --git a/src/osgPresentation/SlideEventHandler.cpp b/src/osgPresentation/SlideEventHandler.cpp index 551c355dc..61f24ff99 100644 --- a/src/osgPresentation/SlideEventHandler.cpp +++ b/src/osgPresentation/SlideEventHandler.cpp @@ -1655,3 +1655,41 @@ void SlideEventHandler::setRequestReload(bool flag) _requestReload = flag; } +bool SlideEventHandler::checkNeedToDoFrame() +{ + if (_viewer.valid()) + { + if (_viewer->getRequestRedraw()) return true; + if (_viewer->getRequestContinousUpdate()) return true; + + // If the database pager is going to update the scene the render flag is + // set so that the updates show up + if(_viewer->getDatabasePager()->requiresUpdateSceneGraph() || _viewer->getDatabasePager()->getRequestsInProgress()) return true; + + // if there update callbacks then we need to do frame. + if (_viewer->getCamera()->getUpdateCallback()) return true; + + if (!_pause) + { + if (_slideSwitch.valid() && _activeLayer(_slideSwitch->getNumChildren())) + { + if (_slideSwitch->getChild(_activeLayer)->getNumChildrenRequiringUpdateTraversal()>0) return true; + } + else if (_viewer->getSceneData()!=0 && _viewer->getSceneData()->getNumChildrenRequiringUpdateTraversal()>0) return true; + } + + // check if events are available and need processing + if (_viewer->checkEvents()) return true; + + // now check if any of the event handles have prompted a redraw. + if (_viewer->getRequestRedraw()) return true; + if (_viewer->getRequestContinousUpdate()) return true; + + return false; + } + else + { + return true; + } +} +