From 79d75aa08d774283c5d9021e64e23f1d07fcbb33 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 9 Nov 2026 20:19:08 +0100 Subject: [PATCH] simplify gl "downsampling" stuff still kinda meh but whatever, shit works --- src/hardware/hw_main.cpp | 10 ++--- src/hardware/r_opengl/r_opengl.c | 6 +-- src/i_video.h | 6 +-- src/sdl/i_video.c | 63 ++++++++++++-------------------- src/sdl/ogl_sdl.c | 2 +- 5 files changed, 35 insertions(+), 52 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 30d319b26..007148aeb 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -255,6 +255,7 @@ static void CV_screentextures_OnChange(void) #endif intermissionbginit = false; } + GL_SetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_glscreentextures.value); M_UpdateOGLMenu(); } @@ -263,12 +264,11 @@ static void CV_screentextures_OnChange(void) static void CV_glframebuffer_OnChange(void) { ONLY_IF_GL_LOADED - if ((cv_glframebuffer.value != 0 && cv_glscreentextures.value != 2) - || (!supportFBO && cv_glframebuffer.value != 0)) // screen FBO needs screen textures - CV_SetValue(&cv_glframebuffer, 0); + // screen FBO needs screen textures currently + if (cv_glframebuffer.value != 0 && ((cv_glscreentextures.value != 2) || !supportFBO)) + CV_StealthSetValue(&cv_glframebuffer, 0); // dont recursively call this lul - I_DownSample(); - RefreshOGLSDLSurface(); + I_CheckDownSampleState(true); M_UpdateOGLMenu(); intermissionbginit = false; } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 4a6a13adb..48c916463 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3266,7 +3266,7 @@ static void GL_FBO_DeleteAttachments(void) static void GL_FBO_Generate(void) { - if (supportFBO == FBO_NONE || framebufferobject.init || !UseScreenFBO()) + if (supportFBO == FBO_NONE || framebufferobject.init) return; // Generate the framebuffer @@ -3348,13 +3348,13 @@ void GL_FBO_BindMainFrameBuffer(void) void GL_FBO_Enable(void) { - if (supportFBO == FBO_NONE || !UseScreenFBO()) + if (supportFBO == FBO_NONE) return; GL_FBO_Generate(); // failed - if (supportFBO == FBO_NONE || !framebufferobject.init) + if (!framebufferobject.init) return; pglBindFramebuffer(GL_FRAMEBUFFER_EXT, framebufferobject.fboobj); diff --git a/src/i_video.h b/src/i_video.h index 9a43f82a7..7511b476a 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -126,11 +126,9 @@ boolean I_CheckNativeRes(void); void I_SetBorderlessWindow(void); #ifdef USE_FBO_OGL - -void RefreshOGLSDLSurface(void); -void I_DownSample(void); +void I_CheckDownSampleState(boolean forcerefresh); +boolean I_IsDownsampling(void); boolean UseScreenFBO(void); -extern boolean downsample; #endif // So we can call this from i_video event loop diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 68ec2c771..9d85dbb3e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -197,10 +197,6 @@ static INT32 custom_height = 0; static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); static void Impl_SetWindowIcon(void); -#ifdef USE_FBO_OGL -boolean downsample = false; -#endif - static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) { if (code >= SDL_SCANCODE_A && code <= SDL_SCANCODE_Z) @@ -522,7 +518,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { I_CheckDesktopRes(); #ifdef USE_FBO_OGL - I_DownSample(); + I_CheckDownSampleState(false); #endif windowmoved = SDL_FALSE; } @@ -1263,8 +1259,9 @@ static void I_CheckDesktopRes(void) int currentDisplayIndex = -1; SDL_DisplayMode curmode; - desktopwidth = 0; - desktopheight = 0; + // just fallback to game res ig? + desktopwidth = vid.width; + desktopheight = vid.height; currentDisplayIndex = SDL_GetWindowDisplayIndex(window); @@ -1274,7 +1271,7 @@ static void I_CheckDesktopRes(void) return; } - if (SDL_GetDesktopDisplayMode(currentDisplayIndex, &curmode) != 0) + if (SDL_GetCurrentDisplayMode(currentDisplayIndex, &curmode) < 0) { return; } @@ -1290,46 +1287,33 @@ boolean I_CheckNativeRes(void) } #ifdef USE_FBO_OGL +static boolean vid_downsampling = false; -void RefreshOGLSDLSurface(void) +boolean I_IsDownsampling(void) { - if (rendermode == render_opengl) - OglSdlSurface(vid.width, vid.height); + return vid_downsampling; } -void I_DownSample(void) +void I_CheckDownSampleState(boolean forcerefresh) { - boolean needrefresh = false; - - if (!cv_glframebuffer.value || !supportFBO || (cv_glscreentextures.value == 0)) // no sense to do this crap if we cant benefit from it + // no fbo support so we dont care + if (!supportFBO) { - downsample = false; + vid_downsampling = false; return; } - if (I_CheckNativeRes() && (downsample == true)) + // no sense to do this crap if we cant benefit from it + const boolean newdownsamplestate = cv_glframebuffer.value && (cv_glscreentextures.value == 2) && I_CheckAboveDesktopRes(vid.width, vid.height); + + // state changed or fbo was toggled + if (vid_downsampling != newdownsamplestate || forcerefresh) { - downsample = false; - RefreshOGLSDLSurface(); - return; + //printf("downsample changed from %d to %d\n", vid_downsampling, curdownsamplestate); + OglSdlSurface(vid.width, vid.height); } - if ((vid.width > desktopwidth) || (vid.height > desktopheight)) //check if current resolution is higher than current display resolution - { - downsample = true; - needrefresh = true; - } - else if (downsample == true) - { - downsample = false; - needrefresh = true; - } - - if (needrefresh) - { - RefreshOGLSDLSurface(); - needrefresh = false; - } + vid_downsampling = newdownsamplestate; } #endif @@ -1359,10 +1343,11 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) } // Reposition window only in windowed mode + const int windowpos = SDL_GetWindowDisplayIndex(window); SDL_SetWindowSize(window, width, height); SDL_SetWindowPosition(window, - SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)), - SDL_WINDOWPOS_CENTERED_DISPLAY(SDL_GetWindowDisplayIndex(window)) + SDL_WINDOWPOS_CENTERED_DISPLAY(windowpos), + SDL_WINDOWPOS_CENTERED_DISPLAY(windowpos) ); } } @@ -1384,7 +1369,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { I_CheckDesktopRes(); #ifdef USE_FBO_OGL - I_DownSample(); + I_CheckDownSampleState(false); #endif OglSdlSurface(vid.width, vid.height); } diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 2af913170..d2767307a 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -65,7 +65,7 @@ PFNglGetString pglGetString; #ifdef USE_FBO_OGL boolean UseScreenFBO(void) { - return (supportFBO && cv_glframebuffer.value && downsample); + return (supportFBO && cv_glframebuffer.value && I_IsDownsampling() && (cv_glscreentextures.value == 2)); } #endif