From cb0abd51dbad857fc8df60dfb775530b31229aa7 Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Wed, 18 May 2022 23:46:27 +0200 Subject: [PATCH] RenderingManager: FPS software limiter even with VSYNC V-sync on multiple windows is not always performing well. So limiting to 61 FPS works with both VSYNC at 60FPS or without VSYNC. This means the settings for VSYNC is useless (removed from Settings panel). --- RenderingManager.cpp | 40 ++++++++++++++++++++-------------------- UserInterfaceManager.cpp | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/RenderingManager.cpp b/RenderingManager.cpp index d85918d..808f7e8 100644 --- a/RenderingManager.cpp +++ b/RenderingManager.cpp @@ -1,4 +1,4 @@ -/* +/* * This file is part of vimix - video live mixer * * **Copyright** (C) 2019-2022 Bruno Herbelin @@ -311,6 +311,13 @@ void Rendering::pushBackDrawCallback(RenderingCallback function) void Rendering::draw() { + // Poll and handle events (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + glfwPollEvents(); + // change windows fullscreen mode if requested main_.toggleFullscreen_(); output_.toggleFullscreen_(); @@ -338,28 +345,21 @@ void Rendering::draw() request_screenshot_ = false; } + // software framerate limiter < 61 FPS + { + static GTimer *timer = g_timer_new (); + double elapsed = g_timer_elapsed (timer, NULL) * 1000000.0; + if ( (elapsed < 16390.0) && (elapsed > 0.0) ) + g_usleep( 16390 - (gulong)elapsed ); + g_timer_start(timer); + } + // swap GL buffers glfwSwapBuffers(main_.window()); // draw output window (and swap buffer output) output_.draw( Mixer::manager().session()->frame() ); - // software framerate limiter 60FPS if not v-sync - if ( Settings::application.render.vsync < 1 ) { - static GTimer *timer = g_timer_new (); - double elapsed = g_timer_elapsed (timer, NULL) * 1000000.0; - if ( (elapsed < 16000.0) && (elapsed > 0.0) ) - g_usleep( 16000 - (gulong)elapsed ); - g_timer_start(timer); - } - - // Poll and handle events (inputs, window resize, etc.) - // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. - // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. - // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. - // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. - glfwPollEvents(); - } void Rendering::terminate() @@ -983,13 +983,13 @@ void RenderingWindow::draw(FrameBuffer *fb) glBindTexture(GL_TEXTURE_2D, 0); } + // restore attribs + Rendering::manager().popAttrib(); + // swap buffer glfwSwapBuffers(window_); } - // restore attribs - Rendering::manager().popAttrib(); - // give back context ownership glfwMakeContextCurrent(master_); } diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 9ad1b0c..8658019 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -7281,9 +7281,9 @@ void Navigator::RenderMainPannelSettings() static bool multi = (Settings::application.render.multisampling > 0); static bool gpu = Settings::application.render.gpu_decoding; bool change = false; - change |= ImGuiToolkit::ButtonSwitch( "Vertical synchronization", &vsync); change |= ImGuiToolkit::ButtonSwitch( "Blit framebuffer", &blit); #ifndef NDEBUG + change |= ImGuiToolkit::ButtonSwitch( "Vertical synchronization", &vsync); change |= ImGuiToolkit::ButtonSwitch( "Antialiasing framebuffer", &multi); #endif // hardware support deserves more explanation