Added extra controls into osgDB::DatabasePager for customizing how

much time is allocated to compiling and deleting OpenGL objects, also
added support into osgProducer::OsgSceneHandler.cpp for these new parameters.

The new cotrols are:

    DatabasePager::s/getTargetFrameRate(..)
    DatabasePager::s/getMinimumTimeAvailableForGLCompileAndDeletePerFrame()
    DatabasePager::s/getMaximumNumOfObjectsToCompilePerFrame()
This commit is contained in:
Robert Osfield
2005-03-17 19:32:09 +00:00
parent a06ca64061
commit 8bb4649cd5
3 changed files with 88 additions and 4 deletions

View File

@@ -50,6 +50,10 @@ DatabasePager::DatabasePager()
_expiryDelay = 10;
_targetFrameRate = 100.0;
_minimumTimeAvailableForGLCompileAndDeletePerFrame = 0.001; // 1ms.
_maximumNumOfObjectsToCompilePerFrame = 8;
// make sure a SharedStateManager exists.
//osgDB::Registry::instance()->getOrCreateSharedStateManager();
@@ -834,7 +838,7 @@ void DatabasePager::compileGLObjects(osg::State& state, double& availableTime)
// while there are valid databaseRequest's in the to compile list and there is
// sufficient time left compile each databaseRequest's stateset and drawables.
while (databaseRequest.valid() && elapsedTime<availableTime && numObjectsCompiled<maxNumObjectsToCompile)
while (databaseRequest.valid() && elapsedTime<availableTime && numObjectsCompiled<_maximumNumOfObjectsToCompilePerFrame)
{
DataToCompileMap& dcm = databaseRequest->_dataToCompileMap;
DataToCompile& dtc = dcm[state.getContextID()];

View File

@@ -84,14 +84,53 @@ void OsgSceneHandler::drawImplementation(Producer::Camera &)
osgDB::DatabasePager* dp = osgDB::Registry::instance()->getDatabasePager();
if (dp)
{
#if 1
double timeForCullAndDraw = osg::Timer::instance()->delta_s(_frameStartTick, osg::Timer::instance()->tick());
double targeFrameTime = 1.0/dp->getTargetFrameRate();
double drawCostFactor = 2.0; // must be greater than 1 to account for the extra cost of emptying the OpenGL fifo.
double frameFactor = 0.9; // must be less than 1, to compensate for extra time spent in update and swap buffers etc.
double timeLeftTillEndOfFrame = targeFrameTime*frameFactor - timeForCullAndDraw*drawCostFactor;
double availableTime = timeLeftTillEndOfFrame / drawCostFactor; // account for the fifo when download texture objects.
// clamp the available time by the prescribed minimum
if (availableTime<dp->getMinimumTimeAvailableForGLCompileAndDeletePerFrame())
{
availableTime = dp->getMinimumTimeAvailableForGLCompileAndDeletePerFrame();
}
static unsigned int _numFramesThatNoTimeAvailable = 0;
static unsigned int _maxNumFramesThatNoTimeAvailable = 10;
if (_numFramesThatNoTimeAvailable>_maxNumFramesThatNoTimeAvailable)
{
availableTime = 0.0025; // 2.5ms.
}
if (availableTime>0.0)
{
_numFramesThatNoTimeAvailable = 0;
// osg::notify(osg::NOTICE)<<"Time available = "<<availableTime<<std::endl;
dp->compileGLObjects(*(getSceneView()->getState()),availableTime);
// flush deleted GL objects.
getSceneView()->flushDeletedGLObjects(availableTime);
}
else
{
++_numFramesThatNoTimeAvailable;
}
#else
double timeForPreviousFrame = osg::Timer::instance()->delta_s(_previousFrameStartTick, _frameStartTick);
double timeForCullAndDraw = osg::Timer::instance()->delta_s(_frameStartTick, osg::Timer::instance()->tick());
double minimumTargetMaxFrameTime = 0.010; // 10ms.
double targetMaxFrameTime = osg::minimum(timeForPreviousFrame, minimumTargetMaxFrameTime);
// Unused variable warning
//double maximumAvailableTime = 0.0025; // 2.5ms.
double drawCostFactor = 2.0; // must be greater than 1 to account for the extra cost of emptying the OpenGL fifo.
double frameFactor = 0.9; // must be less than 1, to compensate for extra time spent in update and swap buffers etc.
double timeLeftTillEndOfFrame = targetMaxFrameTime*frameFactor - timeForCullAndDraw*drawCostFactor;
@@ -120,7 +159,7 @@ void OsgSceneHandler::drawImplementation(Producer::Camera &)
{
++_numFramesThatNoTimeAvailable;
}
#endif
dp->signalEndFrame();
}
}