From 0c7851bd2699b773d59f44e181dddbfcc2a0cfa2 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 03:13:17 +0100 Subject: [PATCH] try to clean up downsampling and resolution checking stuff - global function that updates variables with current display resolution -smol boolean function that quickly checks if the game res matches the desktop res - i_downsample has been simplyfied a bit --- src/sdl/i_video.c | 84 ++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 524be7885..a7538ba6c 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -128,6 +128,11 @@ consvar_t cv_keyboardlayout = {"keyboardlayout", "Default US", CV_SAVE|CV_CALL, static void Impl_SetVsync(void); +static INT32 desktopwidth = 0, desktopheight = 0; + +static void I_CheckDesktopRes(void); +static void I_ResetFBOSurface(void); + // synchronize page flipping with screen refresh consvar_t cv_vidwait = {"vid_wait", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Impl_SetVsync, 0, NULL, NULL, 0, 0, NULL}; static consvar_t cv_stretch = {"stretch", "Off", CV_SAVE|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -274,6 +279,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) #ifdef HWRENDER if (rendermode == render_opengl) { + I_CheckDesktopRes(); #ifdef USE_FBO_OGL I_DownSample(); #endif @@ -695,21 +701,14 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } -boolean I_CheckNativeRes(void) +static void I_CheckDesktopRes(void) { - static INT32 oldwidth = 0, oldheight = 0; - static boolean resstate = false; int currentDisplayIndex = -1; SDL_DisplayMode curmode; - if (cv_glscreentextures.value == 0) + if (desktopwidth == vid.width && desktopheight == vid.height) { - return false; - } - - if (oldwidth == vid.width && oldheight == vid.height) - { - return resstate; + return; } currentDisplayIndex = SDL_GetWindowDisplayIndex(window); @@ -717,72 +716,68 @@ boolean I_CheckNativeRes(void) // No valid index if (currentDisplayIndex < 0) { - return false; + return; } if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) != 0) { - return false; + return; } - resstate = ((vid.width == curmode.w) && (vid.height == curmode.h)); - oldwidth = vid.width; - oldheight = vid.height; + desktopwidth = curmode.w; + desktopheight = curmode.h; +} - return resstate; +boolean I_CheckNativeRes(void) +{ + return (vid.width == desktopwidth && vid.height == desktopheight); } #ifdef USE_FBO_OGL void I_DownSample(void) { - int currentDisplayIndex = -1; - SDL_DisplayMode curmode; + boolean needrefresh = false; - if (!cv_glframebuffer.value || !supportFBO || I_CheckNativeRes()) //no sense to do this crap if we cant benefit from it + if (!cv_glframebuffer.value || !supportFBO || (cv_glscreentextures.value == 0)) // no sense to do this crap if we cant benefit from it { downsample = false; return; } - currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - - // No valid index - if (currentDisplayIndex < 0) + if (I_CheckNativeRes() && (downsample == true)) { downsample = false; + I_ResetFBOSurface(); return; } - if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) != 0) - { - downsample = false; // couldnt get display info so turn the thing off - RefreshOGLSDLSurface(); - return; - } - - if ((vid.width > curmode.w) || (vid.height > curmode.h)) //check if current resolution is higher than current display resolution + if ((vid.width > desktopwidth) || (vid.height > desktopheight)) //check if current resolution is higher than current display resolution { downsample = true; - RefreshOGLSDLSurface(); + needrefresh = true; } - else + else if (downsample == true) { - if (downsample == true) - { - downsample = false; // its not so no need to do crap - RefreshOGLSDLSurface(); - } + downsample = false; + needrefresh = true; } + + if (needrefresh) + I_ResetFBOSurface(); +} + +static void I_ResetFBOSurface(void) +{ + InvSupersampleFactorX = (float)(desktopwidth) / vid.width; + InvSupersampleFactorY = (float)(desktopheight) / vid.height; + RefreshOGLSDLSurface(); } #endif static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { -#ifdef USE_FBO_OGL #define FOCUSUNION (mousefocus | (kbfocus << 1) | (windowmoved << 2)) -#else -#define FOCUSUNION (mousefocus | (kbfocus << 1)) -#endif + static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; @@ -822,12 +817,13 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) return; } -#ifdef USE_FBO_OGL if (windowmoved && rendermode == render_opengl) { + I_CheckDesktopRes(); +#ifdef USE_FBO_OGL I_DownSample(); - } #endif + } if (mousefocus && kbfocus) {