From ee3402e72a7ab444206c8bbf98f87756ba4061b4 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sat, 2 May 2026 11:58:19 -0400 Subject: [PATCH] Screentextures toggle port from saturn --- src/d_main.cpp | 3 +-- src/hardware/hw_defs.h | 1 + src/hardware/hw_main.c | 45 ++++++++++++++++++++++++++++++++ src/hardware/hw_main.h | 2 +- src/hardware/hw_map.c | 2 +- src/hardware/r_opengl/r_opengl.c | 25 ++++++++++++++++++ src/hu_stuff.c | 4 +++ src/hu_stuff.h | 1 + src/sdl/ogl_sdl.c | 6 +++-- src/y_inter.c | 4 +++ 10 files changed, 87 insertions(+), 6 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index eb6239b56..d12321681 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -339,13 +339,12 @@ boolean D_RenderLevel(void) if (r_splitscreen == 2) // Draw over the fourth screen so you don't have to stare at a HOM :V { // V_DrawPatchFill, but for the fourth screen only - patch_t *pat = static_cast(W_CachePatchName("SRB2BACK", PU_CACHE)); INT32 x, y, pw = SHORT(pat->width) * vid.dup, ph = SHORT(pat->height) * vid.dup; for (x = vid.width>>1; x < vid.width; x += pw) { for (y = vid.height>>1; y < vid.height; y += ph) - V_DrawScaledPatch(x, y, V_NOSCALESTART, pat); + V_DrawScaledPatch(x, y, V_NOSCALESTART, srb2back); } } } diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 2e82ef325..65b6b6084 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -316,6 +316,7 @@ enum hwdsetspecialstate HWD_SET_SHADERS, HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, + HWD_SET_SCREEN_TEXTURES, HWD_NUMSTATE }; typedef enum hwdsetspecialstate hwdspecialstate_t; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 4a1df33a3..52b9b0722 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -877,6 +877,7 @@ static CV_PossibleValue_t glshearing_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "Thi static void CV_glfiltermode_OnChange(void); static void CV_glanisotropic_OnChange(void); +static void CV_screentextures_OnChange(void); static CV_PossibleValue_t glfiltermode_cons_t[]= {{HWD_SET_TEXTUREFILTER_POINTSAMPLED, "Nearest"}, {HWD_SET_TEXTUREFILTER_BILINEAR, "Bilinear"}, {HWD_SET_TEXTUREFILTER_TRILINEAR, "Trilinear"}, @@ -892,6 +893,15 @@ consvar_t cv_glallowshaders = CVAR_INIT ("gr_allowclientshaders", "On", CV_NETVA consvar_t cv_fovchange = CVAR_INIT ("gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL); consvar_t cv_glsecbright = CVAR_INIT("gr_secbright", "0", CV_SAVE, glsecbright_cons_t, NULL); +// The current screen texture implementation is inefficient and disabling it can result in significant +// performance gains on lower end hardware. The game is still quite playable without this functionality. +// Features that break when disabling this: +// - water and heat wave effects +// - intermission background +// - full screen scaling (use native resolution or windowed mode to avoid this) +static CV_PossibleValue_t glscreentextures_cons_t[] = {{0, "Off"}, {1, "Wipes Only"}, {2, "All"}, {0, NULL}}; +consvar_t cv_glscreentextures = CVAR_INIT("gr_screentextures", "All", CV_CALL|CV_SAVE, glscreentextures_cons_t, CV_screentextures_OnChange); + consvar_t cv_glmodels = CVAR_INIT ("gr_models", "Off", CV_SAVE, CV_OnOff, NULL); #ifdef BAD_MODEL_OPTIONS @@ -940,6 +950,17 @@ consvar_t cv_glskydebug = CVAR_INIT ("gr_skydebug", "0", 0, CV_Unsigned, NULL); #define ONLY_IF_GL_LOADED if (vid.glstate != VID_GL_LIBRARY_LOADED) return; +static void CV_screentextures_OnChange(void) +{ + ONLY_IF_GL_LOADED + if (cv_glscreentextures.value != 2) + { + if (cv_glpaletterendering.value != 0) + CV_SetValue(&cv_glpaletterendering, 0); + } + GL_SetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_glscreentextures.value); +} + static void CV_glfiltermode_OnChange(void) { ONLY_IF_GL_LOADED @@ -964,10 +985,15 @@ void CV_glmodellighting_OnChange(void) void CV_glpaletterendering_OnChange(void) { ONLY_IF_GL_LOADED + + if (cv_glpaletterendering.value != 0 && cv_glscreentextures.value != 2) // can't do palette rendering without screen textures + CV_SetValue(&cv_glpaletterendering, 0); + if (gl_shadersavailable) { HWR_CompileShaders(); HWR_TogglePaletteRendering(); + HWR_PrecacheLevel(); } } @@ -1051,6 +1077,8 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_gldebugportal); CV_RegisterVar(&cv_glskydebug); + + CV_RegisterVar(&cv_glscreentextures); } void HWR_AddSessionCommands(void) @@ -1081,6 +1109,14 @@ void HWR_Startup(void) gl_shadersavailable = HWR_InitShaders(); HWR_SetShaderState(); HWR_TogglePaletteRendering(); + + if (cv_glscreentextures.value != 2) + { + if (cv_glpaletterendering.value != 0) + CV_SetValue(&cv_glpaletterendering, 0); + } + + GL_SetSpecialState(HWD_SET_SCREEN_TEXTURES, cv_glscreentextures.value); } gl_init = true; @@ -1180,6 +1216,9 @@ void HWR_DoPostProcessor(player_t *player) GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_Additive|PF_NoTexture|PF_NoDepthTest); } + if (cv_glscreentextures.value != 2) // screen textures are needed for the rest of the effects + return; + // Capture the screen for intermission and screen waving if (gamestate != GS_INTERMISSION) GL_MakeScreenTexture(HWD_SCREENTEXTURE_GENERIC1); @@ -1290,6 +1329,12 @@ static boolean HWR_WipeCheck(UINT8 wipenum, UINT8 scrnnum) void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum) { + if (cv_glscreentextures.value == 0) + { + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // just draw a black screen instead of flashing and crap + return; + } + if (!HWR_WipeCheck(wipenum, scrnnum)) return; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index becec7e94..025a65ed0 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -86,7 +86,7 @@ boolean HWR_ShouldUsePaletteRendering(void); extern CV_PossibleValue_t glanisotropicmode_cons_t[]; extern consvar_t cv_glshaders, cv_glallowshaders; -extern consvar_t cv_glmodels; +extern consvar_t cv_glmodels, cv_glscreentextures; // SRB2Kart: We don't like these options. // Interpolation should be up to who animated the model. diff --git a/src/hardware/hw_map.c b/src/hardware/hw_map.c index 7a78f60f9..1822e392b 100644 --- a/src/hardware/hw_map.c +++ b/src/hardware/hw_map.c @@ -2034,7 +2034,7 @@ static void loading_status(void) x = BASEVIDWIDTH/2; y = BASEVIDHEIGHT/2; V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, levelfadecol); // Black background to match fade in effect - //V_DrawPatchFill(W_CachePatchName("SRB2BACK",PU_CACHE)); // SRB2 background, ehhh too bright. + //V_DrawPatchFill(srb2back); // SRB2 background, ehhh too bright. M_DrawTextBox(x-58, y-8, 13, 1); V_DrawString(x-50, y, V_YELLOWMAP, "Loading..."); V_DrawRightAlignedString(x+50, y, V_YELLOWMAP, s); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 3d3cd75c0..59a25a9b5 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -628,6 +628,9 @@ static PFNglUniform3fv pglUniform3fv; static PFNglGetUniformLocation pglGetUniformLocation; // 13062019 + +static INT32 gl_enable_screen_textures = 2; + typedef enum { // textures @@ -2411,6 +2414,10 @@ void GL_SetSpecialState(hwdspecialstate_t IdState, INT32 Value) Flush(); //??? if we want to change filter mode by texture, remove this break; + case HWD_SET_SCREEN_TEXTURES: + gl_enable_screen_textures = Value; + break; + default: break; } @@ -3043,6 +3050,9 @@ void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) float float_x, float_y, float_nextx, float_nexty; float xfix, yfix; + if (gl_enable_screen_textures != 2) + return; + const float blackBack[16] = { -16.0f, -16.0f, 6.0f, @@ -3135,6 +3145,9 @@ void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags) { float xfix, yfix; + if (gl_enable_screen_textures != 2) + return; + const float screenVerts[12] = { -1.0f, -1.0f, 1.0f, @@ -3183,6 +3196,9 @@ void GL_DoScreenWipe(int wipeStart, int wipeEnd) INT32 fademaskdownloaded = tex_downloaded; // the fade mask that has been set + if (!gl_enable_screen_textures) + return; + const float screenVerts[12] = { -1.0f, -1.0f, 1.0f, @@ -3260,6 +3276,9 @@ void GL_MakeScreenTexture(int tex) { boolean firstTime = (screenTextures[tex] == 0); + if (!gl_enable_screen_textures) + return; + // Create screen texture if (firstTime) pglGenTextures(1, &screenTextures[tex]); @@ -3285,6 +3304,9 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 float fix[8]; float i; + if (gl_enable_screen_textures != 2) + return; + GLubyte color[4] = {255, 255, 255, 255}; float screenVerts[12] = @@ -3402,6 +3424,9 @@ void GL_DrawScreenFinalTexture(int tex, int width, int height) float off[12]; float fix[8]; + if (gl_enable_screen_textures != 2) + return; + xfix = 1/((float)(texsize)/((float)((screen_width)))); yfix = 1/((float)(texsize)/((float)((screen_height)))); diff --git a/src/hu_stuff.c b/src/hu_stuff.c index dd8307530..62b746b5d 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -82,6 +82,8 @@ patch_t *pinglocal[2]; // mindelay indecator patch_t *framecounter; patch_t *frameslash; // framerate stuff. Used in screen.c +patch_t *srb2back = NULL; + static player_t *plr; boolean hu_keystrokes; // :) boolean chat_on; // entering a chat message? @@ -166,6 +168,8 @@ void HU_LoadGraphics(void) // fps stuff HU_UpdatePatch(&framecounter, "FRAMER"); HU_UpdatePatch(&frameslash, "FRAMESL"); + + HU_UpdatePatch(&srb2back, "SRB2BACK"); } // Initialise Heads up diff --git a/src/hu_stuff.h b/src/hu_stuff.h index f34e6c935..bbb8027d8 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -111,6 +111,7 @@ extern boolean hu_keystrokes; extern patch_t *pinggfx[5]; extern patch_t *framecounter; extern patch_t *frameslash; +extern patch_t *srb2back; // set true whenever the tab rankings are being shown for any reason extern boolean hu_showscores; diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 9a96759fc..24c92c24c 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -185,9 +185,11 @@ void OglSdlFinishUpdate(boolean waitvbl) SDL_GetWindowSizeInPixels(window, &sdlw, &sdlh); HWR_MakeScreenFinalTexture(); - GL_SetShader(HWR_GetShaderFromTarget(SHADER_FINAL_POST_PROCESS)); + if (gl_shadersavailable) + GL_SetShader(HWR_GetShaderFromTarget(SHADER_FINAL_POST_PROCESS)); HWR_DrawScreenFinalTexture(sdlw, sdlh); - GL_UnSetShader(); + if (gl_shadersavailable) + GL_UnSetShader(); SDL_GL_SwapWindow(window); GL_GClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE); diff --git a/src/y_inter.c b/src/y_inter.c index e260b449d..d5b3134ba 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -384,7 +384,11 @@ void Y_IntermissionDrawer(void) if (useinterpic) V_DrawScaledPatch(0, 0, 0, interpic); +#ifdef HWRENDER + else if (y_screenbuffer != NULL && !(rendermode == render_opengl && cv_glscreentextures.value != 2)) +#else else if (y_screenbuffer != NULL) +#endif { if (rendermode == render_soft) VID_BlitLinearScreen(y_screenbuffer, vid.screens[0], vid.width, vid.height, vid.width, vid.rowbytes);