diff --git a/include/osgDB/ImagePager b/include/osgDB/ImagePager index cd3245f2a..682e2f8de 100644 --- a/include/osgDB/ImagePager +++ b/include/osgDB/ImagePager @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -87,6 +88,14 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler /** Merge the changes to the scene graph. */ virtual void updateSceneGraph(const osg::FrameStamp &frameStamp); + /** Signal the image thread that the update, cull and draw has begun for a new frame. + * Note, this is called by the application so that the image pager can go to sleep while the CPU is busy on the main rendering threads. */ + virtual void signalBeginFrame(const osg::FrameStamp* framestamp); + + /** Signal the image thread that the update, cull and draw dispatch has completed. + * Note, this is called by the application so that the image pager can go to wake back up now the main rendering threads are iddle waiting for the next frame.*/ + virtual void signalEndFrame(); + int cancel(); protected: @@ -105,6 +114,7 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler _timeToMergeBy(0.0), _attachmentIndex(-1) {} + unsigned int _frameNumber; double _timeToMergeBy; std::string _fileName; osg::ref_ptr _loadOptions; @@ -160,6 +170,9 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler bool _done; bool _databasePagerThreadPaused; + OpenThreads::Atomic _frameNumber; + + OpenThreads::Mutex _ir_mutex; osg::ref_ptr _readQueue; typedef std::vector< osg::ref_ptr > ImageThreads; diff --git a/src/osgDB/ImagePager.cpp b/src/osgDB/ImagePager.cpp index 2845b8e62..9aa328f46 100644 --- a/src/osgDB/ImagePager.cpp +++ b/src/osgDB/ImagePager.cpp @@ -78,19 +78,14 @@ void ImagePager::ReadQueue::clear() updateBlock(); } -void ImagePager::ReadQueue::add(ImagePager::ImageRequest* databaseRequest) +void ImagePager::ReadQueue::add(ImagePager::ImageRequest* imageRequest) { - // tempo hack to avoid the ImagePager accumulating requests when it can keep up, - // note this will mean that only one ImageSequence can be properly managed at one time, - // this hack will be removed once a better system for managing expiry of requests is introduced. - // clear(); - OpenThreads::ScopedLock lock(_requestMutex); - _requestList.push_back(databaseRequest); - databaseRequest->_requestQueue = this; + _requestList.push_back(imageRequest); + imageRequest->_requestQueue = this; - OSG_INFO<<"ImagePager::ReadQueue::add("<_fileName<<"), size()="<<_requestList.size()<_fileName<<"), size()="<<_requestList.size()<getFrameNumber()<<">>>>>>>>>>>>>>>>"<getFrameNumber()); + + } //else OSG_INFO << "signalBeginFrame >>>>>>>>>>>>>>>>"<getDatabasePager() : 0; - if (dp) - { - dp->signalBeginFrame(frameStamp); - } + if (dp) dp->signalBeginFrame(frameStamp); + + osgDB::ImagePager* ip = scene ? scene->getImagePager() : 0; + if (ip) ip->signalBeginFrame(frameStamp); if (scene->getSceneData()) { @@ -841,10 +841,10 @@ void ViewerBase::renderingTraversals() { Scene* scene = *sitr; osgDB::DatabasePager* dp = scene ? scene->getDatabasePager() : 0; - if (dp) - { - dp->signalEndFrame(); - } + if (dp) dp->signalEndFrame(); + + osgDB::ImagePager* ip = scene ? scene->getImagePager() : 0; + if (ip) ip->signalEndFrame(); } // wait till the dynamic draw is complete.