Skip to content

Commit e6f84e1

Browse files
committed
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
1 parent 605ff23 commit e6f84e1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Source/Managers/WindowMan.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "WindowMan.h"
22
#include "RTEError.h"
3-
#include "SDL3/SDL_error.h"
4-
#include "SDL3/SDL_video.h"
3+
#include "SDL3/SDL.h"
54
#include "SettingsMan.h"
65
#include "FrameMan.h"
76
#include "ActivityMan.h"
@@ -155,6 +154,10 @@ void WindowMan::Initialize() {
155154
} else {
156155
SetViewportLetterboxed();
157156
}
157+
158+
#ifdef _WIN32
159+
SDL_AddEventWatch((SDL_EventFilter)WindowMan::HandleWindowExposedEvent, nullptr);
160+
#endif
158161
}
159162

160163
void WindowMan::CreatePrimaryWindow() {
@@ -674,6 +677,15 @@ void WindowMan::DisplaySwitchOut() const {
674677
SDL_SetCursor(nullptr);
675678
}
676679

680+
void WindowMan::HandleWindowExposedEvent(void *userdata, SDL_Event *event) {
681+
if (event->type == SDL_EVENT_WINDOW_EXPOSED) {
682+
g_WindowMan.SetViewportLetterboxed();
683+
g_WindowMan.ClearBackbuffer(false);
684+
g_WindowMan.UploadFrame();
685+
g_WindowMan.Present();
686+
}
687+
}
688+
677689
void WindowMan::QueueWindowEvent(const SDL_Event& windowEvent) {
678690
m_EventQueue.emplace_back(windowEvent);
679691
}
@@ -722,6 +734,7 @@ void WindowMan::Update() {
722734
case SDL_EVENT_WINDOW_RESIZED:
723735
case SDL_WINDOW_MAXIMIZED:
724736
SetViewportLetterboxed();
737+
std::cout << "resize" << std::endl;
725738
break;
726739
default:
727740
break;

Source/Managers/WindowMan.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ namespace RTE {
168168
#pragma endregion
169169

170170
#pragma region Concrete Methods
171+
/// SDL_EventFilter to hadnle window exposed events for live resize.
172+
static void HandleWindowExposedEvent(void* userdata, SDL_Event* event);
173+
171174
/// Adds an SDL_Event to the Event queue for processing on Update.
172175
/// @param windowEvent The SDL window event to queue.
173176
void QueueWindowEvent(const SDL_Event& windowEvent);

0 commit comments

Comments
 (0)