mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 20:35:17 +02:00
Handle vsync without halving fps
This commit is contained in:
parent
1cce891f7c
commit
2026226fe2
1 changed files with 16 additions and 12 deletions
|
@ -1822,28 +1822,37 @@ bool Application::event(QEvent* event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool justPresented = false;
|
// Presentation/painting logic
|
||||||
|
// TODO: Decouple presentation and painting loops
|
||||||
|
static bool isPainting = false;
|
||||||
if ((int)event->type() == (int)Present) {
|
if ((int)event->type() == (int)Present) {
|
||||||
if (justPresented) {
|
if (isPainting) {
|
||||||
justPresented = false;
|
// If painting (triggered by presentation) is hogging the main thread,
|
||||||
|
// repost as low priority to avoid hanging the GUI.
|
||||||
// If presentation is hogging the main thread, repost as low priority to avoid hanging the GUI.
|
|
||||||
// This has the effect of allowing presentation to exceed the paint budget by X times and
|
// This has the effect of allowing presentation to exceed the paint budget by X times and
|
||||||
// only dropping every (1/X) frames, instead of every ceil(X) frames.
|
// only dropping every (1/X) frames, instead of every ceil(X) frames
|
||||||
// (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).
|
// (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS).
|
||||||
removePostedEvents(this, Present);
|
removePostedEvents(this, Present);
|
||||||
postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);
|
postEvent(this, new QEvent(static_cast<QEvent::Type>(Present)), Qt::LowEventPriority);
|
||||||
|
isPainting = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
idle();
|
idle();
|
||||||
|
|
||||||
|
postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority);
|
||||||
|
isPainting = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if ((int)event->type() == (int)Paint) {
|
} else if ((int)event->type() == (int)Paint) {
|
||||||
// NOTE: This must be updated as close to painting as possible,
|
// NOTE: This must be updated as close to painting as possible,
|
||||||
// or AvatarInputs will mysteriously move to the bottom-right
|
// or AvatarInputs will mysteriously move to the bottom-right
|
||||||
AvatarInputs::getInstance()->update();
|
AvatarInputs::getInstance()->update();
|
||||||
justPresented = true;
|
|
||||||
paintGL();
|
paintGL();
|
||||||
|
|
||||||
|
isPainting = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2658,9 +2667,6 @@ void Application::idle() {
|
||||||
// Sync up the _renderedFrameIndex
|
// Sync up the _renderedFrameIndex
|
||||||
_renderedFrameIndex = displayPlugin->presentCount();
|
_renderedFrameIndex = displayPlugin->presentCount();
|
||||||
|
|
||||||
// Request a paint ASAP
|
|
||||||
postEvent(this, new QEvent(static_cast<QEvent::Type>(Paint)), Qt::HighEventPriority + 1);
|
|
||||||
|
|
||||||
// Update the deadlock watchdog
|
// Update the deadlock watchdog
|
||||||
updateHeartbeat();
|
updateHeartbeat();
|
||||||
|
|
||||||
|
@ -2687,8 +2693,6 @@ void Application::idle() {
|
||||||
_keyboardDeviceHasFocus = true;
|
_keyboardDeviceHasFocus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// We're going to execute idle processing, so restart the last idle timer
|
// We're going to execute idle processing, so restart the last idle timer
|
||||||
_lastTimeUpdated.start();
|
_lastTimeUpdated.start();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue