From 77a00b08a5d628c9c373dcf4a7e79046f7000c2a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 8 Sep 2025 19:29:01 +0200 Subject: [PATCH 1/4] optimize gl vhseffect slightly we dont need to remake our screen texture 3 times also avoid combining float with interger maths esp in the loop --- src/hardware/r_opengl/r_opengl.c | 55 +++++++++++++++++++------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 4dcd1253b..32aa784d1 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3348,7 +3348,6 @@ void GL_DoScreenWipe(int wipeStart, int wipeEnd) void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize) { - int tex = HWD_SCREENTEXTURE_VHS; float xfix, yfix; float fix[8]; GLubyte color[4] = {255, 255, 255, 255}; @@ -3368,14 +3367,19 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 xfix = 1/((float)(screen_texsizew)/((float)((screen_width)))); yfix = 1/((float)(screen_texsizeh)/((float)((screen_height)))); - // Slight fuzziness - GL_MakeScreenTexture(tex); - GL_SetBlend(PF_Modulated|PF_Translucent|PF_NoDepthTest); - pglBindTexture(GL_TEXTURE_2D, screenTextures[tex]); + const GLfloat scrwf = (float)screen_width; + const GLfloat scrwh = (float)screen_height; - for (i = 0; i < 1; i += 2.f/vid.height) + // Slight fuzziness + GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); + GL_SetBlend(PF_Modulated|PF_Translucent|PF_NoDepthTest); + pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); + + const float stride = 2.f/scrwh; + + for (i = 0; i < 1; i += stride) { - fix[2] = (float)(rand() % 128) / -22000 * xfix; + fix[2] = (float)(rand() % 128) / -22000.f * xfix; fix[0] = fix[2]; fix[6] = fix[0] + xfix; fix[4] = fix[2] + xfix; @@ -3393,8 +3397,8 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 } // Upward bar - GL_MakeScreenTexture(tex); - pglBindTexture(GL_TEXTURE_2D, screenTextures[tex]); + //GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); + //pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); color[0] = color[1] = color[2] = 190; color[3] = 250; @@ -3402,14 +3406,14 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 fix[0] = 0.0f; fix[6] = xfix; - fix[2] = (float)updistort / screen_width * xfix; + fix[2] = (float)updistort / scrwf * xfix; fix[4] = fix[2] + fix[6]; - screenVerts[1] = screenVerts[10] = 2.0f*upbary/screen_height - 1.0f; - screenVerts[4] = screenVerts[7] = screenVerts[1] + (float)barsize/screen_height; + screenVerts[1] = screenVerts[10] = 2.0f*upbary/scrwh - 1.0f; + screenVerts[4] = screenVerts[7] = screenVerts[1] + (float)barsize/scrwh; - fix[1] = fix[7] = (float)upbary/screen_height * yfix; - fix[3] = fix[5] = fix[1] + (float)barsize/2/screen_height * yfix; + fix[1] = fix[7] = (float)upbary/scrwh * yfix; + fix[3] = fix[5] = fix[1] + (float)barsize/2/scrwh * yfix; pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); @@ -3422,19 +3426,19 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); // Downward bar - GL_MakeScreenTexture(tex); - pglBindTexture(GL_TEXTURE_2D, screenTextures[tex]); + //GL_MakeScreenTexture(HWD_SCREENTEXTURE_VHS); + //pglBindTexture(GL_TEXTURE_2D, screenTextures[HWD_SCREENTEXTURE_VHS]); fix[0] = 0.0f; fix[6] = xfix; - fix[2] = (float)downdistort / screen_width * -xfix; + fix[2] = (float)downdistort / scrwf * -xfix; fix[4] = fix[2] + fix[6]; - screenVerts[1] = screenVerts[10] = 2.0f*downbary/screen_height - 1.0f; - screenVerts[4] = screenVerts[7] = screenVerts[1] + (float)barsize/screen_height; + screenVerts[1] = screenVerts[10] = 2.0f*downbary/scrwh - 1.0f; + screenVerts[4] = screenVerts[7] = screenVerts[1] + (float)barsize/scrwh; - fix[1] = fix[7] = (float)downbary/screen_height * yfix; - fix[3] = fix[5] = fix[1] + (float)barsize/2/screen_height * yfix; + fix[1] = fix[7] = (float)downbary/scrwh * yfix; + fix[3] = fix[5] = fix[1] + (float)barsize/2/scrwh * yfix; pglTexCoordPointer(2, GL_FLOAT, 0, fix); pglVertexPointer(3, GL_FLOAT, 0, screenVerts); @@ -3450,11 +3454,13 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 // Create a texture from the screen. void GL_MakeScreenTexture(int tex) { - boolean firstTime = (screenTextures[tex] == 0); + boolean firstTime; if (!gl_enable_screen_textures) return; + firstTime = (screenTextures[tex] == 0); + // Create screen texture if (firstTime) pglGenTextures(1, &screenTextures[tex]); @@ -3539,7 +3545,7 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh pglBindTexture(GL_TEXTURE_2D, screenTextures[tex]); if (useshader) - pglUseProgram(gl_shaders[SHADER_PALETTE_POSTPROCESS].program); // palette postprocess shader + pglUseProgram(gl_shaders[SHADER_PALETTE_POSTPROCESS].program); // Final postprocess step of palette rendering, after everything else has been drawn. pglColor4ubv(white); @@ -3557,6 +3563,7 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh void GL_SetPaletteLookup(UINT8 *lut) { GLenum internalFormat; + if (gl_version[0] == '1' || gl_version[0] == '2') { // if the OpenGL version is below 3.0, then the GL_R8 format may not be available. @@ -3584,6 +3591,7 @@ void GL_SetPaletteLookup(UINT8 *lut) UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable) { LTListItem *item = malloc(sizeof(LTListItem)); + if (!LightTablesTail) { LightTablesHead = LightTablesTail = item; @@ -3593,6 +3601,7 @@ UINT32 GL_CreateLightTable(RGBA_t *hw_lighttable) LightTablesTail->next = item; LightTablesTail = item; } + item->next = NULL; pglGenTextures(1, &item->id); pglBindTexture(GL_TEXTURE_2D, item->id); From ff5bb34204ab5e5ed0d3209212462a153f9d8752 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 8 Sep 2025 19:33:46 +0200 Subject: [PATCH 2/4] parentheses hell --- src/hardware/r_opengl/r_opengl.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 32aa784d1..3a903a9af 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3142,8 +3142,8 @@ void GL_PostImgRedraw(float points[SCREENVERTS][SCREENVERTS][2]) return; // X/Y stretch fix for all resolutions(!) - xfix = (float)(screen_texsizew)/((float)((screen_width)/(float)(SCREENVERTS-1))); - yfix = (float)(screen_texsizeh)/((float)((screen_height)/(float)(SCREENVERTS-1))); + xfix = (float)screen_texsizew/((float)(screen_width/(float)(SCREENVERTS-1))); + yfix = (float)screen_texsizeh/((float)(screen_height/(float)(SCREENVERTS-1))); pglDisable(GL_DEPTH_TEST); pglDisable(GL_BLEND); @@ -3230,12 +3230,9 @@ void GL_DrawScreenTexture(int tex, FSurfaceInfo *surf, FBITFIELD polyflags) if (gl_enable_screen_textures != 2) return; - xfix = 1/((float)(screen_texsizew)/((float)((screen_width)))); - yfix = 1/((float)(screen_texsizeh)/((float)((screen_height)))); + xfix = 1/((float)screen_texsizew/(float)screen_width); + yfix = 1/((float)screen_texsizeh/(float)screen_height); - // const float screenVerts[12] - - // float fix[8]; fix[0] = 0.0f; fix[1] = 0.0f; fix[2] = 0.0f; @@ -3289,12 +3286,9 @@ void GL_DoScreenWipe(int wipeStart, int wipeEnd) if (!gl_enable_screen_textures) return; - xfix = 1/((float)(screen_texsizew)/((float)((screen_width)))); - yfix = 1/((float)(screen_texsizeh)/((float)((screen_height)))); + xfix = 1/((float)screen_texsizew/(float)screen_width); + yfix = 1/((float)screen_texsizeh/(float)screen_height); - // const float screenVerts[12] - - // float fix[8]; fix[0] = 0.0f; fix[1] = 0.0f; fix[2] = 0.0f; @@ -3364,8 +3358,8 @@ void GL_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 if (gl_enable_screen_textures != 2) return; - xfix = 1/((float)(screen_texsizew)/((float)((screen_width)))); - yfix = 1/((float)(screen_texsizeh)/((float)((screen_height)))); + xfix = 1/((float)screen_texsizew/(float)screen_width); + yfix = 1/((float)screen_texsizeh/(float)screen_height); const GLfloat scrwf = (float)screen_width; const GLfloat scrwh = (float)screen_height; @@ -3494,8 +3488,8 @@ void GL_DrawScreenFinalTexture(int tex, INT32 width, INT32 height, boolean usesh if (gl_enable_screen_textures != 2) return; - xfix = 1/((float)(screen_texsizew)/((float)((screen_width)))); - yfix = 1/((float)(screen_texsizeh)/((float)((screen_height)))); + xfix = 1/((float)screen_texsizew/(float)screen_width); + yfix = 1/((float)screen_texsizeh/(float)screen_height); origaspect = (float)screen_width / screen_height; newaspect = (float)width / height; From 29db810c54ebdfe8cfd04614a04e180ffb9d9498 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 9 Sep 2025 18:16:52 +0200 Subject: [PATCH 3/4] delet remaining "highcolor" stuff --- src/android/i_video.c | 4 ---- src/dedicated/i_video.c | 4 +--- src/i_video.h | 5 ----- src/r_data.c | 44 ----------------------------------------- src/r_data.h | 3 --- src/screen.c | 4 ++-- src/screen.h | 2 +- src/sdl/i_video.c | 2 -- 8 files changed, 4 insertions(+), 64 deletions(-) diff --git a/src/android/i_video.c b/src/android/i_video.c index 4db66afe0..bbe1cf3a3 100644 --- a/src/android/i_video.c +++ b/src/android/i_video.c @@ -10,12 +10,8 @@ rendermode_t rendermode = render_soft; -boolean highcolor = false; - boolean allow_fullscreen = false; - - consvar_t cv_vidwait = {"vid_wait", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; void I_StartupGraphics(void){} diff --git a/src/dedicated/i_video.c b/src/dedicated/i_video.c index 8f8781e9e..e2a712995 100644 --- a/src/dedicated/i_video.c +++ b/src/dedicated/i_video.c @@ -29,8 +29,6 @@ rendermode_t rendermode = render_none; -boolean highcolor = false; - // synchronize page flipping with screen refresh consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -153,7 +151,7 @@ boolean I_UseNativeKeyboard(void) return false; } -void I_SetBorderlessWindow(void) +void I_SetBorderlessWindow(void) { } diff --git a/src/i_video.h b/src/i_video.h index 88d295ed9..d9bb9e1ce 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -40,11 +40,6 @@ typedef enum */ extern rendermode_t rendermode; - -/** \brief use highcolor modes if true -*/ -extern boolean highcolor; - /** \brief setup video mode */ void I_StartupGraphics(void); diff --git a/src/r_data.c b/src/r_data.c index 688b03972..0b4b153e4 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -121,10 +121,6 @@ UINT8 invertmap[256]; // for debugging/info purposes size_t flatmemory, spritememory, texturememory; // gotta play by 2.2 rules to get this to work -// highcolor stuff -INT16 color8to16[256]; // remap color index to highcolor rgb value -INT16 *hicolormaps; // test a 32k colormap remaps high -> high - // Blends two pixels together, using the equation // that matches the specified alpha style. UINT32 ASTBlendPixel(RGBA_t background, RGBA_t foreground, int style, UINT8 alpha) @@ -1661,40 +1657,6 @@ const char *R_ColormapNameForNum(INT32 num) } -// -// build a table for quick conversion from 8bpp to 15bpp -// - -// -// added "static inline" keywords, linking with the debug version -// of allegro, it have a makecol15 function of it's own, now -// with "static inline" keywords,it sloves this problem ;) -// -FUNCMATH static inline int makecol15(int r, int g, int b) -{ - return (((r >> 3) << 10) | ((g >> 3) << 5) | ((b >> 3))); -} - -static void R_Init8to16(void) -{ - UINT8 *palette; - int i; - - palette = W_CacheLumpName("PLAYPAL",PU_CACHE); - - for (i = 0; i < 256; i++) - { - // PLAYPAL uses 8 bit values - color8to16[i] = (INT16)makecol15(palette[0], palette[1], palette[2]); - palette += 3; - } - - // test a big colormap - hicolormaps = Z_Malloc(16384*sizeof(*hicolormaps), PU_STATIC, NULL); - for (i = 0; i < 16384; i++) - hicolormaps[i] = (INT16)(i<<1); -} - // // R_InitData // @@ -1703,12 +1665,6 @@ static void R_Init8to16(void) // void R_InitData(void) { - if (highcolor) - { - CONS_Printf("InitHighColor...\n"); - R_Init8to16(); - } - CONS_Printf("R_LoadTextures()...\n"); R_LoadTextures(); diff --git a/src/r_data.h b/src/r_data.h index 58afc34d0..2a74d591c 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -69,9 +69,6 @@ extern fixed_t *textureheight; // needed for texture pegging UINT32 ASTBlendPixel(RGBA_t background, RGBA_t foreground, int style, UINT8 alpha); UINT32 ASTBlendTexturePixel(RGBA_t background, RGBA_t foreground, int style, UINT8 alpha); -extern INT16 color8to16[256]; // remap color index to highcolor -extern INT16 *hicolormaps; // remap high colors to high colors.. - extern CV_PossibleValue_t Color_cons_t[]; // Load TEXTURE1/TEXTURE2/PNAMES definitions, create lookup tables diff --git a/src/screen.c b/src/screen.c index a8a3ca78b..4d239e186 100644 --- a/src/screen.c +++ b/src/screen.c @@ -8,7 +8,7 @@ // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- /// \file screen.c -/// \brief Handles multiple resolutions, 8bpp/16bpp(highcolor) modes +/// \brief Handles multiple resolutions #include "doomdef.h" #include "doomstat.h" @@ -37,7 +37,7 @@ // global video state // ------------------ viddef_t vid; -INT32 setmodeneeded; //video mode change needed if > 0 (the mode number to set + 1) +INT32 setmodeneeded; // video mode change needed if > 0 (the mode number to set + 1) static CV_PossibleValue_t shittyscreen_cons_t[] = {{0, "Okay"}, {1, "Shitty"}, {2, "Extra Shitty"}, {0, NULL}}; diff --git a/src/screen.h b/src/screen.h index 38483b28d..42bc6c144 100644 --- a/src/screen.h +++ b/src/screen.h @@ -8,7 +8,7 @@ // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- /// \file screen.h -/// \brief Handles multiple resolutions, 8bpp/16bpp(highcolor) modes +/// \brief Handles multiple resolutions #ifndef __SCREEN_H__ #define __SCREEN_H__ diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 8e19b33ac..389e086e2 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -113,8 +113,6 @@ unsigned msaa = 0; boolean a2c = false; #endif -boolean highcolor = false; - static void KeyboardLayout_OnChange(void) { HU_Shiftform(); From c98861be6eead0a719ba2b1a7a0ee181047632a3 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Sep 2025 13:07:15 +0200 Subject: [PATCH 4/4] fix tracker module playback going nuts when changing audio buffer size forgor CV_CALL :chaosleep: --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index aead25f0c..1bac40a46 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -62,7 +62,7 @@ consvar_t cv_samplerate = {"samplerate", "44100", 0, CV_Unsigned, NULL, 22050, N #endif static CV_PossibleValue_t audbuffersize_cons_t[] = {{128, "128"}, {256, "256"}, {512, "512"}, {1024, "1024"}, {2048, "2048"}, {4096, "4096"}, {0, NULL}}; -consvar_t cv_audbuffersize = {"audiobuffersize", "2048", CV_SAVE, audbuffersize_cons_t, BufferSize_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_audbuffersize = {"audiobuffersize", "2048", CV_SAVE|CV_CALL, audbuffersize_cons_t, BufferSize_OnChange, 0, NULL, NULL, 0, 0, NULL}; // stereo reverse consvar_t stereoreverse = {"stereoreverse", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL};