Stuff from displaycrap branch to detect downsampling automatically

This commit is contained in:
Alug committed 2024-03-27 18:33:29 +01:00
1 parent 91a3b288ef
commit a28f025d40
3 files changed
+104 -15

No files matched your search

+2
View File
@@ -139,4 +139,6 @@ UINT32 I_GetRefreshRate(void);
void RefreshSDLSurface(void);
extern boolean downsample;
#endif
+87 -1
View File
@@ -159,6 +159,11 @@ static SDL_bool exposevideo = SDL_FALSE;
static SDL_bool usesdl2soft = SDL_FALSE;
static SDL_bool borderlesswindow = SDL_FALSE;
static boolean displayinit = false;
static int currentDisplayIndex = -1;
static int previousDisplayIndex = -1;
static int numDisplays = -1;
// SDL2 vars
SDL_Window *window;
SDL_Renderer *renderer;
@@ -166,6 +171,12 @@ static SDL_Texture *texture;
static SDL_bool havefocus = SDL_TRUE;
static const char *fallback_resolution_name = "Fallback";
static void ScaleQuality_OnChange(void)
{
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, cv_scalequality.string);
COM_ImmedExecute(va("vid_mode %d", vid.modenum)); // Hack to make it apply without restarting
}
// windowed video modes from which to choose from.
static INT32 windowedModes[MAXWINMODES][2] =
{
@@ -203,7 +214,8 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen);
//static void Impl_SetWindowName(const char *title);
static void Impl_SetWindowIcon(void);
#ifdef HWRENDER
boolean downsample = false;
void RefreshSDLSurface(void)
{
OglSdlSurface(vid.width, vid.height);
@@ -769,11 +781,23 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which)
return raxis;
}
static void SDL_CheckDisplays(void)
{
if (!displayinit)
{
numDisplays = SDL_GetNumVideoDisplays();
displayinit = true;
}
currentDisplayIndex = SDL_GetWindowDisplayIndex(window);
}
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;
switch (evt.event)
{
@@ -793,6 +817,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)
@@ -832,6 +859,43 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
}
}
if (windowmoved)
{
SDL_CheckDisplays();
if (numDisplays > 1)
{
currentDisplayIndex = SDL_GetWindowDisplayIndex(window);
if (currentDisplayIndex != previousDisplayIndex)
{
for (int i = 0; i < numDisplays; ++i)
{
if (currentDisplayIndex == i)
{
SDL_DisplayMode curmode;
if (SDL_GetCurrentDisplayMode(i, &curmode) == 0)
{
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)
@@ -1908,6 +1972,25 @@ INT32 VID_SetMode(INT32 modeNum)
}
//Impl_SetWindowName("SRB2Kart "VERSIONSTRING);
for (int i = 0; i < numDisplays; ++i)
{
if (currentDisplayIndex == i)
{
SDL_DisplayMode curmode;
if (SDL_GetCurrentDisplayMode(i, &curmode) == 0)
{
if (cv_grframebuffer.value && ((vid.width > curmode.w) || (vid.height > curmode.h))) //framebuffer downsampler thinge
{
downsample = true;
RefreshSDLSurface();
}
else
downsample = false;
}
break; // found our current display break outta here
}
}
SDLSetMode(vid.width, vid.height, USE_FULLSCREEN);
Impl_VideoSetupBuffer();
@@ -2318,6 +2401,9 @@ void I_StartupGraphics(void)
// Fury: we do window initialization after GL setup to allow
// SDL_GL_LoadLibrary to work well on Windows
//check for display things
SDL_CheckDisplays();
// Create window
//Impl_CreateWindow(USE_FULLSCREEN);
//Impl_SetWindowName("SRB2Kart "VERSIONSTRING);
+15 -14
View File
@@ -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 <stdarg.h>
@@ -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)
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);