ref: 66f090f08bca46ce8705a892600611db0ea686bf
parent: aafbdbb8a3f68d5847cfbdb9e18d21e6f6333c9d
author: Fabian Greffrath <fabian@greffrath.com>
date: Sat Sep 19 16:55:19 EDT 2015
Video: Vast improvements to the CreateUpscaledTexture() algorithm - Now there are separate upscale factors for horizontal and vertical directions. - Before calculating upscale factors, the actual dimensions of the rendered area are taken into account. - If the screen dimension matches an integer multiple of the original resolution in one direction, it not necessary to overscale into this direction. - Cap the maximum texture dimension at 1600x1200.
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1020,33 +1020,67 @@
static void CreateUpscaledTexture(int w, int h)
{
- const int w_scale = (w / SCREENWIDTH) + 1;
- const int h_scale = (h / SCREENHEIGHT) + 1;
- int upscale;
- static int upscale_old;
+ const int actualheight = aspect_ratio_correct ?
+ SCREENHEIGHT_4_3 :
+ SCREENHEIGHT;
+ int h_upscale, w_upscale;
+ static int h_upscale_old, w_upscale_old;
// When the screen or window dimensions do not match the aspect ratio
- // of the texture, the rendered area is scaled down to fit
+ // of the texture, the rendered area is scaled down to fit. Calculate
+ // the actual dimensions of the rendered area.
- upscale = (w_scale < h_scale) ? w_scale : h_scale;
+ if (w * actualheight < h * SCREENWIDTH)
+ {
+ // Tall window.
- // Limit upscaling factor to 6 (1920x1200)
+ h = w * actualheight / SCREENWIDTH;
+ }
+ else
+ {
+ // Wide window.
- if (upscale < 2)
+ w = h * SCREENWIDTH / actualheight;
+ }
+
+ // If one screen dimension matches an integer multiple of the original
+ // resolution, there is no need to overscale in this direction.
+
+ h_upscale = h / SCREENHEIGHT;
+
+ if (!h || h % SCREENHEIGHT)
{
- upscale = 2;
+ h_upscale++;
}
- else if (upscale > 6)
+
+ w_upscale = w / SCREENWIDTH;
+
+ if (!w || w % SCREENWIDTH)
{
- upscale = 6;
+ w_upscale++;
}
- if (upscale == upscale_old)
+ // Limit maximum texture dimensions to 1600x1200.
+
+ if (h_upscale > 6)
{
+ h_upscale = 6;
+ }
+
+ if (w_upscale > 5)
+ {
+ w_upscale = 5;
+ }
+
+ // Create a new texture only if the upscale factors have actually changed.
+
+ if (h_upscale == h_upscale_old && w_upscale == w_upscale_old)
+ {
return;
}
- upscale_old = upscale;
+ h_upscale_old = h_upscale;
+ w_upscale_old = w_upscale;
if (texture_upscaled)
{
@@ -1062,7 +1096,8 @@
texture_upscaled = SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_TARGET,
- upscale*SCREENWIDTH, upscale*SCREENHEIGHT);
+ w_upscale*SCREENWIDTH,
+ h_upscale*SCREENHEIGHT);
}
//