render: Update the size/scale/viewport on moves, in addition to resizes. For OpenGL this means resetting the viewport state shadowing flag too. Fixes #1504
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 471e8c0..9bb953e 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -698,7 +698,17 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
renderer->WindowEvent(renderer, &event->window);
}
- if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+ /* In addition to size changes, we also want to do this block for
+ * moves as well, for two reasons:
+ *
+ * 1. The window could be moved to a new display, which has a new
+ * DPI and therefore a new window/drawable ratio
+ * 2. For whatever reason, the viewport can get messed up during
+ * window movement (this has been observed on macOS), so this is
+ * also a good opportunity to force viewport updates
+ */
+ if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED ||
+ event->window.event == SDL_WINDOWEVENT_MOVED) {
/* Make sure we're operating on the default render target */
SDL_Texture *saved_target = SDL_GetRenderTarget(renderer);
if (saved_target) {
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index e7c5169..a0ff1e2 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -324,6 +324,20 @@ GL_GetFBO(GL_RenderData *data, Uint32 w, Uint32 h)
return result;
}
+static void
+GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
+{
+ /* If the window x/y/w/h changed at all, assume the viewport has been
+ * changed behind our backs. x/y changes might seem weird but viewport
+ * resets have been observed on macOS at minimum!
+ */
+ if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED ||
+ event->event == SDL_WINDOWEVENT_MOVED) {
+ GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
+ data->drawstate.viewport_dirty = SDL_TRUE;
+ }
+}
+
static int
GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
{
@@ -1216,13 +1230,6 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
}
}
-#ifdef __MACOSX__
- // On macOS, moving the window seems to invalidate the OpenGL viewport state,
- // so don't bother trying to persist it across frames; always reset it.
- // Workaround for: https://github.com/libsdl-org/SDL/issues/1504
- data->drawstate.viewport_dirty = SDL_TRUE;
-#endif
-
while (cmd) {
switch (cmd->command) {
case SDL_RENDERCMD_SETDRAWCOLOR: {
@@ -1767,6 +1774,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
goto error;
}
+ renderer->WindowEvent = GL_WindowEvent;
renderer->GetOutputSize = GL_GetOutputSize;
renderer->SupportsBlendMode = GL_SupportsBlendMode;
renderer->CreateTexture = GL_CreateTexture;