From 8a0bb50ecaeafc7ff847deb1ccd5d7241e7338de Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Thu, 27 Apr 2023 04:27:04 +0700 Subject: [PATCH] factor calculation for upscaled_texture from Crispy Doom (#1019) * factor calculation for upscaled_texture from Crispy Doom * use SDL_GetDesktopDisplayMode istead of SDL_GetRendererOutputSize --- src/i_video.c | 82 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/src/i_video.c b/src/i_video.c index eb380869..7ec8cb4b 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -1423,6 +1423,64 @@ void I_GetScreenDimensions(void) WIDESCREENDELTA = (SCREENWIDTH - NONWIDEWIDTH) / 2; } +static void CreateUpscaledTexture(int v_w, int v_h) +{ + SDL_RendererInfo info; + SDL_DisplayMode mode; + int w_upscale, h_upscale; + + SDL_GetRendererInfo(renderer, &info); + + if (info.flags & SDL_RENDERER_SOFTWARE) + { + return; + } + + SDL_GetDesktopDisplayMode(video_display, &mode); + + // Pick texture size the next integer multiple of the screen dimensions. + // If one screen dimension matches an integer multiple of the original + // resolution, there is no need to overscale in this direction. + + w_upscale = (mode.w + v_w - 1) / v_w; + h_upscale = (mode.h + v_h - 1) / v_h; + + while (w_upscale * v_w > info.max_texture_width) + { + --w_upscale; + } + while (h_upscale * v_h > info.max_texture_height) + { + --h_upscale; + } + + if (w_upscale < 1) + { + w_upscale = 1; + } + if (h_upscale < 1) + { + h_upscale = 1; + } + + if (texture_upscaled != NULL) + { + SDL_DestroyTexture(texture_upscaled); + } + + // Set the scaling quality for rendering the upscaled texture + // to "linear", which looks much softer and smoother than "nearest" + // but does a better job at downscaling from the upscaled texture to + // screen. + + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); + + texture_upscaled = SDL_CreateTexture(renderer, + SDL_GetWindowPixelFormat(screen), + SDL_TEXTUREACCESS_TARGET, + w_upscale* v_w, h_upscale * v_h); +} + // // killough 11/98: New routine, for setting hires and page flipping // @@ -1757,29 +1815,7 @@ static void I_InitGraphicsMode(void) if (bilinear_sharpening) { - SDL_RendererInfo info; - - SDL_GetRendererInfo(renderer, &info); - - if (!(info.flags & SDL_RENDERER_SOFTWARE)) - { - if (texture_upscaled != NULL) - { - SDL_DestroyTexture(texture_upscaled); - } - - // Set the scaling quality for rendering the upscaled texture - // to "linear", which looks much softer and smoother than "nearest" - // but does a better job at downscaling from the upscaled texture to - // screen. - - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); - - texture_upscaled = SDL_CreateTexture(renderer, - pixel_format, - SDL_TEXTUREACCESS_TARGET, - v_w * 2, v_h * 2); - } + CreateUpscaledTexture(v_w, v_h); } UpdateGrab();