From 1c2fb14f45716ce38f9ac4ad88f4b99392951456 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 00:50:28 +0100 Subject: [PATCH 01/11] makes no sense without screen tex --- src/sdl/i_video.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b3a18899d..6f6f06022 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -709,6 +709,11 @@ boolean I_CheckNativeRes(void) int currentDisplayIndex = 0; SDL_DisplayMode curmode; + if (cv_glscreentextures.value == 0) + { + return false; + } + if (oldwidth == vid.width && oldheight == vid.height) { return resstate; From 8df8749a9cebbe68ab7820283a17b9ed1378b571 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 00:51:05 +0100 Subject: [PATCH 02/11] return false here --- src/sdl/i_video.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 6f6f06022..9e1fbeb97 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -723,12 +723,13 @@ boolean I_CheckNativeRes(void) if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) != 0) { - return resstate; + return false; } resstate = ((vid.width == curmode.w) && (vid.height == curmode.h)); oldwidth = vid.width; oldheight = vid.height; + return resstate; } From e0796b0cf1278ca20fc46f5ac3baaad51004e5bf Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 00:59:18 +0100 Subject: [PATCH 03/11] just query this once --- src/sdl/ogl_sdl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index fa18c0b1b..cb28cf062 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -245,6 +245,9 @@ void OglSdlFinishUpdate(boolean waitvbl) { static boolean oldwaitvbl = false; int sdlw, sdlh; + + const boolean usefbo = UseScreenFBO(); + if (oldwaitvbl != waitvbl) { SDL_GL_SetSwapInterval(waitvbl ? 1 : 0); @@ -256,15 +259,19 @@ void OglSdlFinishUpdate(boolean waitvbl) HWR_MakeScreenFinalTexture(); #ifdef USE_FBO_OGL - if (UseScreenFBO()) + if (usefbo) + { GLFramebuffer_Unbind(); + } #endif HWR_DrawScreenFinalTexture(sdlw, sdlh, HWR_ShouldUsePaletteRendering()); #ifdef USE_FBO_OGL - if (UseScreenFBO()) + if (usefbo) + { GLFramebuffer_Enable(); + } #endif SDL_GL_SwapWindow(window); From 404927c53c1debbe5d942302003f45604be904ef Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 00:57:31 +0100 Subject: [PATCH 04/11] no --- src/sdl/ogl_sdl.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index cb28cf062..43de323a7 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -213,13 +213,6 @@ boolean OglSdlSurface(INT32 w, INT32 h) pglClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); #ifdef USE_FBO_OGL - - if (!supportFBO) - { - if (cv_glframebuffer.value) - CV_SetValue(&cv_glframebuffer, 0); - } - if (UseScreenFBO()) GLFramebuffer_Enable(); else From fde4f64b8395bfbb8e7b29f0649d7ce810d9922c Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 00:59:46 +0100 Subject: [PATCH 05/11] simplify this crap and make compiler happy --- src/sdl/ogl_sdl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 43de323a7..710986e77 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -273,11 +273,12 @@ void OglSdlFinishUpdate(boolean waitvbl) // Sryder: We need to draw the final screen texture again into the other buffer in the original position so that // effects that want to take the old screen can do so after this - if ((!I_CheckNativeRes()) // well we dont need it on native res it seems + // well we dont need it on native res it seems #ifdef USE_FBO_OGL - && (!UseScreenFBO()) + if (!I_CheckNativeRes() && !usefbo) +#else + if (!I_CheckNativeRes()) #endif - ) HWR_DrawScreenFinalTexture(realwidth, realheight, false); } From 2034eedbe45d671593e7fb598482a6ad020982be Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 01:20:51 +0100 Subject: [PATCH 06/11] add another early return --- src/sdl/i_video.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9e1fbeb97..9b8790795 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -704,9 +704,9 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) boolean I_CheckNativeRes(void) { - static int oldwidth = 0, oldheight = 0; + static INT32 oldwidth = 0, oldheight = 0; static boolean resstate = false; - int currentDisplayIndex = 0; + int currentDisplayIndex = -1; SDL_DisplayMode curmode; if (cv_glscreentextures.value == 0) @@ -721,6 +721,12 @@ boolean I_CheckNativeRes(void) currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + // No valid index + if (currentDisplayIndex < 0) + { + return false; + } + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) != 0) { return false; @@ -736,14 +742,23 @@ boolean I_CheckNativeRes(void) #ifdef USE_FBO_OGL void I_DownSample(void) { + int currentDisplayIndex = -1; + SDL_DisplayMode curmode; + if (!cv_glframebuffer.value || !supportFBO || I_CheckNativeRes()) //no sense to do this crap if we cant benefit from it { downsample = false; return; } - int currentDisplayIndex = SDL_GetWindowDisplayIndex(window); - SDL_DisplayMode curmode; + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + + // No valid index + if (currentDisplayIndex < 0) + { + downsample = false; + return; + } if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) != 0) { From 5b46ae2eb9159f72d768bd89d8694480d292b131 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 03:12:57 +0100 Subject: [PATCH 07/11] better nvidia xwayland workaround handling what in the world was i thinking???? --- src/i_video.h | 3 --- src/sdl/i_video.c | 24 ------------------------ src/sdl/ogl_sdl.c | 15 +++++++++++---- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index 76055a6aa..70321d138 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -142,9 +142,6 @@ boolean I_UseNativeKeyboard(void); boolean I_CheckNativeRes(void); #ifdef USE_FBO_OGL -#if defined (__unix__) -extern boolean xwaylandcrap; -#endif void RefreshOGLSDLSurface(void); void I_DownSample(void); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9b8790795..524be7885 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -217,10 +217,6 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); static void Impl_SetWindowIcon(void); #ifdef USE_FBO_OGL -#if defined (__unix__) -static void I_FixXwaylandNvidia(void); -boolean xwaylandcrap = false; -#endif boolean downsample = false; void RefreshOGLSDLSurface(void) { @@ -279,9 +275,6 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) if (rendermode == render_opengl) { #ifdef USE_FBO_OGL -#if defined (__unix__) - I_FixXwaylandNvidia(); -#endif I_DownSample(); #endif OglSdlSurface(vid.width, vid.height); @@ -781,23 +774,6 @@ void I_DownSample(void) } } } - -#if defined (__unix__) -static void I_FixXwaylandNvidia(void) //dumbass crap, fix ur shit nvidia -{ - if (!supportFBO) - { - xwaylandcrap = false; - return; - } - - // enable fbo resize shit, update the ogl surface and turn crap back off lol - xwaylandcrap = true; - RefreshOGLSDLSurface(); - xwaylandcrap = false; - RefreshOGLSDLSurface(); -} -#endif #endif static void Impl_HandleWindowEvent(SDL_WindowEvent evt) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 710986e77..a509857f6 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -69,15 +69,16 @@ PFNglGetString pglGetString; #endif #ifdef USE_FBO_OGL + #if defined (__unix__) -static boolean isnvidiagpu = false; +static boolean xwaylandcrap = false; #endif boolean UseScreenFBO(void) { return ((supportFBO && cv_glframebuffer.value && downsample) #if defined (__unix__) - || (supportFBO && isnvidiagpu && xwaylandcrap) + || (supportFBO && xwaylandcrap) #endif ); } @@ -187,8 +188,8 @@ boolean OglSdlSurface(INT32 w, INT32 h) #if defined (__unix__) #ifdef USE_FBO_OGL - if (strstr((const char*)gl_renderer, "NVIDIA")) - isnvidiagpu = true; + if (supportFBO && strstr((const char*)gl_renderer, "NVIDIA")) + xwaylandcrap = true; #endif #endif } @@ -280,6 +281,12 @@ void OglSdlFinishUpdate(boolean waitvbl) if (!I_CheckNativeRes()) #endif HWR_DrawScreenFinalTexture(realwidth, realheight, false); + +#if defined (__unix__) +#ifdef USE_FBO_OGL + xwaylandcrap = false; +#endif +#endif } EXPORT void HWRAPI(OglSdlSetPalette) (RGBA_t *palette) From 0c7851bd2699b773d59f44e181dddbfcc2a0cfa2 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 03:13:17 +0100 Subject: [PATCH 08/11] 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) { From 4a3af6bc8afd9eedca8a52f33ff1289dbad229e2 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 03:17:12 +0100 Subject: [PATCH 09/11] whoops --- src/sdl/i_video.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index a7538ba6c..f422aea51 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -781,9 +781,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; -#ifdef USE_FBO_OGL static SDL_bool windowmoved = SDL_FALSE; -#endif const unsigned int oldfocus = FOCUSUNION; @@ -805,11 +803,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; -#ifdef USE_FBO_OGL case SDL_WINDOWEVENT_MOVED: windowmoved = SDL_TRUE; break; -#endif } if (FOCUSUNION == oldfocus) // No state change From 494a87feea2924ec64b4d741b10df54ffd564ef8 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 11:19:09 +0100 Subject: [PATCH 10/11] idk just set to false here too --- src/sdl/i_video.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f422aea51..d1f550621 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -763,7 +763,10 @@ void I_DownSample(void) } if (needrefresh) + { I_ResetFBOSurface(); + needrefresh = false; + } } static void I_ResetFBOSurface(void) From 4f037896dbfefa3e9b077f89712f0d852d12ab2a Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 20 Dec 2024 11:27:49 +0100 Subject: [PATCH 11/11] oops this is lugstuff only lel --- src/sdl/i_video.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index d1f550621..b07e29463 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -131,7 +131,6 @@ 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}; @@ -747,7 +746,7 @@ void I_DownSample(void) if (I_CheckNativeRes() && (downsample == true)) { downsample = false; - I_ResetFBOSurface(); + RefreshOGLSDLSurface(); return; } @@ -764,17 +763,10 @@ void I_DownSample(void) if (needrefresh) { - I_ResetFBOSurface(); + RefreshOGLSDLSurface(); needrefresh = false; } } - -static void I_ResetFBOSurface(void) -{ - InvSupersampleFactorX = (float)(desktopwidth) / vid.width; - InvSupersampleFactorY = (float)(desktopheight) / vid.height; - RefreshOGLSDLSurface(); -} #endif static void Impl_HandleWindowEvent(SDL_WindowEvent evt)