From 1b31024cd52872beb8d5e696c60bb1579f6752ab Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 23 Sep 2004 18:50:38 +0000 Subject: [PATCH] Clean up of new DatabasePager code, and change of osgProducer so that DatabasePager support is now integrated into the OsgSceneHandler. --- include/osgDB/DatabasePager | 38 ++++++---- include/osgProducer/OsgSceneHandler | 10 ++- src/osg/Texture.cpp | 2 +- src/osgDB/DatabasePager.cpp | 104 ++++++++-------------------- src/osgProducer/OsgSceneHandler.cpp | 34 +++++++++ src/osgProducer/Viewer.cpp | 84 +++------------------- 6 files changed, 103 insertions(+), 169 deletions(-) diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index bcc36e986..71b20d51b 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -182,15 +182,11 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl void getMaxAnisotropyPolicy(bool& changeAnisotropy, float& valueAnisotropy) const { changeAnisotropy = _changeAnisotropy; valueAnisotropy = _valueAnisotropy; } - /** Iterate through the active PagedLOD nodes children removing - * children which havn't been visited since specified expiryTime. - * note, should be only be called from the update thread. */ - void removeExpiredSubgraphs(double currentFrameTime); - - /** Add the loaded data to the scene graph.*/ - void addLoadedDataToSceneGraph(double currentFrameTime); + /** Return trye if there are pending updates to the scene graph that require a call to updateSceneGraph(double). */ + bool requiresUpdateSceneGraph() const; - /** Merge the changes to the scene graph by calling calling removeExpiredSubgraphs then addLoadedDataToSceneGraph*/ + /** Merge the changes to the scene graph by calling calling removeExpiredSubgraphs then addLoadedDataToSceneGraph. + * Note, must only be called from single thread update phase. */ void updateSceneGraph(double currentFrameTime) { removeExpiredSubgraphs(currentFrameTime); @@ -204,8 +200,13 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl /** Get whether the compilation of rendering objects for specfied graphics context on (true) or off(false). */ bool getCompileGLObjectsForContextID(unsigned int contextID); + /** Return true if there are pending compile operations that are required. + * If requiresCompileGLObjects() return true the application should call compileGLObjects() .*/ + bool requiresCompileGLObjects() const; + /** Compile the rendering objects (display lists,texture objects, VBO's) on loaded subgraph. - * note, should only be called from the draw thread.*/ + * note, should only be called from the draw thread. + * Note, must only be called from a valid graphics context. */ void compileGLObjects(osg::State& state,double& availableTime); @@ -213,7 +214,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl typedef std::list< osg::ref_ptr > PagedLODList; - typedef std::vector< osg::ref_ptr > StateSetList; + typedef std::set< osg::ref_ptr > StateSetList; typedef std::vector< osg::ref_ptr > DrawableList; typedef std::pair DataToCompile; typedef std::map< unsigned int, DataToCompile > DataToCompileMap; @@ -262,6 +263,15 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl } + /** Iterate through the active PagedLOD nodes children removing + * children which havn't been visited since specified expiryTime. + * note, should be only be called from the update thread. */ + void removeExpiredSubgraphs(double currentFrameTime); + + /** Add the loaded data to the scene graph.*/ + void addLoadedDataToSceneGraph(double currentFrameTime); + + bool _done; bool _acceptNewRequests; bool _databasePagerThreadPaused; @@ -274,10 +284,10 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl ThreadPriority _threadPriorityOutwithFrame; DatabaseRequestList _fileRequestList; - OpenThreads::Mutex _fileRequestListMutex; + mutable OpenThreads::Mutex _fileRequestListMutex; DatabaseRequestList _dataToCompileList; - OpenThreads::Mutex _dataToCompileListMutex; + mutable OpenThreads::Mutex _dataToCompileListMutex; bool _changeAutoUnRef; bool _valueAutoUnRef; @@ -286,10 +296,10 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl bool _deleteRemovedSubgraphsInDatabaseThread; ObjectList _childrenToDeleteList; - OpenThreads::Mutex _childrenToDeleteListMutex; + mutable OpenThreads::Mutex _childrenToDeleteListMutex; DatabaseRequestList _dataToMergeList; - OpenThreads::Mutex _dataToMergeListMutex; + mutable OpenThreads::Mutex _dataToMergeListMutex; PagedLODList _activePagedLODList; diff --git a/include/osgProducer/OsgSceneHandler b/include/osgProducer/OsgSceneHandler index cf872a501..3b7126f43 100644 --- a/include/osgProducer/OsgSceneHandler +++ b/include/osgProducer/OsgSceneHandler @@ -14,10 +14,14 @@ #ifndef OSGPRODUCER_OSGSCENEHANDLER #define OSGPRODUCER_OSGSCENEHANDLER 1 -#include +#include +#include #include -#include + +#include + + namespace osgProducer { @@ -99,6 +103,8 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler osg::ref_ptr _clearCallback; osg::ref_ptr _cullCallback; osg::ref_ptr _drawCallback; + + osg::Timer_t _frameStartTick; }; } diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index e44dc741b..92e223afb 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -257,7 +257,7 @@ void TextureObjectManager::flushTextureObjects(unsigned int contextID,double cur itr!=tol.end() && elapsedTimes_minimumNumberOfTextureObjectsToRetainInCache && numObjectsDeleted_timeStamp_timeStamp<=expiryTime) { --s_number; ++Texture::s_numberDeletedTextureInLastFrame; diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 4f2a2a149..e4e39fb03 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -47,7 +47,7 @@ DatabasePager::DatabasePager() _deleteRemovedSubgraphsInDatabaseThread = false; #endif - _expiryDelay = 30; + _expiryDelay = 10; // make sure a SharedStateManager exists. //osgDB::Registry::instance()->getOrCreateSharedStateManager(); @@ -226,11 +226,6 @@ void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* grou } } -static double s_start_frame = 0; -static double s_before_compile = 0; -static double s_after_compile = 0; -static osg::Timer_t startTick = 0; - void DatabasePager::signalBeginFrame(const osg::FrameStamp* framestamp) { @@ -239,58 +234,8 @@ void DatabasePager::signalBeginFrame(const osg::FrameStamp* framestamp) //osg::notify(osg::INFO) << "signalBeginFrame "<getFrameNumber()<<">>>>>>>>>>>>>>>>"<getFrameNumber(); - } //else osg::notify(osg::INFO) << "signalBeginFrame >>>>>>>>>>>>>>>>"<tick(); - - double timeStamp = osg::Timer::instance()->delta_s(startTick,osg::Timer::instance()->tick()); - - double drawTime = s_before_compile-s_start_frame; - double compileTime = s_after_compile-s_before_compile; - double timeDelta = timeStamp-s_start_frame; - - unsigned int numFrames = (timeDelta*60.0074); -/* - if (timeDelta>0.02) - { - std::string str; - if (osg::Texture::s_numberTextureReusedLastInLastFrame > 0) str += " RT "; - if (osg::Texture::s_numberNewTextureInLastFrame > 0) str += " NT "; - if (osg::Texture::s_numberDeletedTextureInLastFrame > 0) str += " DT "; - if (osg::Drawable::s_numberDrawablesReusedLastInLastFrame > 0) str += " RD "; - if (osg::Drawable::s_numberNewDrawablesInLastFrame > 0) str += " ND "; - if (osg::Drawable::s_numberDeletedDrawablesInLastFrame > 0) str += " DD "; - - if (str.empty()) str += " ?? "; - - osg::notify(osg::NOTICE)<<" ************* frame="< lock(_dataToMergeListMutex); + if (!_dataToMergeList.empty()) return true; + } + + return false; + +} + + void DatabasePager::addLoadedDataToSceneGraph(double timeStamp) { @@ -623,6 +581,7 @@ void DatabasePager::addLoadedDataToSceneGraph(double timeStamp) } + void DatabasePager::removeExpiredSubgraphs(double currentFrameTime) { //osg::notify(osg::NOTICE)<<"DatabasePager::removeExpiredSubgraphs()"<(plod)->removeExpiredChildren(currentFrameTime,childrenRemoved)) -// if (const_cast(plod)->removeExpiredChildren(expiryTime,childrenRemoved)) + if (const_cast(plod)->removeExpiredChildren(expiryTime,childrenRemoved)) { //osg::notify(osg::NOTICE)<<"Some children removed from PLod"<accept(fplv); } +bool DatabasePager::requiresCompileGLObjects() const +{ + OpenThreads::ScopedLock lock(_dataToCompileListMutex); + return !_dataToCompileList.empty(); +} + void DatabasePager::setCompileGLObjectsForContextID(unsigned int contextID, bool on) { if (on) @@ -816,19 +780,14 @@ void DatabasePager::compileGLObjects(osg::State& state, double& availableTime) { // osg::notify(osg::NOTICE)<<"DatabasePager::compileGLObjects "<<_frameNumber<delta_s(startTick,osg::Timer::instance()->tick()); - - - double drawTime = s_before_compile-s_start_frame; - if (drawTime<0.01) + if (availableTime>0.0) { const osg::Timer& timer = *osg::Timer::instance(); osg::Timer_t start_tick = timer.tick(); double elapsedTime = 0.0; - double estimatedTextureDuration = 0.0; - double estimatedDrawableDuration = 0.0; + double estimatedTextureDuration = 0.0001; + double estimatedDrawableDuration = 0.0001; osg::ref_ptr databaseRequest; @@ -930,8 +889,6 @@ void DatabasePager::compileGLObjects(osg::State& state, double& availableTime) // estimate the duration of the compile based on current compile duration. estimatedDrawableDuration = (elapsedTime-startCompileTime); - // osg::notify(osg::NOTICE)<<" Compiling drawable "< lock(_dataToCompileListMutex); @@ -985,9 +940,9 @@ void DatabasePager::compileGLObjects(osg::State& state, double& availableTime) elapsedTime = timer.delta_s(start_tick,timer.tick()); } - // availableTime -= elapsedTime; + availableTime -= elapsedTime; - // osg::notify(osg::NOTICE)<<"elapsedTime="<