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.
Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all
Unified · Split
| @@ -1041,8 +1041,25 @@ void Application::initializeUi() { · 1040 unmodified lines | ||
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | void Application::paintGL() { |
| 1044 | + _frameCount++; | |
| 1044 | 1045 | |
| 1045 | − idle(); | |
| 1046 | + // update fps moving average | |
| 1047 | + uint64_t now = usecTimestampNow(); | |
| 1048 | + static uint64_t lastPaintBegin{ now }; | |
| 1049 | + uint64_t diff = now - lastPaintBegin; | |
| 1050 | + if (diff != 0) { | |
| 1051 | + _framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff); | |
| 1052 | + } | |
| 1053 | + | |
| 1054 | + lastPaintBegin = now; | |
| 1055 | + | |
| 1056 | + // update fps once a second | |
| 1057 | + if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) { | |
| 1058 | + _fps = _framesPerSecond.getAverage(); | |
| 1059 | + _lastFramesPerSecondUpdate = now; | |
| 1060 | + } | |
| 1061 | + | |
| 1062 | + idle(now); | |
| 1046 | 1063 | |
| 1047 | 1064 | PROFILE_RANGE(__FUNCTION__); |
| 1048 | 1065 | PerformanceTimer perfTimer("paintGL"); |
| @@ -1318,24 +1335,6 @@ void Application::paintGL() { · 269 unmodified lines | ||
| 1318 | 1335 | batch.resetStages(); |
| 1319 | 1336 | }); |
| 1320 | 1337 | } |
| 1321 | − | |
| 1322 | − // update fps moving average | |
| 1323 | − { | |
| 1324 | − uint64_t now = usecTimestampNow(); | |
| 1325 | − static uint64_t lastPaintEnd{ now }; | |
| 1326 | − uint64_t diff = now - lastPaintEnd; | |
| 1327 | − if (diff != 0) { | |
| 1328 | − _framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff); | |
| 1329 | − } | |
| 1330 | − lastPaintEnd = now; | |
| 1331 | − | |
| 1332 | − // update fps once a second | |
| 1333 | − if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) { | |
| 1334 | − _fps = _framesPerSecond.getAverage(); | |
| 1335 | − _lastFramesPerSecondUpdate = now; | |
| 1336 | − } | |
| 1337 | − _frameCount++; | |
| 1338 | − } | |
| 1339 | 1338 | } |
| 1340 | 1339 | |
| 1341 | 1340 | void Application::runTests() { |
| @@ -2107,7 +2106,7 @@ void Application::ping() { · 765 unmodified lines | ||
| 2107 | 2106 | } |
| 2108 | 2107 | } |
| 2109 | 2108 | |
| 2110 | −void Application::idle() { | |
| 2109 | +void Application::idle(uint64_t now) { | |
| 2111 | 2110 | if (_aboutToQuit) { |
| 2112 | 2111 | return; // bail early, nothing to do here. |
| 2113 | 2112 | } |
| @@ -2130,7 +2129,6 @@ void Application::idle() { · 16 unmodified lines | ||
| 2130 | 2129 | |
| 2131 | 2130 | { |
| 2132 | 2131 | PROFILE_RANGE(__FUNCTION__); |
| 2133 | − uint64_t now = usecTimestampNow(); | |
| 2134 | 2132 | static uint64_t lastIdleStart{ now }; |
| 2135 | 2133 | uint64_t idleStartToStartDuration = now - lastIdleStart; |
| 2136 | 2134 | if (idleStartToStartDuration != 0) { |