From bc356ceac9ef973ebfdad88cce3897089f5a2b18 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Sep 2024 00:51:58 +0200 Subject: [PATCH] make downsampleshader respect the resoltion factor --- src/hardware/hw_shaders.h | 10 ++++++---- src/hardware/r_opengl/r_opengl.c | 16 ++++++++++++++++ src/i_video.h | 3 +++ src/sdl/i_video.c | 19 +++++++++++++------ src/sdl/ogl_sdl.c | 5 +++++ 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index cc48ba496..6ac193c24 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -48,6 +48,7 @@ #define GLSL_DOWNSAMPLE_FRAGMENT_SHADER \ "uniform sampler2D tex;\n" \ + "uniform vec2 inv_supersamplefactor;\n" \ "#ifdef SRB2_PALETTE_RENDERING\n" \ "uniform sampler3D palette_lookup_tex;\n" \ "uniform sampler1D palette_tex;\n" \ @@ -55,10 +56,10 @@ "void main(void) {\n" \ "vec2 uv = gl_TexCoord[0].st;\n" \ "vec2 texel_size = 1.0 / textureSize(tex, 0);\n" \ - "vec2 offset1 = vec2(texel_size.x * 0.5, texel_size.y * 0.5);\n" \ - "vec2 offset2 = vec2(-texel_size.x * 0.5, texel_size.y * 0.5);\n" \ - "vec2 offset3 = vec2(texel_size.x * 0.5, -texel_size.y * 0.5);\n" \ - "vec2 offset4 = vec2(-texel_size.x * 0.5, -texel_size.y * 0.5);\n" \ + "vec2 offset1 = vec2(texel_size.x * inv_supersamplefactor.x, texel_size.y * inv_supersamplefactor.y);\n" \ + "vec2 offset2 = vec2(-texel_size.x * inv_supersamplefactor.x, texel_size.y * inv_supersamplefactor.y);\n" \ + "vec2 offset3 = vec2(texel_size.x * inv_supersamplefactor.x, -texel_size.y * inv_supersamplefactor.y);\n" \ + "vec2 offset4 = vec2(-texel_size.x * inv_supersamplefactor.x, -texel_size.y * inv_supersamplefactor.y);\n" \ "vec4 color1 = texture2D(tex, uv + offset1);\n" \ "vec4 color2 = texture2D(tex, uv + offset2);\n" \ "vec4 color3 = texture2D(tex, uv + offset3);\n" \ @@ -127,6 +128,7 @@ GLSL_DOOM_COLORMAP_NODITHER \ "#endif\n" \ "}\n" + // lighting cap adjustment: // first num (155.0), increase to make it start to go dark sooner // second num (0.26), increase to make it go dark faster diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index aa7ca4c94..426e91649 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -31,6 +31,8 @@ #include "../hw_main.h" #include "../hw_clip.h" +#include "../../i_video.h" + // Eeeeh not sure is this right way, but it works < sry :c < sry again it had to go :c extern fixed_t fovtan; // also extremely bad, I'm just too lazy!!! @@ -673,6 +675,9 @@ typedef enum gluniform_leveltime, gluniform_scr_resolution, + + // supersampling crap + gluniform_inv_supersamplefactor, gluniform_max, } gluniform_t; @@ -1984,6 +1989,9 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) shader->uniforms[gluniform_scr_resolution] = GETUNI("scr_resolution"); + // supersampling crap + shader->uniforms[gluniform_inv_supersamplefactor] = GETUNI("inv_supersamplefactor"); + // misc. shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); #undef GETUNI @@ -1993,6 +2001,10 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) if (uniform != -1) \ function (uniform, a); +#define UNIFORM_2(uniform, a, b, function) \ + if (uniform != -1) \ + function (uniform, a, b); + pglUseProgram(shader->program); // texture unit numbers for the samplers used for palette rendering @@ -2000,9 +2012,13 @@ static boolean Shader_CompileProgram(gl_shader_t *shader, GLint i) UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 1, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i); + // supersampling crap + UNIFORM_2(shader->uniforms[gluniform_inv_supersamplefactor], InvSupersampleFactorX, InvSupersampleFactorY, pglUniform2f); + // restore gl shader state pglUseProgram(gl_shaderstate.program); #undef UNIFORM_1 +#undef UNIFORM_2 return true; } diff --git a/src/i_video.h b/src/i_video.h index 6a60f8036..37dffdf7a 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -144,6 +144,9 @@ boolean I_UseNativeKeyboard(void); extern boolean xwaylandcrap; #endif +extern float InvSupersampleFactorX; +extern float InvSupersampleFactorY; + void RefreshOGLSDLSurface(void); void I_DownSample(void); extern boolean downsample; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 857e52b82..ec5473d53 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -222,6 +222,10 @@ static void I_FixXwaylandNvidia(void); boolean xwaylandcrap = false; #endif boolean downsample = false; + +float InvSupersampleFactorX = 0.0; +float InvSupersampleFactorY = 0.0; + void RefreshOGLSDLSurface(void) { if (rendermode == render_opengl) @@ -780,6 +784,9 @@ void I_DownSample(void) if ((vid.width > curmode.w) || (vid.height > curmode.h)) //check if current resolution is higher than current display resolution { downsample = true; + + InvSupersampleFactorX = (float)(curmode.w) / vid.width; + InvSupersampleFactorY = (float)(curmode.h) / vid.height; RefreshOGLSDLSurface(); } else @@ -809,7 +816,7 @@ static void I_FixXwaylandNvidia(void) //dumbass crap, fix ur shit nvidia static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { -#define FOCUSUNION (mousefocus | (kbfocus << 1)) +#define FOCUSUNION (mousefocus | (kbfocus << 1) | (windowmoved << 2)) static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool mousefocus = SDL_TRUE; static SDL_bool kbfocus = SDL_TRUE; @@ -844,6 +851,11 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) #endif } + if (FOCUSUNION == oldfocus) // No state change + { + return; + } + #ifdef USE_FBO_OGL if (windowmoved && rendermode == render_opengl) { @@ -851,11 +863,6 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) } #endif - if (FOCUSUNION == oldfocus) // No state change - { - return; - } - if (mousefocus && kbfocus) { // Tell game we got focus back, resume music if necessary diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 28dab83a9..491636368 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -220,6 +220,11 @@ boolean OglSdlSurface(INT32 w, INT32 h) GLFramebuffer_Enable(); else GLFramebuffer_Disable(); + + if (RenderToFramebuffer && HWR_UseShader()) + { + HWR_CompileShaders(); + } #endif HWR_Startup();