diff --git a/pcsx2/GS/GS.cpp b/pcsx2/GS/GS.cpp index 434721ef53940..384d9199cf0fd 100644 --- a/pcsx2/GS/GS.cpp +++ b/pcsx2/GS/GS.cpp @@ -701,7 +701,7 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config) // Handle OSD scale changes by pushing a window resize through. if (new_config.OsdScale != old_config.OsdScale) - ImGuiManager::WindowResized(); + ImGuiManager::RequestScaleUpdate(); // Options which need a full teardown/recreate. if (!GSConfig.RestartOptionsAreEqual(old_config)) diff --git a/pcsx2/ImGui/ImGuiManager.cpp b/pcsx2/ImGui/ImGuiManager.cpp index b27404435dd84..f4534db28a3b4 100644 --- a/pcsx2/ImGui/ImGuiManager.cpp +++ b/pcsx2/ImGui/ImGuiManager.cpp @@ -47,6 +47,7 @@ namespace ImGuiManager std::pair pos; }; + static void UpdateScale(); static void SetStyle(); static void SetKeyMap(); static bool LoadFontData(); @@ -96,6 +97,7 @@ static constexpr float OSD_FADE_OUT_TIME = 0.4f; // need to keep track of this, so we can reinitialize on renderer switch static bool s_fullscreen_ui_was_initialized = false; +static bool s_scale_changed = false; static std::array s_software_cursors = {}; @@ -134,6 +136,7 @@ bool ImGuiManager::Initialize() } s_global_scale = std::max(0.5f, g_gs_device->GetWindowScale() * (GSConfig.OsdScale / 100.0f)); + s_scale_changed = false; ImGui::CreateContext(); @@ -225,11 +228,13 @@ void ImGuiManager::WindowResized() s_window_height = static_cast(new_height); ImGui::GetIO().DisplaySize = ImVec2(s_window_width, s_window_height); - UpdateScale(); + // Scale might have changed as a result of window resize. + RequestScaleUpdate(); +} - // restart imgui frame on the new window size to pick it up, otherwise we draw to the old size - ImGui::EndFrame(); - NewFrame(); +void ImGuiManager::RequestScaleUpdate() +{ + s_scale_changed = true; } void ImGuiManager::UpdateScale() @@ -240,9 +245,6 @@ void ImGuiManager::UpdateScale() if ((!HasFullscreenFonts() || !ImGuiFullscreen::UpdateLayoutScale()) && scale == s_global_scale) return; - // This is assumed to be called mid-frame. - ImGui::EndFrame(); - s_global_scale = scale; SetStyle(); @@ -251,8 +253,6 @@ void ImGuiManager::UpdateScale() if (!g_gs_device->UpdateImGuiFontTexture()) pxFailRel("Failed to recreate font texture after scale+resize"); - - NewFrame(); } void ImGuiManager::NewFrame() @@ -260,6 +260,12 @@ void ImGuiManager::NewFrame() ImGuiIO& io = ImGui::GetIO(); io.DeltaTime = s_last_render_time.GetTimeSecondsAndReset(); + if (s_scale_changed) + { + s_scale_changed = false; + UpdateScale(); + } + ImGui::NewFrame(); // Disable nav input on the implicit (Debug##Default) window. Otherwise we end up requesting keyboard diff --git a/pcsx2/ImGui/ImGuiManager.h b/pcsx2/ImGui/ImGuiManager.h index 05efa9577e681..52d2ef9a89927 100644 --- a/pcsx2/ImGui/ImGuiManager.h +++ b/pcsx2/ImGui/ImGuiManager.h @@ -35,7 +35,7 @@ namespace ImGuiManager void WindowResized(); /// Updates scaling of the on-screen elements. - void UpdateScale(); + void RequestScaleUpdate(); /// Call at the beginning of the frame to set up ImGui state. void NewFrame();