Moved fps timing to beginning of paintGL

This should improve accuracy.

However the fps displayed can still sometimes be slightly greater then the
vsync, this is either due to timer accuracy problems or QTimer delay within
OpenGLDisplayPlugin.
This commit is contained in:
Anthony J. Thibault 2015-11-03 15:51:18 -08:00
parent c139b62217
commit 31f361d49c
2 changed files with 20 additions and 22 deletions

View file

@ -1041,8 +1041,25 @@ void Application::initializeUi() {
}
void Application::paintGL() {
_frameCount++;
idle();
// update fps moving average
uint64_t now = usecTimestampNow();
static uint64_t lastPaintBegin{ now };
uint64_t diff = now - lastPaintBegin;
if (diff != 0) {
_framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff);
}
lastPaintBegin = now;
// update fps once a second
if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) {
_fps = _framesPerSecond.getAverage();
_lastFramesPerSecondUpdate = now;
}
idle(now);
PROFILE_RANGE(__FUNCTION__);
PerformanceTimer perfTimer("paintGL");
@ -1318,24 +1335,6 @@ void Application::paintGL() {
batch.resetStages();
});
}
// update fps moving average
{
uint64_t now = usecTimestampNow();
static uint64_t lastPaintEnd{ now };
uint64_t diff = now - lastPaintEnd;
if (diff != 0) {
_framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff);
}
lastPaintEnd = now;
// update fps once a second
if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) {
_fps = _framesPerSecond.getAverage();
_lastFramesPerSecondUpdate = now;
}
_frameCount++;
}
}
void Application::runTests() {
@ -2107,7 +2106,7 @@ void Application::ping() {
}
}
void Application::idle() {
void Application::idle(uint64_t now) {
if (_aboutToQuit) {
return; // bail early, nothing to do here.
}
@ -2130,7 +2129,6 @@ void Application::idle() {
{
PROFILE_RANGE(__FUNCTION__);
uint64_t now = usecTimestampNow();
static uint64_t lastIdleStart{ now };
uint64_t idleStartToStartDuration = now - lastIdleStart;
if (idleStartToStartDuration != 0) {

View file

@ -307,7 +307,7 @@ public slots:
private slots:
void clearDomainOctreeDetails();
void ping();
void idle();
void idle(uint64_t now);
void aboutToQuit();
void handleScriptEngineLoaded(const QString& scriptFilename);