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.
This commit is contained in:
Robert Osfield 2005-05-31 05:37:13 +00:00
parent ac5ffa2bec
commit 44b8b0177c
2 changed files with 23 additions and 5 deletions

View File

@ -157,6 +157,16 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
* note, should be only be called from the update thread. */ * note, should be only be called from the update thread. */
virtual void registerPagedLODs(osg::Node* subgraph); 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. /** 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. * 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; ActiveGraphicsContexts _activeGraphicsContexts;
bool _doPreCompile;
double _targetFrameRate; double _targetFrameRate;
double _minimumTimeAvailableForGLCompileAndDeletePerFrame; double _minimumTimeAvailableForGLCompileAndDeletePerFrame;
unsigned int _maximumNumOfObjectsToCompilePerFrame; unsigned int _maximumNumOfObjectsToCompilePerFrame;

View File

@ -20,8 +20,9 @@
using namespace osgDB; using namespace osgDB;
using namespace OpenThreads; using namespace OpenThreads;
static osg::ApplicationUsageProxy DatabasePager_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MINIMUM_COMPILE_TIME_PER_FRAME <float>","minimum compile time alloted to compiling GL objects per frame in database pager."); static osg::ApplicationUsageProxy DatabasePager_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_DO_PRE_COMPILE <ON/OFF>","Switch on or off the pre compile of OpenGL object database pager.");
static osg::ApplicationUsageProxy DatabasePager_e1(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAXIMUM_OBJECTS_TO_COMPILE_PER_FRAME <int>","maximum number of GL objects to compile per frame in database pager."); static osg::ApplicationUsageProxy DatabasePager_e1(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MINIMUM_COMPILE_TIME_PER_FRAME <float>","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 <int>","maximum number of OpenGL objects to compile per frame in database pager.");
DatabasePager::DatabasePager() DatabasePager::DatabasePager()
{ {
@ -56,11 +57,17 @@ DatabasePager::DatabasePager()
_expiryDelay = 10; _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; _targetFrameRate = 100.0;
_minimumTimeAvailableForGLCompileAndDeletePerFrame = 0.001; // 1ms. _minimumTimeAvailableForGLCompileAndDeletePerFrame = 0.001; // 1ms.
_maximumNumOfObjectsToCompilePerFrame = 8; _maximumNumOfObjectsToCompilePerFrame = 8;
const char* ptr=0;
if( (ptr = getenv("OSG_MINIMUM_COMPILE_TIME_PER_FRAME")) != 0) if( (ptr = getenv("OSG_MINIMUM_COMPILE_TIME_PER_FRAME")) != 0)
{ {
_minimumTimeAvailableForGLCompileAndDeletePerFrame = atof(ptr); _minimumTimeAvailableForGLCompileAndDeletePerFrame = atof(ptr);
@ -462,7 +469,7 @@ void DatabasePager::run()
bool loadedObjectsNeedToBeCompiled = false; 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 // 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. // merged with the main scene graph and large computeBound() isn't incurred.