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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user