From 44b8b0177c3ac752b41987af31f9c47d9836de8c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 31 May 2005 05:37:13 +0000 Subject: [PATCH] Added ability to toggle on/off the pre compile of OpenGL objects in the DatabasePager via the setDoPreCompile(bool) method or via the env var OSG_DO_PRE_COMPILE=ON or OFF. --- include/osgDB/DatabasePager | 11 +++++++++++ src/osgDB/DatabasePager.cpp | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index c387ebda8..3b8fc45a8 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -157,6 +157,16 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl * note, should be only be called from the update thread. */ virtual void registerPagedLODs(osg::Node* subgraph); + /** Set whether the database pager should pre compile OpenGL objects before allowing + * them to be merged into the scene graph. + * Pre compilation helps reduce the chances of frame drops, but also slows the + * speed at which tiles are merged as they have to be compiled first.*/ + void setDoPreCompile(bool flag) { _doPreCompile = flag; } + + /** Get whether the database pager should pre compile OpenGL objects before allowing + * them to be merged into the scene graph.*/ + bool getDoPreCompile() const { return _doPreCompile; } + /** Set the target frame rate that the DatabasePager should assume. * Typically one would set this to the value refresh rate of your display system i.e. 60Hz. @@ -367,6 +377,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl ActiveGraphicsContexts _activeGraphicsContexts; + bool _doPreCompile; double _targetFrameRate; double _minimumTimeAvailableForGLCompileAndDeletePerFrame; unsigned int _maximumNumOfObjectsToCompilePerFrame; diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 4c2b63081..ad3884c73 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -20,8 +20,9 @@ using namespace osgDB; using namespace OpenThreads; -static osg::ApplicationUsageProxy DatabasePager_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MINIMUM_COMPILE_TIME_PER_FRAME ","minimum compile time alloted to compiling GL objects per frame in database pager."); -static osg::ApplicationUsageProxy DatabasePager_e1(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAXIMUM_OBJECTS_TO_COMPILE_PER_FRAME ","maximum number of GL objects to compile per frame in database pager."); +static osg::ApplicationUsageProxy DatabasePager_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_DO_PRE_COMPILE ","Switch on or off the pre compile of OpenGL object database pager."); +static osg::ApplicationUsageProxy DatabasePager_e1(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MINIMUM_COMPILE_TIME_PER_FRAME ","minimum compile time alloted to compiling OpenGL objects per frame in database pager."); +static osg::ApplicationUsageProxy DatabasePager_e2(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAXIMUM_OBJECTS_TO_COMPILE_PER_FRAME ","maximum number of OpenGL objects to compile per frame in database pager."); DatabasePager::DatabasePager() { @@ -56,11 +57,17 @@ DatabasePager::DatabasePager() _expiryDelay = 10; + const char* ptr=0; + _doPreCompile = true; + if( (ptr = getenv("OSG_DO_PRE_COMPILE")) != 0) + { + _doPreCompile = strcmp(ptr,"yes")==0 || strcmp(ptr,"YES")==0 || + strcmp(ptr,"ON")==0 || strcmp(ptr,"ON")==0; + } + _targetFrameRate = 100.0; _minimumTimeAvailableForGLCompileAndDeletePerFrame = 0.001; // 1ms. _maximumNumOfObjectsToCompilePerFrame = 8; - - const char* ptr=0; if( (ptr = getenv("OSG_MINIMUM_COMPILE_TIME_PER_FRAME")) != 0) { _minimumTimeAvailableForGLCompileAndDeletePerFrame = atof(ptr); @@ -462,7 +469,7 @@ void DatabasePager::run() bool loadedObjectsNeedToBeCompiled = false; - if (databaseRequest->_loadedModel.valid() && !_activeGraphicsContexts.empty()) + if (_doPreCompile && databaseRequest->_loadedModel.valid() && !_activeGraphicsContexts.empty()) { // force a compute of the loaded model's bounding volume, so that when the subgraph // merged with the main scene graph and large computeBound() isn't incurred.