Fixed bug 5424 - Renderer doesn't use entirely the viewport when scaling is used

Viewport/Clip dimensions are calculated usingg SDL_ceil whereas all renders use SDL_floor
This commit is contained in:
Sylvain Becker 2020-12-30 16:12:14 +01:00
parent a88071deb5
commit 590a5469ed
1 changed files with 10 additions and 10 deletions

View File

@ -2007,9 +2007,9 @@ UpdateLogicalSize(SDL_Renderer *renderer)
} else { } else {
scale = (float)(h / renderer->logical_h); scale = (float)(h / renderer->logical_h);
} }
viewport.w = (int)SDL_ceil(renderer->logical_w * scale); viewport.w = (int)SDL_floor(renderer->logical_w * scale);
viewport.x = (w - viewport.w) / 2; viewport.x = (w - viewport.w) / 2;
viewport.h = (int)SDL_ceil(renderer->logical_h * scale); viewport.h = (int)SDL_floor(renderer->logical_h * scale);
viewport.y = (h - viewport.h) / 2; viewport.y = (h - viewport.h) / 2;
SDL_RenderSetViewport(renderer, &viewport); SDL_RenderSetViewport(renderer, &viewport);
@ -2026,7 +2026,7 @@ UpdateLogicalSize(SDL_Renderer *renderer)
scale = (float)h / renderer->logical_h; scale = (float)h / renderer->logical_h;
viewport.y = 0; viewport.y = 0;
viewport.h = h; viewport.h = h;
viewport.w = (int)SDL_ceil(renderer->logical_w * scale); viewport.w = (int)SDL_floor(renderer->logical_w * scale);
viewport.x = (w - viewport.w) / 2; viewport.x = (w - viewport.w) / 2;
SDL_RenderSetViewport(renderer, &viewport); SDL_RenderSetViewport(renderer, &viewport);
} else { } else {
@ -2034,7 +2034,7 @@ UpdateLogicalSize(SDL_Renderer *renderer)
scale = (float)w / renderer->logical_w; scale = (float)w / renderer->logical_w;
viewport.x = 0; viewport.x = 0;
viewport.w = w; viewport.w = w;
viewport.h = (int)SDL_ceil(renderer->logical_h * scale); viewport.h = (int)SDL_floor(renderer->logical_h * scale);
viewport.y = (h - viewport.h) / 2; viewport.y = (h - viewport.h) / 2;
SDL_RenderSetViewport(renderer, &viewport); SDL_RenderSetViewport(renderer, &viewport);
} }
@ -2047,7 +2047,7 @@ UpdateLogicalSize(SDL_Renderer *renderer)
scale = (float)w / renderer->logical_w; scale = (float)w / renderer->logical_w;
viewport.x = 0; viewport.x = 0;
viewport.w = w; viewport.w = w;
viewport.h = (int)SDL_ceil(renderer->logical_h * scale); viewport.h = (int)SDL_floor(renderer->logical_h * scale);
viewport.y = (h - viewport.h) / 2; viewport.y = (h - viewport.h) / 2;
SDL_RenderSetViewport(renderer, &viewport); SDL_RenderSetViewport(renderer, &viewport);
} else { } else {
@ -2055,7 +2055,7 @@ UpdateLogicalSize(SDL_Renderer *renderer)
scale = (float)h / renderer->logical_h; scale = (float)h / renderer->logical_h;
viewport.y = 0; viewport.y = 0;
viewport.h = h; viewport.h = h;
viewport.w = (int)SDL_ceil(renderer->logical_w * scale); viewport.w = (int)SDL_floor(renderer->logical_w * scale);
viewport.x = (w - viewport.w) / 2; viewport.x = (w - viewport.w) / 2;
SDL_RenderSetViewport(renderer, &viewport); SDL_RenderSetViewport(renderer, &viewport);
} }
@ -2127,8 +2127,8 @@ SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect)
if (rect) { if (rect) {
renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x); renderer->viewport.x = (int)SDL_floor(rect->x * renderer->scale.x);
renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y); renderer->viewport.y = (int)SDL_floor(rect->y * renderer->scale.y);
renderer->viewport.w = (int)SDL_ceil(rect->w * renderer->scale.x); renderer->viewport.w = (int)SDL_floor(rect->w * renderer->scale.x);
renderer->viewport.h = (int)SDL_ceil(rect->h * renderer->scale.y); renderer->viewport.h = (int)SDL_floor(rect->h * renderer->scale.y);
} else { } else {
renderer->viewport.x = 0; renderer->viewport.x = 0;
renderer->viewport.y = 0; renderer->viewport.y = 0;
@ -2163,8 +2163,8 @@ SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
renderer->clipping_enabled = SDL_TRUE; renderer->clipping_enabled = SDL_TRUE;
renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x); renderer->clip_rect.x = (int)SDL_floor(rect->x * renderer->scale.x);
renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y); renderer->clip_rect.y = (int)SDL_floor(rect->y * renderer->scale.y);
renderer->clip_rect.w = (int)SDL_ceil(rect->w * renderer->scale.x); renderer->clip_rect.w = (int)SDL_floor(rect->w * renderer->scale.x);
renderer->clip_rect.h = (int)SDL_ceil(rect->h * renderer->scale.y); renderer->clip_rect.h = (int)SDL_floor(rect->h * renderer->scale.y);
} else { } else {
renderer->clipping_enabled = SDL_FALSE; renderer->clipping_enabled = SDL_FALSE;
SDL_zero(renderer->clip_rect); SDL_zero(renderer->clip_rect);