1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-02 02:53:32 +02:00

Always update scaling before rendering

This fixes the following bug that only occurs on Wayland: If the game is
configured to be fullscreened and in stretch mode, on startup, it won't
be in stretch mode. It will appear to be in letterbox mode, but the game
still thinks it's in stretch mode.

This is because during the ResizeScreen() call on startup, for whatever
reason, the window size will be reported to be the default size (640 by
480) instead of the screen resolution of the monitor, as one would
expect from being in fullscreen. It seems like when the game queries the
window size, the window isn't actually in fullscreen at that time, even
though this is after fullscreen has been set to true.

To fix this, I decided to always update the logical size before
SDL_RenderPresent() is called. To make this neater, I put the scaling
code in its own function named UpdateScaling().

This bug has existed since 2.3 and does not occur on X11. I tested this
on GNOME Wayland, and for testing it on X11, I used Openbox in a Xephyr
session while running VVVVVV with SDL_VIDEODRIVER=x11.
This commit is contained in:
Misa 2023-03-20 20:31:31 -07:00
parent 64874065eb
commit e1e9e47d95
2 changed files with 33 additions and 28 deletions

View File

@ -170,33 +170,6 @@ void Screen::ResizeScreen(int x, int y)
SDL_SetWindowPosition(m_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
}
if (scalingMode == SCALING_STRETCH)
{
int winX, winY;
GetWindowSize(&winX, &winY);
int result = SDL_RenderSetLogicalSize(m_renderer, winX, winY);
if (result != 0)
{
vlog_error("Error: could not set logical size: %s", SDL_GetError());
return;
}
result = SDL_RenderSetIntegerScale(m_renderer, SDL_FALSE);
if (result != 0)
{
vlog_error("Error: could not set scale: %s", SDL_GetError());
return;
}
}
else
{
SDL_RenderSetLogicalSize(m_renderer, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS);
int result = SDL_RenderSetIntegerScale(m_renderer, (SDL_bool) (scalingMode == SCALING_INTEGER));
if (result != 0)
{
vlog_error("Error: could not set scale: %s", SDL_GetError());
return;
}
}
}
void Screen::ResizeToNearestMultiple(void)
@ -267,8 +240,39 @@ void Screen::GetWindowSize(int* x, int* y)
}
}
void Screen::UpdateScaling(void)
{
int width;
int height;
if (scalingMode == SCALING_STRETCH)
{
GetWindowSize(&width, &height);
}
else
{
width = SCREEN_WIDTH_PIXELS;
height = SCREEN_HEIGHT_PIXELS;
}
int result = SDL_RenderSetLogicalSize(m_renderer, width, height);
if (result != 0)
{
vlog_error("Error: could not set logical size: %s", SDL_GetError());
return;
}
result = SDL_RenderSetIntegerScale(m_renderer, (SDL_bool) (scalingMode == SCALING_INTEGER));
if (result != 0)
{
vlog_error("Error: could not set scale: %s", SDL_GetError());
}
}
void Screen::RenderPresent(void)
{
/* In certain cases, the window size might mismatch with the logical size.
* So it's better to just always call this. */
UpdateScaling();
SDL_RenderPresent(m_renderer);
graphics.clear();
}
@ -288,7 +292,7 @@ void Screen::toggleFullScreen(void)
void Screen::toggleScalingMode(void)
{
scalingMode = (scalingMode + 1) % NUM_SCALING_MODES;
ResizeScreen(-1, -1);
UpdateScaling();
}
void Screen::toggleLinearFilter(void)

View File

@ -19,6 +19,7 @@ public:
void ResizeToNearestMultiple(void);
void GetWindowSize(int* x, int* y);
void UpdateScaling(void);
void RenderPresent(void);
void toggleFullScreen(void);