From e6f84e14b45c302084e2f471eab762f2622347c8 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Sat, 12 Jul 2025 18:02:48 +0200 Subject: [PATCH 1/4] add event watch for window exposed Disabled on linux since it introduces really bad flickering on resize, and is not needed anyway since linux does not lock your main thread while you're changing the window --- Source/Managers/WindowMan.cpp | 17 +++++++++++++++-- Source/Managers/WindowMan.h | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Source/Managers/WindowMan.cpp b/Source/Managers/WindowMan.cpp index 49fe98d19..7aef2ada3 100644 --- a/Source/Managers/WindowMan.cpp +++ b/Source/Managers/WindowMan.cpp @@ -1,7 +1,6 @@ #include "WindowMan.h" #include "RTEError.h" -#include "SDL3/SDL_error.h" -#include "SDL3/SDL_video.h" +#include "SDL3/SDL.h" #include "SettingsMan.h" #include "FrameMan.h" #include "ActivityMan.h" @@ -155,6 +154,10 @@ void WindowMan::Initialize() { } else { SetViewportLetterboxed(); } + +#ifdef _WIN32 + SDL_AddEventWatch((SDL_EventFilter)WindowMan::HandleWindowExposedEvent, nullptr); +#endif } void WindowMan::CreatePrimaryWindow() { @@ -674,6 +677,15 @@ void WindowMan::DisplaySwitchOut() const { SDL_SetCursor(nullptr); } +void WindowMan::HandleWindowExposedEvent(void *userdata, SDL_Event *event) { + if (event->type == SDL_EVENT_WINDOW_EXPOSED) { + g_WindowMan.SetViewportLetterboxed(); + g_WindowMan.ClearBackbuffer(false); + g_WindowMan.UploadFrame(); + g_WindowMan.Present(); + } +} + void WindowMan::QueueWindowEvent(const SDL_Event& windowEvent) { m_EventQueue.emplace_back(windowEvent); } @@ -722,6 +734,7 @@ void WindowMan::Update() { case SDL_EVENT_WINDOW_RESIZED: case SDL_WINDOW_MAXIMIZED: SetViewportLetterboxed(); + std::cout << "resize" << std::endl; break; default: break; diff --git a/Source/Managers/WindowMan.h b/Source/Managers/WindowMan.h index b8ca28997..1148bad7f 100644 --- a/Source/Managers/WindowMan.h +++ b/Source/Managers/WindowMan.h @@ -168,6 +168,9 @@ namespace RTE { #pragma endregion #pragma region Concrete Methods + /// SDL_EventFilter to hadnle window exposed events for live resize. + static void HandleWindowExposedEvent(void* userdata, SDL_Event* event); + /// Adds an SDL_Event to the Event queue for processing on Update. /// @param windowEvent The SDL window event to queue. void QueueWindowEvent(const SDL_Event& windowEvent); From 621bbca40b47d1e07333d9e2ee88cd4cce88f2d0 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Sat, 12 Jul 2025 18:08:01 +0200 Subject: [PATCH 2/4] remove debug print --- Source/Managers/WindowMan.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Managers/WindowMan.cpp b/Source/Managers/WindowMan.cpp index 7aef2ada3..1843089e2 100644 --- a/Source/Managers/WindowMan.cpp +++ b/Source/Managers/WindowMan.cpp @@ -734,7 +734,6 @@ void WindowMan::Update() { case SDL_EVENT_WINDOW_RESIZED: case SDL_WINDOW_MAXIMIZED: SetViewportLetterboxed(); - std::cout << "resize" << std::endl; break; default: break; From dff8b3749de9917be6dfc0735f9680f6156d1c86 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Sun, 13 Jul 2025 01:02:49 +0200 Subject: [PATCH 3/4] oops --- Source/Managers/WindowMan.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Managers/WindowMan.cpp b/Source/Managers/WindowMan.cpp index 1843089e2..0bf5aeed5 100644 --- a/Source/Managers/WindowMan.cpp +++ b/Source/Managers/WindowMan.cpp @@ -682,7 +682,6 @@ void WindowMan::HandleWindowExposedEvent(void *userdata, SDL_Event *event) { g_WindowMan.SetViewportLetterboxed(); g_WindowMan.ClearBackbuffer(false); g_WindowMan.UploadFrame(); - g_WindowMan.Present(); } } From fd03dec70aefa393346e3fdf8532e8cc637b1199 Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Sun, 13 Jul 2025 01:12:01 +0200 Subject: [PATCH 4/4] enable expose watcher everywhere, turns out macos does want it as well, and it doesn't hurt on linux --- Source/Managers/WindowMan.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Managers/WindowMan.cpp b/Source/Managers/WindowMan.cpp index 0bf5aeed5..b5997cd3b 100644 --- a/Source/Managers/WindowMan.cpp +++ b/Source/Managers/WindowMan.cpp @@ -155,9 +155,7 @@ void WindowMan::Initialize() { SetViewportLetterboxed(); } -#ifdef _WIN32 SDL_AddEventWatch((SDL_EventFilter)WindowMan::HandleWindowExposedEvent, nullptr); -#endif } void WindowMan::CreatePrimaryWindow() {