From b30c8ed942f2f32bea067a15e77c4c5a62158404 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 18 Mar 2021 07:47:40 +0100 Subject: Fix disabling vsync for frame-count shell The frame-count shell depends on disabling vsync to be able to render as many frames as it can during 20 seconds. But the logic was inverted in the condition that checked for the --shell parameter, so the frame-count shell would never be detected and the swap interval would never be set to 0. This patch also updates the logic to take into consideration that frame-count is the default now, so it will default to disabling vsync. Change-Id: I9d866a7fddfa46266ba1c8245b84e8389e00b154 Reviewed-by: Daniel Smith --- src/main.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7528e34..a57b3e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -241,22 +241,23 @@ QStringList processCommandLineArguments(const QCoreApplication &app) void setupDefaultSurfaceFormat(int argc, char **argv) { - bool expectingShell = false; + bool frameCountShell = true; // default for (int i = 0; i < argc; ++i) { - if (strcmp(argv[i], "--shell")) { - expectingShell = true; - } else if (expectingShell && strcmp(argv[i], "frame-count") == 0) { - QSurfaceFormat format = QSurfaceFormat::defaultFormat(); + if (strcmp(argv[i], "--shell") == 0 && i < argc - 1) { + if (strcmp(argv[i + 1], "frame-count") != 0) + frameCountShell = false; + } + } + + if (frameCountShell) { + QSurfaceFormat format = QSurfaceFormat::defaultFormat(); #if QT_VERSION >= 0x050300 - format.setSwapInterval(0); + format.setSwapInterval(0); #else - fprintf(stderr, "Cannot disable swap interval on this Qt version, frame-count shell won't work properly!\n"); - ::exit(1); + fprintf(stderr, "Cannot disable swap interval on this Qt version, frame-count shell won't work properly!\n"); + ::exit(1); #endif - QSurfaceFormat::setDefaultFormat(format); - } else { - expectingShell = false; - } + QSurfaceFormat::setDefaultFormat(format); } } -- cgit v1.2.3