Hi all,

Here we use osg 2.8.2 and have a requirement to cap the framerate in certain 
cases. We found that doing the following caused us to barely reach the 
framerate limit, so instead of hitting 30 fps it was around 28.X fps.


Code:
while(!viewer.done())
{
  osg::Timer_t startFrameTick = osg::Timer::instance()->tick();

  viewer.frame();

  osg::Timer_t endFrameTick = osg::Timer::instance()->tick();
  double frameTime = osg::Timer::instance()->delta_s(startFrameTick, 
endFrameTick);
  OpenThreads::Thread::microSleep(static_cast<unsigned 
int>(0.95*1000000.0*(minFrameTime-frameTime)));
  if (frameTime < minFrameTime) 
OpenThreads::Thread::microSleep(static_cast<unsigned 
int>(1000000.0*(minFrameTime-frameTime)));
}




however the following code lets us hit exactly 30.0 fps or whatever we ask:


Code:

void CustomViewer::frame(double simulationTime)
{
  if (_done) return;

  float fpsLimit = 30.0;
  osg::Timer_t currentTime = osg::Timer::instance()->tick();
  if (osg::Timer::instance()->delta_s(lastFrameTime, currentTime) < (1.0 / 
fpsLimit)) 
    return;
  lastFrameTime = currentTime;

  if (_firstFrame)
    {
      viewerInit();
      if (!isRealized()) realize();
      _firstFrame = false;
    }

  advance(simulationTime);
  
  eventTraversal();
  updateTraversal();
  renderingTraversals();
}




any thoughts or comments about why this is the case? Also, does the constant 
spinning in the second example mess with OSG multithreading?

thank you!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=45919#45919





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to