mirror of
https://github.com/libsdl-org/SDL.git
synced 2024-11-30 23:33:42 +08:00
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
This commit is contained in:
parent
5613a56032
commit
cb81630816
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user