From 93957145376d0b7c91ec22f28f9e0b29c527afac Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 8 Apr 2023 09:54:15 +0400 Subject: [PATCH] Avoid event loop being throttled by OpenGL By default, Qt uses swap interval of 1 what causes the (egl|wgl|glx)SwapBuffers call to wait for vblank. Using swap interval of 0 makes the call to return immediately. --- ui/rp_widget.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ui/rp_widget.cpp b/ui/rp_widget.cpp index afa77b9..35fbe2f 100644 --- a/ui/rp_widget.cpp +++ b/ui/rp_widget.cpp @@ -44,6 +44,12 @@ public: TWidget::TWidget(QWidget *parent) : TWidgetHelper(*(new TWidgetPrivate), parent, {}) { + [[maybe_unused]] static const auto Once = [] { + auto format = QSurfaceFormat::defaultFormat(); + format.setSwapInterval(0); + QSurfaceFormat::setDefaultFormat(format); + return true; + }(); } namespace Ui {