Skip to content

Commit

Permalink
[macOS] Workaround for changing vsync at runtime in Vulkan mode
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 17, 2024
1 parent 277bccb commit 94cc6db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/framework/wzapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ bool wzChangeWindowMode(WINDOW_MODE mode, bool silent = false);
WINDOW_MODE wzGetCurrentWindowMode();
bool wzIsFullscreen();
void wzSetWindowIsResizable(bool resizable);
void wzPostChangedSwapInterval();
bool wzIsWindowResizable();
bool wzChangeDisplayScale(unsigned int displayScale);
bool wzChangeCursorScale(unsigned int cursorScale);
Expand Down
33 changes: 33 additions & 0 deletions lib/sdl/main_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,39 @@ WINDOW_MODE wzGetToggleFullscreenMode()
return altEnterToggleFullscreenMode;
}

void wzPostChangedSwapInterval()
{
#ifdef WZ_OS_MAC
if (WZbackend == video_backend::vulkan)
{
// If using Vulkan backend (and, thus, MoltenVK),
// Workaround MoltenVK issue (doesn't seem to fully accept the recreated swapchain until window resize event?)
// - Trigger a window resize event (regardless of current window mode)
auto currentMode = wzGetCurrentWindowMode();
switch (currentMode)
{
case WINDOW_MODE::desktop_fullscreen:
case WINDOW_MODE::fullscreen:
if (wzChangeWindowMode(WINDOW_MODE::windowed))
{
wzChangeWindowMode(currentMode);
}
break;
case WINDOW_MODE::windowed:
int currWidth = 0, currHeight = 0;
SDL_GetWindowSize(WZwindow, &currWidth, &currHeight);

// set one bigger than current size
SDL_SetWindowSize(WZwindow, currWidth+1, currHeight+1);

// restore the old windowed size
SDL_SetWindowSize(WZwindow, currWidth, currHeight);
break;
}
}
#endif
}

bool wzChangeWindowMode(WINDOW_MODE mode, bool silent)
{
auto previousMode = wzGetCurrentWindowMode();
Expand Down
1 change: 1 addition & 0 deletions src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,7 @@ void seqVsyncMode()
{
// succeeded changing vsync mode
saveCurrentSwapMode(currentVsyncMode);
wzPostChangedSwapInterval();
}
}

Expand Down

0 comments on commit 94cc6db

Please sign in to comment.