From 5f58e7b3436ae5cd4f879c110cce29a43968ab8a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 6 Mar 2024 07:26:53 +0100 Subject: [PATCH] multidisplay stuff + only activate framebuffer for downsampling idk i hope this shit works lmao also moved some things in OglSdlSurface so it doesent intialize certain things everytime we change framebuffer shit --- src/i_video.h | 2 ++ src/sdl/i_video.c | 79 +++++++++++++++++++++++++++++++++++++++++++---- src/sdl/ogl_sdl.c | 29 ++++++++--------- 3 files changed, 90 insertions(+), 20 deletions(-) diff --git a/src/i_video.h b/src/i_video.h index 2f08e4b1f..098d65cf6 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -139,4 +139,6 @@ UINT32 I_GetRefreshRate(void); void RefreshSDLSurface(void); +extern boolean downsample; + #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 655769dbd..5c3ca6738 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -163,7 +163,6 @@ static SDL_bool exposevideo = SDL_FALSE; static SDL_bool usesdl2soft = SDL_FALSE; static SDL_bool borderlesswindow = SDL_FALSE; static SDL_DisplayMode currentDisplayMode; -static SDL_DisplayMode currentWindowMode; // SDL2 vars SDL_Window *window; @@ -215,6 +214,8 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); //static void Impl_SetWindowName(const char *title); static void Impl_SetWindowIcon(void); +boolean downsample = false; + void RefreshSDLSurface(void) { OglSdlSurface(vid.width, vid.height); @@ -229,7 +230,6 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) Uint32 amask; int bpp = 16; int sw_texture_format = SDL_PIXELFORMAT_ABGR8888; - int index = SDL_GetWindowDisplayIndex(window); realwidth = vid.width; realheight = vid.height; @@ -245,8 +245,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) else if (fullscreen && cv_fullscreen.value == 2) { wasfullscreen = SDL_TRUE; - SDL_GetDesktopDisplayMode(index, ¤tWindowMode); - SDL_SetWindowSize(window, currentWindowMode.w, currentWindowMode.h); + SDL_SetWindowSize(window, width, height); SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); } else // windowed mode @@ -280,8 +279,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) else if (fullscreen && cv_fullscreen.value == 2) { wasfullscreen = SDL_TRUE; - SDL_GetDesktopDisplayMode(index, ¤tWindowMode); - SDL_SetWindowSize(window, currentWindowMode.w, currentWindowMode.h); + SDL_SetWindowSize(window, width, height); SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); } } @@ -798,11 +796,18 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which) return raxis; } +boolean displayinit = false; + 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; + static SDL_bool windowmoved = SDL_FALSE; + + static int currentDisplayIndex = -1; + static int previousDisplayIndex = -1; + static int numDisplays = -1; switch (evt.event) { @@ -822,6 +827,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; + case SDL_WINDOWEVENT_MOVED: + windowmoved = SDL_TRUE; + break; } if (mousefocus && kbfocus) @@ -861,6 +869,52 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } } + if (windowmoved) + { + currentDisplayIndex = SDL_GetWindowDisplayIndex(window); + + if (!displayinit) // dont need to recheck for new displays i think noone adds a display while playing kart lmkao + { + numDisplays = SDL_GetNumVideoDisplays(); + //CONS_Printf("Number of connected displays: %d\n", numDisplays); + displayinit = true; + } + + if (currentDisplayIndex != previousDisplayIndex) + { + //CONS_Printf("Window has changed displays.\n"); + for (int i = 0; i < numDisplays; ++i) + { + if (currentDisplayIndex == i) + { + SDL_DisplayMode curmode; + if (SDL_GetCurrentDisplayMode(i, &curmode) == 0) + { + //CONS_Printf("Current Display Info:\n"); + //CONS_Printf(" Resolution: %dx%d\n", curmode.w, curmode.h); + //CONS_Printf(" Refresh rate: %d Hz\n", curmode.refresh_rate); + + if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge + { + downsample = true; + RefreshSDLSurface(); + } + else + downsample = false; + + if (cv_fullscreen.value == 2) //exclusive + SDLSetMode(curmode.w, curmode.h, true); + else if (cv_fullscreen.value == 1) //borderless sdl thing + SDLSetMode(vid.width, vid.height, true); + else //windowed mode + SDLSetMode(vid.width, vid.height, false); + } + break; // found our current display break outta here + } + } + previousDisplayIndex = currentDisplayIndex; + } + } } static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) @@ -1900,6 +1954,8 @@ static UINT32 VID_GetRefreshRate(void) INT32 VID_SetMode(INT32 modeNum) { + int index = SDL_GetWindowDisplayIndex(window); + SDL_DisplayMode balls; SDLdoUngrabMouse(); vid.recalc = 1; @@ -1936,6 +1992,17 @@ INT32 VID_SetMode(INT32 modeNum) vid.modenum = -1; } //Impl_SetWindowName("SRB2Kart "VERSIONSTRING); + + if (SDL_GetCurrentDisplayMode(index, &balls) == 0) + { + if (cv_grframebuffer.value && ((vid.width > balls.w) || (vid.height > balls.h))) //framebuffer downsampler thinge + { + downsample = true; + RefreshSDLSurface(); + } + else + downsample = false; + } SDLSetMode(vid.width, vid.height, USE_FULLSCREEN); Impl_VideoSetupBuffer(); diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 7ffae65e2..df6aef9b9 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -42,6 +42,7 @@ #include "../i_system.h" #include "hwsym_sdl.h" #include "../m_argv.h" +#include "../i_video.h" #ifdef DEBUG_TO_FILE #include @@ -149,22 +150,22 @@ boolean OglSdlSurface(INT32 w, INT32 h) "- GPU vendor has dropped OpenGL support on your GPU and OS. (Old GPU?)\n" "- GPU drivers are missing or broken. You may need to update your drivers."); } + + if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) + pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); + else + maximumAnisotropy = 1; + + SetupGLInfo(); + + SetupGLFunc4(); + + granisotropicmode_cons_t[1].value = maximumAnisotropy; } first_init = true; - if (isExtAvailable("GL_EXT_texture_filter_anisotropic", gl_extensions)) - pglGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maximumAnisotropy); - else - maximumAnisotropy = 1; - - SetupGLInfo(); - - SetupGLFunc4(); - - granisotropicmode_cons_t[1].value = maximumAnisotropy; - SDL_GL_SetSwapInterval(cv_vidwait.value ? 1 : 0); - + // The screen textures need to be flushed if the width or height change so that they be remade for the correct size if (screen_width != w || screen_height != h) { @@ -182,7 +183,7 @@ boolean OglSdlSurface(INT32 w, INT32 h) RenderToFramebuffer = FrameBufferEnabled; GLFramebuffer_Disable(); - if (RenderToFramebuffer) + if (RenderToFramebuffer && downsample)//uuuuuuuuhuhuuhuhhuhuuh well changing resolutions can break this thing GLFramebuffer_Enable(); HWR_Startup(); @@ -216,7 +217,7 @@ void OglSdlFinishUpdate(boolean waitvbl) HWR_DrawScreenFinalTexture(sdlw, sdlh); - if (RenderToFramebuffer) + if (RenderToFramebuffer && downsample) GLFramebuffer_Enable(); SDL_GL_SwapWindow(window);