From f1e146906a2138c614d4204b4f376530e0cb00c7 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 8 Jan 2024 23:14:22 +0300 Subject: [PATCH 01/50] Mention crash log in crash popup --- src/sdl/i_system.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index a3813767c..5343c41de 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -420,7 +420,7 @@ static void I_ReportSignal(int num, int coredumped) { //static char msg[] = "oh no! back to reality!\r\n"; const char * sigmsg; - char msg[128]; + char msg[256]; switch (num) { @@ -459,15 +459,25 @@ static void I_ReportSignal(int num, int coredumped) sprintf(msg, "%s (core dumped)", sigmsg); else strcat(msg, " (core dumped)"); - - sigmsg = msg; } + else + { + sprintf(msg, "%s", sigmsg); + } + +#ifdef HAVE_LIBBACKTRACE + strncat(msg, "\n\nCrash report have been saved into srb2kart-crash-log.txt", 255); +#elif defined(_WIN32) + // Uuh assume we are on 32bit windows where we still have rpt files? + // Really unsure about this one + strncat(msg, "\n\nCrash report have been saved into srb2kart.rpt", 255); +#endif I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Process killed by signal", - sigmsg, NULL); + msg, NULL); } #ifndef NEWSIGNALHANDLER From c4bb4965e13622068c7d46f698013351beef91ae Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 8 Jan 2024 23:35:34 +0300 Subject: [PATCH 02/50] Better check for 32 bit windows in I_ReportSignal --- src/sdl/i_system.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 5343c41de..48ea7fea3 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -467,9 +467,7 @@ static void I_ReportSignal(int num, int coredumped) #ifdef HAVE_LIBBACKTRACE strncat(msg, "\n\nCrash report have been saved into srb2kart-crash-log.txt", 255); -#elif defined(_WIN32) - // Uuh assume we are on 32bit windows where we still have rpt files? - // Really unsure about this one +#elif defined(_WIN32) && !defined(__MINGW64__) strncat(msg, "\n\nCrash report have been saved into srb2kart.rpt", 255); #endif From 2321e4aa7f2e9a87b39b2f0800a2e07b880c284c Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 9 Jan 2024 13:38:24 +0100 Subject: [PATCH 03/50] use og values for pal --- src/hardware/r_opengl/r_opengl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 4d1fb626d..7ef8aed94 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -709,8 +709,7 @@ static float shader_leveltime = 0; "float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \ "float startmap = (15.0 - lightnum) * 4.0;\n" \ "float scale = 160.0 / (lightz + 1.0);\n" \ - "float cap = (155.0 - light) * 0.26;\n" \ - "return max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \ + "return (startmap * STARTMAP_FUDGE - scale * MULT_FUDGE * SCALE_FUDGE);\n" \ "}\n" #define GLSL_DOOM_LIGHT_EQUATION \ @@ -762,11 +761,13 @@ static float shader_leveltime = 0; #define GLSL_FLOOR_FUDGES \ "#define STARTMAP_FUDGE 1.06\n" \ + "#define MULT_FUDGE 0.5\n" \ "#define SCALE_FUDGE 1.15\n" #define GLSL_WALL_FUDGES \ "#define STARTMAP_FUDGE 1.05\n" \ - "#define SCALE_FUDGE 2.2\n" + "#define MULT_FUDGE 1.0\n" \ + "#define SCALE_FUDGE 1.1\n" #define GLSL_SOFTWARE_FRAGMENT_SHADER_FLOORS \ GLSL_SOFTWARE_UNIFORMS \ From f3e23ad621f1a52415f695b97784d003185ce381 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 10:10:34 +0100 Subject: [PATCH 04/50] WIP: redo palette rendering TODO: alot of cleanup from the old but from quick testing this seems to actually work tho since we dont have a preprocessor we still have to "switch out" the shaders at runtime also didnt bother with any special toggles yet needs alot of testing --- src/hardware/hw_cache.c | 195 ++++++++++++++- src/hardware/hw_defs.h | 6 + src/hardware/hw_drv.h | 22 +- src/hardware/hw_glob.h | 4 + src/hardware/hw_main.c | 144 ++++++----- src/hardware/hw_main.h | 7 +- src/hardware/r_opengl/ogl_win.c | 8 +- src/hardware/r_opengl/r_opengl.c | 416 ++++++++++++------------------- src/m_menu.c | 45 +--- src/p_setup.c | 3 + src/r_data.c | 6 +- src/r_defs.h | 1 - src/sdl/hwsym_sdl.c | 9 +- src/sdl/i_video.c | 9 +- src/sdl/ogl_sdl.c | 12 +- src/sdl/ogl_sdl.h | 2 +- src/st_stuff.c | 6 +- src/v_video.c | 23 +- 18 files changed, 482 insertions(+), 436 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 4255475bb..9b43fca46 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -33,12 +33,20 @@ static INT32 blocksize, blockwidth, blockheight; INT32 patchformat = GR_TEXFMT_AP_88; // use alpha for holes INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole +RGBA_t mapPalette[256] = {0}; // the palette for the currently loaded level or menu etc. + +// Returns a pointer to the palette which should be used for caching textures. +static RGBA_t *HWR_GetTexturePalette(void) +{ + return HWR_ShouldUsePaletteRendering() ? mapPalette : pLocalPalette; +} + // sprite, use alpha and chroma key for hole static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 pblockheight, INT32 blockmodulo, INT32 ptexturewidth, INT32 ptextureheight, INT32 originx, INT32 originy, // where to draw patch in surface block - const patch_t *realpatch, INT32 bpp) + const patch_t *realpatch, INT32 bpp, RGBA_t *palette) { INT32 x, x1, x2; INT32 col, ncols; @@ -67,6 +75,8 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, if (!ptexturewidth) return; + + palette = HWR_GetTexturePalette(); col = x * pblockwidth / ptexturewidth; ncols = ((x2 - x) * pblockwidth) / ptexturewidth; @@ -152,10 +162,10 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap, case 2 : texelu16 = (UINT16)((alpha<<8) | texel); memcpy(dest, &texelu16, sizeof(UINT16)); break; - case 3 : colortemp = V_GetColor(texel); + case 3 : colortemp = palette[texel]; memcpy(dest, &colortemp, sizeof(RGBA_t)-sizeof(UINT8)); break; - case 4 : colortemp = V_GetColor(texel); + case 4 : colortemp = palette[texel]; colortemp.s.alpha = alpha; memcpy(dest, &colortemp, sizeof(RGBA_t)); break; @@ -329,6 +339,9 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex) INT32 i; boolean skyspecial = false; //poor hack for Legacy large skies.. + + RGBA_t *palette; + palette = HWR_GetTexturePalette(); texture = textures[texnum]; @@ -349,7 +362,12 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex) HWR_ResizeBlock (texture->width, texture->height, &grtex->mipmap.grInfo); grtex->mipmap.width = (UINT16)blockwidth; grtex->mipmap.height = (UINT16)blockheight; - grtex->mipmap.grInfo.format = textureformat; + //grtex->mipmap.grInfo.format = textureformat; + + if (skyspecial) + grtex->mipmap.grInfo.format = GR_RGBA; // that skyspecial code below assumes this format ... + else + grtex->mipmap.grInfo.format = textureformat; grtex->mipmap.colormap = colormaps; @@ -365,7 +383,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex) INT32 j; RGBA_t col; - col = V_GetColor(HWR_CHROMAKEY_EQUIVALENTCOLORINDEX); + col = palette[HWR_CHROMAKEY_EQUIVALENTCOLORINDEX]; for (j = 0; j < blockheight; j++) { for (i = 0; i < blockwidth; i++) @@ -388,7 +406,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex) texture->width, texture->height, patch->originx, patch->originy, realpatch, - format2bpp[grtex->mipmap.grInfo.format]); + format2bpp[grtex->mipmap.grInfo.format], palette); Z_Unlock(realpatch); } //Hurdler: not efficient at all but I don't remember exactly how HWR_DrawPatchInCache works :( @@ -412,6 +430,8 @@ static void HWR_GenerateTexture(INT32 texnum, GLTexture_t *grtex) void HWR_MakePatch (patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap) { INT32 newwidth, newheight; + + RGBA_t *palette = HWR_GetTexturePalette(); // don't do it twice (like a cache) if (grMipmap->width == 0) @@ -456,7 +476,7 @@ void HWR_MakePatch (patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, bo grPatch->width, grPatch->height, 0, 0, patch, - format2bpp[grMipmap->grInfo.format]); + format2bpp[grMipmap->grInfo.format], palette); } grPatch->max_s = (float)newwidth / (float)blockwidth; @@ -557,7 +577,7 @@ void HWR_PrepLevelCache(size_t pnumtextures) I_Error("HWR_PrepLevelCache: can't alloc gr_textures"); } -void HWR_SetPalette(RGBA_t *palette) +/*void HWR_SetPalette(RGBA_t *palette) { //Hudler: 16/10/99: added for OpenGL gamma correction RGBA_t gamma_correction = {0x7F7F7F7F}; @@ -575,7 +595,7 @@ void HWR_SetPalette(RGBA_t *palette) Z_FreeTags(PU_HWRCACHE, PU_HWRCACHE); Z_FreeTags(PU_HWRCACHE_UNLOCKED, PU_HWRCACHE_UNLOCKED); } -} +}*/ // -------------------------------------------------------------------------- // Make sure texture is downloaded and set it as the source // -------------------------------------------------------------------------- @@ -821,6 +841,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 UINT8 *flat; UINT8 *dest, *src, texel; RGBA_t col; + RGBA_t *palette = HWR_GetTexturePalette(); // Place the flats data into flat W_ReadLump(fademasklumpnum, Z_Malloc(W_LumpLength(fademasklumpnum), @@ -838,7 +859,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32 { // fademask bpp is always 1, and is used just for alpha texel = src[(posx)>>FRACBITS]; - col = V_GetColor(texel); + col = palette[texel]; *dest = col.s.red; // take the red level of the colour and use it for alpha, as fademasks do dest++; @@ -914,4 +935,158 @@ void HWR_GetFadeMask(lumpnum_t fademasklumpnum) Z_ChangeTag(grmip->grInfo.data, PU_HWRCACHE_UNLOCKED); } +// ================================================= +// PALETTE HANDLING +// ================================================= + +void HWR_SetPalette(RGBA_t *palette) +{ + if (HWR_ShouldUsePaletteRendering()) + { + // set the palette for palette postprocessing + + { + // crush to 16-bit rgb565, like software currently does in the standard configuration + // Note: Software's screenshots have the 24-bit palette, but the screen gets + // the 16-bit version! For making comparison screenshots either use an external screenshot + // tool or set the palette depth to 24 bits. + RGBA_t crushed_palette[256]; + int i; + for (i = 0; i < 256; i++) + { + float fred = (float)(palette[i].s.red >> 3); + float fgreen = (float)(palette[i].s.green >> 2); + float fblue = (float)(palette[i].s.blue >> 3); + crushed_palette[i].s.red = (UINT8)(fred / 31.0f * 255.0f); + crushed_palette[i].s.green = (UINT8)(fgreen / 63.0f * 255.0f); + crushed_palette[i].s.blue = (UINT8)(fblue / 31.0f * 255.0f); + crushed_palette[i].s.alpha = 255; + } + HWD.pfnSetScreenPalette(crushed_palette); + } + + // this part is responsible for keeping track of the palette OUTSIDE of a level. + if (!(gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN))) + HWR_SetMapPalette(); + } + else + { + // set the palette for the textures + HWD.pfnSetTexturePalette(palette); + // reset mapPalette so next call to HWR_SetMapPalette will update everything correctly + memset(mapPalette, 0, sizeof(mapPalette)); + // hardware driver will flush there own cache if cache is non paletized + // now flush data texture cache so 32 bit texture are recomputed + //if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA) + if (patchformat == GR_RGBA || textureformat == GR_RGBA) + { + Z_FreeTag(PU_HWRCACHE); + Z_FreeTag(PU_HWRCACHE_UNLOCKED); + } + } +} + +static void HWR_SetPaletteLookup(RGBA_t *palette) +{ + int r, g, b; + UINT8 *lut = Z_Malloc( + HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*sizeof(UINT8), + PU_STATIC, NULL); +#define STEP_SIZE (256/HWR_PALETTE_LUT_SIZE) + for (b = 0; b < HWR_PALETTE_LUT_SIZE; b++) + { + for (g = 0; g < HWR_PALETTE_LUT_SIZE; g++) + { + for (r = 0; r < HWR_PALETTE_LUT_SIZE; r++) + { + lut[b*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE+g*HWR_PALETTE_LUT_SIZE+r] = + NearestColor(r*STEP_SIZE, g*STEP_SIZE, b*STEP_SIZE); + } + } + } +#undef STEP_SIZE + HWD.pfnSetPaletteLookup(lut); + Z_Free(lut); +} + +// Updates mapPalette to reflect the loaded level or other game state. +// Textures are flushed if needed. +// Call this function only in palette rendering mode. +void HWR_SetMapPalette(void) +{ + RGBA_t RGBA_converted[256]; + RGBA_t *palette; + int i; + + if (!(gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN))) //we dont have a master palette + { + // outside of a level, pMasterPalette should have PLAYPAL ready for us + //palette = pMasterPalette; // we dont have this in kart so just use plocalpalette as before + + palette = pLocalPalette; + } + else + { + // in a level pMasterPalette might have a flash palette, but we + // want the map's original palette. + lumpnum_t lumpnum = W_GetNumForName(GetPalette()); + size_t palsize = W_LumpLength(lumpnum); + UINT8 *RGB_data; + if (palsize < 768) // 256 * 3 + I_Error("HWR_SetMapPalette: A programmer assumed palette lumps are at least 768 bytes long, but apparently this was a wrong assumption!\n"); + RGB_data = W_CacheLumpNum(lumpnum, PU_CACHE); + // we got the RGB palette now, but we need it in RGBA format. + for (i = 0; i < 256; i++) + { + RGBA_converted[i].s.red = *(RGB_data++); + RGBA_converted[i].s.green = *(RGB_data++); + RGBA_converted[i].s.blue = *(RGB_data++); + RGBA_converted[i].s.alpha = 255; + } + palette = RGBA_converted; + } + + // check if the palette has changed from the previous one + if (memcmp(mapPalette, palette, sizeof(mapPalette))) + { + memcpy(mapPalette, palette, sizeof(mapPalette)); + // in palette rendering mode, this means that all rgba textures now have wrong colors + // and the lookup table is outdated + HWR_SetPaletteLookup(mapPalette); + HWD.pfnSetTexturePalette(mapPalette); + //if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA) + if (patchformat == GR_RGBA || textureformat == GR_RGBA) + { + Z_FreeTag(PU_HWRCACHE); + Z_FreeTag(PU_HWRCACHE_UNLOCKED); + } + } +} + +// Creates a hardware lighttable from the supplied lighttable. +// Returns the id of the hw lighttable, usable in FSurfaceInfo. +UINT32 HWR_CreateLightTable(UINT8 *lighttable) +{ + UINT32 i, id; + RGBA_t *palette = HWR_GetTexturePalette(); + RGBA_t *hw_lighttable = Z_Malloc(256 * 32 * sizeof(RGBA_t), PU_STATIC, NULL); + + // To make the palette index -> RGBA mapping easier for the shader, + // the hardware lighttable is composed of RGBA colors instead of palette indices. + for (i = 0; i < 256 * 32; i++) + hw_lighttable[i] = palette[lighttable[i]]; + + id = HWD.pfnCreateLightTable(hw_lighttable); + Z_Free(hw_lighttable); + return id; +} + +// Note: all hardware lighttable ids assigned before this +// call become invalid and must not be used. +void HWR_ClearLightTables(void) +{ + //if (vid.glstate == VID_GL_LIBRARY_LOADED) + HWD.pfnClearLightTables(); +} + #endif //HWRENDER diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 28cdd87e1..87e6b33cc 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -25,6 +25,12 @@ #define NZCLIP_PLANE 0.9f // Seems to be only used for the HUD and screen textures #define FAR_ZCLIP_DEFAULT 32768.0f +// The width/height/depth of the palette lookup table used by palette rendering. +// Changing this also requires changing the shader code! +// Also assumed to be a power of two in some parts of the code. +// 64 seems to work perfectly for the vanilla palette. +#define HWR_PALETTE_LUT_SIZE 64 + // ========================================================================== // SIMPLE TYPES // ========================================================================== diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index b231e76c4..60ea552b2 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -29,11 +29,7 @@ EXPORT boolean HWRAPI(Init) (void); EXPORT void HWRAPI(SetupGLInfo) (void); -#if defined (PURESDL) || defined (macintosh) -EXPORT void HWRAPI(SetPalette) (INT32 *, RGBA_t *gamma); -#else -EXPORT void HWRAPI(SetPalette) (RGBA_t *ppal, RGBA_t *pgamma); -#endif +EXPORT void HWRAPI(SetTexturePalette) (RGBA_t *ppal); EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl); EXPORT void HWRAPI(Draw2DLine) (F2DCoord *v1, F2DCoord *v2, RGBA_t Color); EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, boolean horizonSpecial); @@ -84,9 +80,10 @@ EXPORT boolean HWRAPI(InitCustomShaders) (void); EXPORT void HWRAPI(StartBatching) (void); EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, int *sNumPolys, int *sNumVerts, int *sNumCalls, int *sNumShaders, int *sNumTextures, int *sNumPolyFlags, int *sNumColors); -EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut); -EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable); -EXPORT void HWRAPI(ClearLightTableCache) (void); +EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut); +EXPORT UINT32 HWRAPI(CreateLightTable)(RGBA_t *hw_lighttable); +EXPORT void HWRAPI(ClearLightTables)(void); +EXPORT void HWRAPI(SetScreenPalette)(RGBA_t *palette); // ========================================================================== // HWR DRIVER OBJECT, FOR CLIENT PROGRAM @@ -98,7 +95,7 @@ struct hwdriver_s { Init pfnInit; SetupGLInfo pfnSetupGLInfo; - SetPalette pfnSetPalette; + SetTexturePalette pfnSetTexturePalette; FinishUpdate pfnFinishUpdate; Draw2DLine pfnDraw2DLine; DrawPolygon pfnDrawPolygon; @@ -139,9 +136,10 @@ struct hwdriver_s StartBatching pfnStartBatching; RenderBatches pfnRenderBatches; - InitPalette pfnInitPalette; - AddLightTable pfnAddLightTable; - ClearLightTableCache pfnClearLightTableCache; + SetPaletteLookup pfnSetPaletteLookup; + CreateLightTable pfnCreateLightTable; + ClearLightTables pfnClearLightTables; + SetScreenPalette pfnSetScreenPalette; }; extern struct hwdriver_s hwdriver; diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 1950a10da..3423bd09c 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -68,6 +68,10 @@ void HWR_GetMappedPatch(GLPatch_t *gpatch, const UINT8 *colormap); void HWR_MakePatch(patch_t *patch, GLPatch_t *grPatch, GLMipmap_t *grMipmap, boolean makebitmap); void HWR_UnlockCachedPatch(GLPatch_t *gpatch); void HWR_SetPalette(RGBA_t *palette); + +void HWR_SetMapPalette(void); +UINT32 HWR_CreateLightTable(UINT8 *lighttable); +void HWR_ClearLightTables(void); GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump); GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum); void HWR_GetFadeMask(lumpnum_t fademasklumpnum); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9ba76a32b..19e146368 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -57,6 +57,12 @@ // ========================================================================== struct hwdriver_s hwdriver; + +boolean gr_shadersavailable = true; + +// Whether the internal state is set to palette rendering or not. +static boolean gr_palette_rendering_state = false; + // ========================================================================== // Commands and console variables // ========================================================================== @@ -66,15 +72,7 @@ static void CV_anisotropic_ONChange(void); static void CV_screentextures_ONChange(void); static void CV_useCustomShaders_ONChange(void); static void CV_grshaders_OnChange(void); -static void CV_Gammaxxx_ONChange(void); - -static CV_PossibleValue_t grgamma_cons_t[] = {{1, "MIN"}, {255, "MAX"}, {0, NULL}}; -consvar_t cv_grgammared = {"gr_gammared", "127", CV_SAVE|CV_CALL, grgamma_cons_t, - CV_Gammaxxx_ONChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grgammagreen = {"gr_gammagreen", "127", CV_SAVE|CV_CALL, grgamma_cons_t, - CV_Gammaxxx_ONChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grgammablue = {"gr_gammablue", "127", CV_SAVE|CV_CALL, grgamma_cons_t, - CV_Gammaxxx_ONChange, 0, NULL, NULL, 0, 0, NULL}; +static void CV_grpaletterendering_OnChange(void); static CV_PossibleValue_t grfakecontrast_cons_t[] = {{0, "Off"}, {1, "Standard"}, {2, "Smooth"}, {0, NULL}}; @@ -147,9 +145,9 @@ consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL|CV_SAVE, CV_ consvar_t cv_grshaders = {"gr_shaders", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE, CV_OnOff, CV_useCustomShaders_ONChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grpaletteshader = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grpaletterendering = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; +//consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grmdls = {"gr_mdls", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfallbackplayermodel = {"gr_fallbackplayermodel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -181,13 +179,12 @@ static void CV_screentextures_ONChange(void) static void CV_grshaders_OnChange(void) { if (rendermode == render_opengl) - { - if (HWR_ShouldUsePaletteRendering()) - HWR_InitPalette(0, false); - - HWD.pfnSetSpecialState(HWD_PAL_SHADER, HWR_ShouldUsePaletteRendering()); - V_SetPalette(0); + + if (cv_grpaletterendering.value) + { + // can't do palette rendering without shaders, so update the state if needed + HWR_TogglePaletteRendering(); } } @@ -197,25 +194,18 @@ static void CV_useCustomShaders_ONChange(void) { if (HWR_UseShader()) HWD.pfnInitCustomShaders(); - - if (HWR_ShouldUsePaletteRendering()) - HWR_InitPalette(0, false); } } -// change the palette directly to see the change -static void CV_Gammaxxx_ONChange(void) -{ - if (rendermode == render_opengl) - V_SetPalette(0); -} -void HWR_InitPalette(int flashnum, boolean skiplut) +static void CV_grpaletterendering_OnChange(void) { - HWD.pfnInitPalette(flashnum, skiplut); + if (gr_shadersavailable) + { + HWR_TogglePaletteRendering(); + } } - // ========================================================================== // Globals // ========================================================================== @@ -247,8 +237,6 @@ static sector_t *gr_backsector; static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfaceInfo* Surf, INT32 cutflag, ffloor_t *pfloor, FBITFIELD polyflags); -boolean gr_shadersavailable = true; - // Performance stats ps_metric_t ps_hw_nodesorttime = {0}; ps_metric_t ps_hw_nodedrawtime = {0}; @@ -446,13 +434,13 @@ boolean HWR_UseShader(void) boolean HWR_ShouldUsePaletteRendering(void) { - return (cv_grpaletteshader.value && HWR_UseShader()); + return (cv_grpaletterendering.value && HWR_UseShader()); } -boolean HWR_PalRenderFlashpal(void) +/*boolean HWR_PalRenderFlashpal(void) { - return (cv_grpaletteshader.value && HWR_UseShader() && cv_grflashpal.value); -} + return (cv_grpaletterendering.value && HWR_UseShader() && cv_grflashpal.value); +}*/ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap) { @@ -512,34 +500,30 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col if (HWR_ShouldUsePaletteRendering()) { + boolean default_colormap = false; if (!colormap) { - colormap = &extra_colormaps[num_extra_colormaps]; + colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id + // alternatively could just store the id in a global variable if there are issues default_colormap = true; } + // create hw lighttable if there isn't one if (!colormap->gl_lighttable_id) - { + { UINT8 *colormap_pointer; if (default_colormap) - { - colormap_pointer = colormaps; - } + colormap_pointer = colormaps; // don't actually use the data from the "default colormap" else - { colormap_pointer = colormap->colormap; - } - colormap->gl_lighttable_id = HWD.pfnAddLightTable(colormap_pointer); + colormap->gl_lighttable_id = HWR_CreateLightTable(colormap_pointer); } - Surface->LightTableId = colormap->gl_lighttable_id; } -} - -void HWR_ClearLightTableCache(void) -{ - if (rendermode == render_opengl) - HWD.pfnClearLightTableCache(); + else + { + Surface->LightTableId = 0; + } } UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if this can work @@ -862,7 +846,8 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc if (PolyFlags & PF_Fog) HWD.pfnSetShader(6); // fog shader else if (PolyFlags & PF_Ripple) - HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 11 : 5); // water shader + //HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 11 : 5); // water shader + HWD.pfnSetShader(5); // water shader else HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader @@ -6329,7 +6314,48 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) HWR_RenderFrame(viewnumber, player, false); } +// enable or disable palette rendering state depending on settings and availability +// called when relevant settings change +// shader recompilation is done in the cvar callback +void HWR_TogglePaletteRendering(void) +{ + // which state should we go to? + if (HWR_ShouldUsePaletteRendering()) + { + // are we not in that state already? + if (!gr_palette_rendering_state) + { + gr_palette_rendering_state = true; + // The textures will still be converted to RGBA by r_opengl. + // This however makes hw_cache use paletted blending for composite textures! + // (patchformat is not touched) + textureformat = GR_TEXFMT_P_8; + + HWR_SetMapPalette(); + HWR_SetPalette(pLocalPalette); + + // If the r_opengl "texture palette" stays the same during this switch, the textures + // will not be cleared out. However they are still out of date since the + // composite texture blending method has changed. Therefore they need to be cleared. + HWD.pfnClearMipMapCache(); + } + } + else + { + // are we not in that state already? + if (gr_palette_rendering_state) + { + gr_palette_rendering_state = false; + textureformat = GR_RGBA; + HWR_SetPalette(pLocalPalette); + // If the r_opengl "texture palette" stays the same during this switch, the textures + // will not be cleared out. However they are still out of date since the + // composite texture blending method has changed. Therefore they need to be cleared. + HWD.pfnClearMipMapCache(); + } + } +} //added by Hurdler: console varibale that are saved @@ -6351,9 +6377,6 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grrenderdistance); - CV_RegisterVar(&cv_grgammablue); - CV_RegisterVar(&cv_grgammagreen); - CV_RegisterVar(&cv_grgammared); CV_RegisterVar(&cv_grfakecontrast); CV_RegisterVar(&cv_grslopecontrast); @@ -6376,8 +6399,8 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_secbright); - CV_RegisterVar(&cv_grpaletteshader); - CV_RegisterVar(&cv_grflashpal); + CV_RegisterVar(&cv_grpaletterendering); + //CV_RegisterVar(&cv_grflashpal); CV_RegisterVar(&cv_grvhseffect); } @@ -6393,21 +6416,22 @@ void HWR_Startup(void) if (!startupdone) { CONS_Printf("HWR_Startup()...\n"); + textureformat = patchformat = GR_RGBA; + HWR_InitTextureCache(); HWR_InitMD2(); HWD.pfnSetupGLInfo(); } - if (rendermode == render_opengl) - textureformat = patchformat = GR_RGBA; - startupdone = true; // jimita HWD.pfnKillShaders(); if (!HWD.pfnLoadShaders()) gr_shadersavailable = false; + + HWR_TogglePaletteRendering(); if (msaa) { @@ -6490,7 +6514,7 @@ void HWR_DoPostProcessor(player_t *player) // Armageddon Blast Flash! // Could this even be considered postprocessor? - if ((player->flashcount) && (!HWR_PalRenderFlashpal())) + if (player->flashcount) { FOutVector v[4]; FSurfaceInfo Surf; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 3dc18ccf8..25c69c1d8 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -177,9 +177,6 @@ extern consvar_t cv_grfov; extern consvar_t cv_grmdls; extern consvar_t cv_grfog; extern consvar_t cv_grfogdensity; -extern consvar_t cv_grgammared; -extern consvar_t cv_grgammagreen; -extern consvar_t cv_grgammablue; extern consvar_t cv_grfiltermode; extern consvar_t cv_granisotropicmode; extern consvar_t cv_grcorrecttricks; @@ -192,9 +189,9 @@ extern consvar_t cv_grfallbackplayermodel; extern consvar_t cv_grbatching; extern consvar_t cv_grrenderdistance; extern consvar_t cv_grusecustomshaders; -extern consvar_t cv_grpaletteshader; +extern consvar_t cv_grpaletterendering; extern consvar_t cv_grscreentextures; -extern consvar_t cv_grflashpal; +//extern consvar_t cv_grflashpal; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright; diff --git a/src/hardware/r_opengl/ogl_win.c b/src/hardware/r_opengl/ogl_win.c index 562afe998..90376f276 100644 --- a/src/hardware/r_opengl/ogl_win.c +++ b/src/hardware/r_opengl/ogl_win.c @@ -564,15 +564,15 @@ EXPORT void HWRAPI(FinishUpdate) (INT32 waitvbl) // : in OpenGL, we store values for conversion of paletted graphics when // : they are downloaded to the 3D card. // -----------------+ -EXPORT void HWRAPI(SetPalette) (RGBA_t *pal, RGBA_t *gamma) +EXPORT void HWRAPI(SetPalette) (RGBA_t *pal) { INT32 i; for (i = 0; i < 256; i++) { - myPaletteData[i].s.red = (UINT8)MIN((pal[i].s.red*gamma->s.red)/127, 255); - myPaletteData[i].s.green = (UINT8)MIN((pal[i].s.green*gamma->s.green)/127, 255); - myPaletteData[i].s.blue = (UINT8)MIN((pal[i].s.blue*gamma->s.blue)/127, 255); + myPaletteData[i].s.red = pal[i].s.red; + myPaletteData[i].s.green = pal[i].s.green; + myPaletteData[i].s.blue = pal[i].s.blue; myPaletteData[i].s.alpha = pal[i].s.alpha; } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 7ef8aed94..45ed02269 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -51,13 +51,19 @@ struct GLRGBAFloat }; typedef struct GLRGBAFloat GLRGBAFloat; -static const GLubyte white[4] = { 255, 255, 255, 255 }; +// lighttable list item +struct LTListItem +{ + UINT32 id; + struct LTListItem *next; +}; +typedef struct LTListItem LTListItem; // ========================================================================== // CONSTANTS // ========================================================================== - +static const GLubyte white[4] = { 255, 255, 255, 255 }; // With OpenGL 1.1+, the first texture should be 1 #define NOTEXTURE_NUM 0 @@ -82,16 +88,15 @@ static FBITFIELD CurrentPolyFlags; static FTextureInfo *gr_cachetail = NULL; static FTextureInfo *gr_cachehead = NULL; -typedef struct LightTableCacheEntry_s -{ - GLuint id; - struct LightTableCacheEntry_s *next; -} LightTableCacheEntry_t; +// Linked list of all lighttables. +static LTListItem *LightTablesTail = NULL; +static LTListItem *LightTablesHead = NULL; -LightTableCacheEntry_t *ltcachehead = NULL; -LightTableCacheEntry_t *ltcachetail = NULL; +static RGBA_t screenPalette[256] = {0}; // the palette for the postprocessing step in palette rendering +static GLuint screenPaletteTex = 0; // 1D texture containing the screen palette +static GLuint paletteLookupTex = 0; // 3D texture containing RGB -> palette index lookup table +RGBA_t myPaletteData[256]; // the palette for converting textures to RGBA -RGBA_t myPaletteData[256]; GLint screen_width = 0; // used by Draw2DLine() GLint screen_height = 0; GLbyte screen_depth = 0; @@ -429,10 +434,10 @@ typedef void (APIENTRY * PFNglTexEnvi) (GLenum target, GLenum pname, GLint param static PFNglTexEnvi pglTexEnvi; typedef void (APIENTRY * PFNglTexParameteri) (GLenum target, GLenum pname, GLint param); static PFNglTexParameteri pglTexParameteri; +typedef void (APIENTRY * PFNglTexImage1D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +static PFNglTexImage1D pglTexImage1D; typedef void (APIENTRY * PFNglTexImage2D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexImage2D pglTexImage2D; -typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); -static PFNglTexImage3D pglTexImage3D; typedef void (APIENTRY * PFNglTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); static PFNglTexSubImage2D pglTexSubImage2D; @@ -461,6 +466,10 @@ typedef void (APIENTRY * PFNglGenerateMipmap) (GLenum target); static PFNglGenerateMipmap pglGenerateMipmap; #endif +/* 1.2 functions for 3D textures */ +typedef void (APIENTRY * PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); +static PFNglTexImage3D pglTexImage3D; + /* 1.3 functions for multitexturing */ typedef void (APIENTRY *PFNglActiveTexture) (GLenum); static PFNglActiveTexture pglActiveTexture; @@ -560,6 +569,7 @@ boolean SetupGLfunc(void) GETOPENGLFUNC(pglTexEnvi, glTexEnvi) GETOPENGLFUNC(pglTexParameteri, glTexParameteri) + GETOPENGLFUNC(pglTexImage1D, glTexImage1D) GETOPENGLFUNC(pglTexImage2D, glTexImage2D) GETOPENGLFUNC(pglTexSubImage2D , glTexSubImage2D) @@ -640,10 +650,6 @@ static boolean gl_shaderprogramchanged = true; static boolean gl_batching = false;// are we currently collecting batches? -static GLint gl_palette[768]; -boolean gl_palette_initialized = false; -static boolean gl_palshader = false; - static INT32 gl_enable_screen_textures = 1; static GLint gl_portal_stencil_level = 0; @@ -662,10 +668,10 @@ typedef enum gluniform_fade_end, // palette rendering - gluniform_palette, - gluniform_color_lookup, + gluniform_screen_palette_tex, + gluniform_palette_lookup_tex, gluniform_lighttable_tex, - + // misc. gluniform_leveltime, @@ -709,7 +715,8 @@ static float shader_leveltime = 0; "float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \ "float startmap = (15.0 - lightnum) * 4.0;\n" \ "float scale = 160.0 / (lightz + 1.0);\n" \ - "return (startmap * STARTMAP_FUDGE - scale * MULT_FUDGE * SCALE_FUDGE);\n" \ + "float cap = (155.0 - light) * 0.26;\n" \ + "return max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \ "}\n" #define GLSL_DOOM_LIGHT_EQUATION \ @@ -759,15 +766,14 @@ static float shader_leveltime = 0; "gl_FragColor = final_color;\n" \ "}\n" +// hand tuned adjustments for light level calculation #define GLSL_FLOOR_FUDGES \ "#define STARTMAP_FUDGE 1.06\n" \ - "#define MULT_FUDGE 0.5\n" \ "#define SCALE_FUDGE 1.15\n" #define GLSL_WALL_FUDGES \ "#define STARTMAP_FUDGE 1.05\n" \ - "#define MULT_FUDGE 1.0\n" \ - "#define SCALE_FUDGE 1.1\n" + "#define SCALE_FUDGE 2.2\n" #define GLSL_SOFTWARE_FRAGMENT_SHADER_FLOORS \ GLSL_SOFTWARE_UNIFORMS \ @@ -787,21 +793,19 @@ static float shader_leveltime = 0; #define GLSL_SOFTWARE_PAL_UNIFORMS \ "uniform sampler2D tex;\n" \ + "uniform sampler3D palette_lookup_tex;\n" \ "uniform sampler2D lighttable_tex;\n" \ - "uniform sampler3D lookup_tex;\n" \ - "uniform int palette[768];\n" \ "uniform vec4 poly_color;\n" \ "uniform float lighting;\n" \ #define GLSL_SOFTWARE_PAL_MAIN \ "void main(void) {\n" \ "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "int tex_pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ + "float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \ "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ - "int light_y = int(clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0));\n" \ - "vec2 lighttable_coord = vec2((float(tex_pal_idx) + 0.5) / 256.0, (float(light_y) + 0.5) / 32.0);\n" \ - "int final_idx = int(texture2D(lighttable_tex, lighttable_coord)[0] * 255.0);\n" \ - "vec4 final_color = vec4(float(palette[final_idx*3])/255.0, float(palette[final_idx*3+1])/255.0, float(palette[final_idx*3+2])/255.0, 1.0);\n" \ + "float light_y = clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0);\n" \ + "vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (light_y + 0.5) / 32.0);\n" \ + "vec4 final_color = texture2D(lighttable_tex, lighttable_coord);\n" \ "final_color.a = texel.a * poly_color.a;\n" \ "gl_FragColor = final_color;\n" \ "}\n" @@ -857,7 +861,7 @@ static float shader_leveltime = 0; "gl_FragColor = final_color;\n" \ "}\0" -#define GLSL_PALETTE_WATER_FRAGMENT_SHADER \ +/*#define GLSL_PALETTE_WATER_FRAGMENT_SHADER \ GLSL_FLOOR_FUDGES \ "const float freq = 0.025;\n" \ "const float amp = 0.025;\n" \ @@ -885,7 +889,7 @@ static float shader_leveltime = 0; "vec4 final_color = vec4(float(palette[final_idx*3])/255.0, float(palette[final_idx*3+1])/255.0, float(palette[final_idx*3+2])/255.0, 1.0);\n" \ "final_color.a = texel.a * poly_color.a;\n" \ "gl_FragColor = final_color;\n" \ - "}\0" + "}\0"*/ // // Fog block shader @@ -916,12 +920,14 @@ static float shader_leveltime = 0; #define GLSL_PALETTE_FRAGMENT_SHADER \ "uniform sampler2D tex;\n" \ - "uniform sampler3D lookup_tex;\n" \ - "uniform int palette[768];\n" \ + "uniform sampler3D palette_lookup_tex;\n" \ + "uniform sampler1D screen_palette_tex;\n" \ "void main(void) {\n" \ - "vec3 texel = vec3(texture2D(tex, gl_TexCoord[0].st));\n" \ - "int pal_idx = int(texture3D(lookup_tex, vec3((63.0/64.0) * texel + 1.0 / 128.0))[0] * 255.0);\n" \ - "gl_FragColor = vec4(float(palette[pal_idx*3])/255.0, float(palette[pal_idx*3+1])/255.0, float(palette[pal_idx*3+2])/255.0, 1.0);\n" \ + "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ + "float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \ + "float palette_coord = (tex_pal_idx + 0.5) / 256.0;\n" \ + "vec4 final_color = texture1D(screen_palette_tex, palette_coord);\n" \ + "gl_FragColor = final_color;\n" \ "}\0" // @@ -970,7 +976,7 @@ static const char *fragment_shaders[] = { GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_WALLS, // Palette water shader - GLSL_PALETTE_WATER_FRAGMENT_SHADER, + //GLSL_PALETTE_WATER_FRAGMENT_SHADER, NULL, }; @@ -1021,7 +1027,7 @@ static const char *vertex_shaders[] = { GLSL_DEFAULT_VERTEX_SHADER, GLSL_DEFAULT_VERTEX_SHADER, GLSL_DEFAULT_VERTEX_SHADER, - GLSL_DEFAULT_VERTEX_SHADER, + //GLSL_DEFAULT_VERTEX_SHADER, NULL, }; @@ -1030,7 +1036,9 @@ static const char *vertex_shaders[] = { void SetupGLFunc4(void) { + /* 1.2 funcs */ pglTexImage3D = GetGLFunc("glTexImage3D"); + /* 1.3 funcs */ pglActiveTexture = GetGLFunc("glActiveTexture"); pglMultiTexCoord2f = GetGLFunc("glMultiTexCoord2f"); pglClientActiveTexture = GetGLFunc("glClientActiveTexture"); @@ -1199,14 +1207,13 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_fade_start] = GETUNI("fade_start"); shader->uniforms[gluniform_fade_end] = GETUNI("fade_end"); - // misc. (custom shaders) - shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); - // palette rendering - shader->uniforms[gluniform_palette] = GETUNI("palette"); - shader->uniforms[gluniform_color_lookup] = GETUNI("lookup_tex"); + shader->uniforms[gluniform_screen_palette_tex] = GETUNI("screen_palette_tex"); + shader->uniforms[gluniform_palette_lookup_tex] = GETUNI("palette_lookup_tex"); shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex"); - + + // misc. + shader->uniforms[gluniform_leveltime] = GETUNI("leveltime"); #undef GETUNI // set permanent uniform values @@ -1214,22 +1221,18 @@ EXPORT boolean HWRAPI(LoadShaders) (void) 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 - UNIFORM_2(shader->uniforms[gluniform_palette], 768, gl_palette, pglUniform1iv); - UNIFORM_1(shader->uniforms[gluniform_color_lookup], 1, pglUniform1i); + UNIFORM_1(shader->uniforms[gluniform_screen_palette_tex], 2, pglUniform1i); + UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 1, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i); - - pglUseProgram(0); + // restore gl shader state + //pglUseProgram(gl_shaderstate.program); + pglUseProgram(gl_currentshaderprogram); + //pglUseProgram(0); #undef UNIFORM_1 -#undef UNIFORM_2 - } #endif return true; @@ -1334,130 +1337,6 @@ EXPORT void HWRAPI(KillShaders) (void) // unused......................... } -GLuint palette_tex_num; -// length of one side of lookup texture -// smallest separation between all the colors in the srb2 palette is 6, so -// possibly a 64x64x64 lookup texture might be enough for 100% correct colors -// (min separation for 64^3 size is 4) -#define LUT_SIZE 64 -#define STEP_SIZE (256/LUT_SIZE) -// the +2 in the NearestColor call also needs to be adjusted if LUT_SIZE is changed! -// the hardcoded values in the shader also need to be adjusted if LUT_SIZE is changed! - -EXPORT void HWRAPI(InitPalette) (int flashnum, boolean skiplut) -{ - int i, r, g, b; - - //Hudler: 16/10/99: added for OpenGL gamma correction - RGBA_t gamma_correction = {0x7F7F7F7F}; - - //Hurdler 16/10/99: added for OpenGL gamma correction - gamma_correction.s.red = (UINT8)cv_grgammared.value; - gamma_correction.s.green = (UINT8)cv_grgammagreen.value; - gamma_correction.s.blue = (UINT8)cv_grgammablue.value; - - // init the palette - int flashoffset = flashnum*256; - for (i = 0+flashoffset; i < 256+flashoffset; i++) - { - int fi = i-flashoffset; - - // gamma correction - int pr, pg, pb; - pr = (UINT8)MIN((pLocalPalette[i].s.red*gamma_correction.s.red)/127, 255); - pg = (UINT8)MIN((pLocalPalette[i].s.green*gamma_correction.s.green)/127, 255); - pb = (UINT8)MIN((pLocalPalette[i].s.blue*gamma_correction.s.blue)/127, 255); - - // crush to 16-bit rgb565, like software currently does - float fred = (float)(pr >> 3); - float fgreen = (float)(pg >> 2); - float fblue = (float)(pb >> 3); - // restore to rgb888 - gl_palette[fi*3] = (GLint)(fred / 31.0f * 255.0f); - gl_palette[fi*3+1] = (GLint)(fgreen / 63.0f * 255.0f); - gl_palette[fi*3+2] = (GLint)(fblue / 31.0f * 255.0f); - } - - if (!skiplut) - { - 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. - // so use GL_LUMINANCE8 instead to get a single component 8-bit format - // (it is possible to have access to shaders even in some OpenGL 1.x systems, - // so palette rendering can still possibly be achieved there) - internalFormat = GL_LUMINANCE8; - } - else - { - internalFormat = GL_R8; - } - - // init the palette conversion lookup texture - GLubyte *pal_lookup_tex = malloc(LUT_SIZE*LUT_SIZE*LUT_SIZE*sizeof(GLubyte)); - - if (!pal_lookup_tex) - I_Error("Failed to allocate memory for generating palette lookup texture."); - - for (b = 0; b < LUT_SIZE; b++) - { - for (g = 0; g < LUT_SIZE; g++) - { - for (r = 0; r < LUT_SIZE; r++) - { - pal_lookup_tex[b*LUT_SIZE*LUT_SIZE+g*LUT_SIZE+r] = NearestColor(r*STEP_SIZE+0, g*STEP_SIZE+0, b*STEP_SIZE+0); - } - } - } - - pglGenTextures(1, &palette_tex_num); - pglBindTexture(GL_TEXTURE_3D, palette_tex_num); - pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - if (!pglTexImage3D){ - GL_MSG_Error("pglTexImage3D is NULL!"); - CV_Set(&cv_grpaletteshader, "Off"); // turn that thing off if you cant use it - return; - } - - pglTexImage3D(GL_TEXTURE_3D, 0, internalFormat, LUT_SIZE, LUT_SIZE, LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, pal_lookup_tex); - free(pal_lookup_tex); - } -#undef STEP_SIZE - - pglUseProgram(gl_shaderprograms[8].program); - pglUniform1i(gl_shaderprograms[8].uniforms[gluniform_color_lookup], 1); // bind sampler to second texture unit - pglUniform1iv(gl_shaderprograms[8].uniforms[gluniform_palette], 768, gl_palette); - // bind the palette to the fancy shader here - pglUseProgram(gl_shaderprograms[9].program); - pglUniform1iv(gl_shaderprograms[9].uniforms[gluniform_palette], 768, gl_palette); - // bind tex unit 2 to lighttable tex - pglUniform1i(gl_shaderprograms[9].uniforms[gluniform_lighttable_tex], 2); - pglUniform1i(gl_shaderprograms[9].uniforms[gluniform_color_lookup], 1); - // bind the palette to the fancy shader here - pglUseProgram(gl_shaderprograms[10].program); - pglUniform1iv(gl_shaderprograms[10].uniforms[gluniform_palette], 768, gl_palette); - // bind tex unit 2 to lighttable tex - pglUniform1i(gl_shaderprograms[10].uniforms[gluniform_lighttable_tex], 2); - pglUniform1i(gl_shaderprograms[10].uniforms[gluniform_color_lookup], 1); - // bind stuff to wöter shader - pglUseProgram(gl_shaderprograms[11].program); - pglUniform1iv(gl_shaderprograms[11].uniforms[gluniform_palette], 768, gl_palette); - pglUniform1i(gl_shaderprograms[11].uniforms[gluniform_lighttable_tex], 2); - pglUniform1i(gl_shaderprograms[11].uniforms[gluniform_color_lookup], 1); - - pglUseProgram(0); - pglBindTexture(GL_TEXTURE_3D, 0); - - // bind 3d lookup to unit 1, maybe it can stay there - pglActiveTexture(GL_TEXTURE1); - pglBindTexture(GL_TEXTURE_3D, palette_tex_num); - pglActiveTexture(GL_TEXTURE0); - gl_palette_initialized = true; -} - // -----------------+ // SetNoTexture : Disable texture // -----------------+ @@ -1645,65 +1524,6 @@ EXPORT void HWRAPI(ClearMipMapCache) (void) Flush(); } -EXPORT UINT32 HWRAPI(AddLightTable) (UINT8 *lighttable) -{ - LightTableCacheEntry_t *cache_entry = malloc(sizeof(LightTableCacheEntry_t)); - if (!ltcachetail) - { - ltcachehead = ltcachetail = cache_entry; - } - else - { - ltcachetail->next = cache_entry; - ltcachetail = cache_entry; - } - ltcachetail->next = NULL; - - 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. - // so use GL_LUMINANCE8 instead to get a single component 8-bit format - // (it is possible to have access to shaders even in some OpenGL 1.x systems, - // so palette rendering can still possibly be achieved there) - internalFormat = GL_LUMINANCE8; - } - else - { - internalFormat = GL_R8; - } - - pglGenTextures(1, <cachetail->id); - if (!ltcachetail->id){ - GL_MSG_Error("HWR Lighttable cache entry id is zero"); - CV_Set(&cv_grpaletteshader, "Off"); // turn that thing off if you cant use it - return; - } - pglBindTexture(GL_TEXTURE_2D, ltcachetail->id); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 256, 32, 0, GL_RED, GL_UNSIGNED_BYTE, lighttable); - - // restore previously bound texture - if (!gl_batching) - pglBindTexture(GL_TEXTURE_2D, tex_downloaded); - - return ltcachetail->id; -} - -// Delete light table textures, ids given before become invalid and must not be used. -EXPORT void HWRAPI(ClearLightTableCache) (void) -{ - while (ltcachehead) - { - pglDeleteTextures(1, <cachehead->id); - LightTableCacheEntry_t *next = ltcachehead->next; - free(ltcachehead); - ltcachehead = next; - } - ltcachetail = NULL; -} - // -----------------+ // ReadRect : Read a rectangle region of the truecolor framebuffer // : store pixels as 16bit 565 RGB @@ -1815,8 +1635,8 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too - if ((!gl_palette_initialized) && (gl_palshader)) - InitPalette(0, false); // just gonna put this here for now + //if ((!gl_palette_initialized) && (gl_palshader)) + //InitPalette(0, false); // just gonna put this here for now } @@ -2033,6 +1853,8 @@ EXPORT void HWRAPI(UpdateTexture) (FTextureInfo *pTexInfo) w = pTexInfo->width; h = pTexInfo->height; + if (w*h > 2048*2048 && pTexInfo->grInfo.format != GL_RGBA) + I_Error("Tried to convert too big texture: %dx%d", w, h); if ((pTexInfo->grInfo.format == GR_TEXFMT_P_8) || (pTexInfo->grInfo.format == GR_TEXFMT_AP_88)) @@ -2438,7 +2260,7 @@ static int comparePolygons(const void *p1, const void *p2) diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; - if (gl_palshader) + if (HWR_ShouldUsePaletteRendering()) { diff = poly1->surf.LightTableId - poly2->surf.LightTableId; if (diff != 0) return diff; @@ -2581,9 +2403,10 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i if (gl_allowshaders) { Shader_Load(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade); - if (gl_palshader) + + if (HWR_ShouldUsePaletteRendering()) { - pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now + pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId); pglActiveTexture(GL_TEXTURE0); } @@ -2698,7 +2521,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeState = true; changePolyFlags = true; } - if (gl_allowshaders && gl_palshader) + if (gl_allowshaders && HWR_ShouldUsePaletteRendering()) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2712,7 +2535,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i changeSurfaceInfo = true; } } - else if ((gl_allowshaders) && (!gl_palshader)) + else if ((gl_allowshaders) && (!HWR_ShouldUsePaletteRendering())) { if (currentSurfaceInfo.PolyColor.rgba != nextSurfaceInfo.PolyColor.rgba || currentSurfaceInfo.TintColor.rgba != nextSurfaceInfo.TintColor.rgba || @@ -2790,6 +2613,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha]; Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade); + currentShader = nextShader; changeShader = false; @@ -2843,9 +2667,9 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade); - if (gl_palshader) + if (HWR_ShouldUsePaletteRendering()) { - pglActiveTexture(GL_TEXTURE2);// this stuff could be done better but gonna do it quick like this for now + pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId); pglActiveTexture(GL_TEXTURE0); } @@ -2952,13 +2776,13 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.green = byte2float[pSurf->FadeColor.s.green]; fade.blue = byte2float[pSurf->FadeColor.s.blue]; fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; - } - - if (gl_palshader && gl_allowshaders) - { - pglActiveTexture(GL_TEXTURE2); - pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); - pglActiveTexture(GL_TEXTURE0); + + if (HWR_ShouldUsePaletteRendering()) + { + pglActiveTexture(GL_TEXTURE2); + pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); + pglActiveTexture(GL_TEXTURE0); + } } } @@ -3303,9 +3127,9 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) } break; - case HWD_PAL_SHADER: - gl_palshader = Value; - break; + //case HWD_PAL_SHADER: + //gl_palshader = Value; + //break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) @@ -4499,15 +4323,15 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) clearColour.red = clearColour.green = clearColour.blue = 0; clearColour.alpha = 1; ClearBuffer(true, false, false, &clearColour); - if (gl_palshader) + /*if (gl_palshader) { SetBlend(PF_NoDepthTest); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); } - else + else*/ pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - if (gl_palshader) + //if (gl_palshader) { pglUseProgram(gl_shaderprograms[8].program); // palette postprocess shader pglActiveTexture(GL_TEXTURE2); @@ -4521,11 +4345,81 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; - if (gl_palshader) + //if (gl_palshader) { pglUseProgram(0); pglActiveTexture(GL_TEXTURE0); } } + +EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut) +{ + if (!paletteLookupTex) + pglGenTextures(1, &paletteLookupTex); + pglActiveTexture(GL_TEXTURE1); + pglBindTexture(GL_TEXTURE_3D, paletteLookupTex); + pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, + 0, GL_RED, GL_UNSIGNED_BYTE, lut); + pglActiveTexture(GL_TEXTURE0); +} + +EXPORT UINT32 HWRAPI(CreateLightTable)(RGBA_t *hw_lighttable) +{ + LTListItem *item = malloc(sizeof(LTListItem)); + if (!LightTablesTail) + { + LightTablesHead = LightTablesTail = item; + } + else + { + LightTablesTail->next = item; + LightTablesTail = item; + } + item->next = NULL; + pglGenTextures(1, &item->id); + pglBindTexture(GL_TEXTURE_2D, item->id); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + pglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + pglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, hw_lighttable); + + // restore previously bound texture + pglBindTexture(GL_TEXTURE_2D, tex_downloaded); + + return item->id; +} + +// Delete light table textures, ids given before become invalid and must not be used. +EXPORT void HWRAPI(ClearLightTables)(void) +{ + while (LightTablesHead) + { + LTListItem *item = LightTablesHead; + pglDeleteTextures(1, (GLuint *)&item->id); + LightTablesHead = item->next; + free(item); + } + + LightTablesTail = NULL; +} + +// This palette is used for the palette rendering postprocessing step. +EXPORT void HWRAPI(SetScreenPalette)(RGBA_t *palette) +{ + if (memcmp(screenPalette, palette, sizeof(screenPalette))) + { + memcpy(screenPalette, palette, sizeof(screenPalette)); + if (!screenPaletteTex) + pglGenTextures(1, &screenPaletteTex); + pglActiveTexture(GL_TEXTURE2); + pglBindTexture(GL_TEXTURE_1D, screenPaletteTex); + pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + pglTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + pglTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, palette); + pglActiveTexture(GL_TEXTURE0); + } +} + #endif //HWRENDER diff --git a/src/m_menu.c b/src/m_menu.c index c46cf9cca..201391727 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -319,7 +319,7 @@ static void M_ResetControls(INT32 choice); // Video & Sound menu_t OP_VideoOptionsDef, OP_VideoModeDef, OP_ExpOptionsDef; #ifdef HWRENDER -menu_t OP_OpenGLOptionsDef, OP_OpenGLColorDef; +menu_t OP_OpenGLOptionsDef; #endif menu_t OP_SoundOptionsDef; menu_t OP_SoundAdvancedDef; @@ -410,9 +410,6 @@ static void M_DrawVideoMenu(void); static void M_DrawHUDOptions(void); static void M_DrawVideoMode(void); static void M_DrawMonitorToggles(void); -#ifdef HWRENDER -static void M_OGL_DrawColorMenu(void); -#endif static void M_DrawMPMainMenu(void); #ifndef NONET static void M_DrawConnectMenu(void); @@ -1497,8 +1494,8 @@ static menuitem_t OP_OpenGLOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Fallback Player 3D Model", &cv_grfallbackplayermodel, 20}, {IT_STRING | IT_CVAR, NULL, "Shaders", &cv_grshaders, 25}, //{IT_STRING|IT_CVAR, NULL, "Use custom Shaders", &cv_grusecustomshaders, 35}, - {IT_STRING | IT_CVAR, NULL, "Palette Rendering", &cv_grpaletteshader, 30}, - {IT_STRING | IT_CVAR, NULL, "Flashpals in Palette Renderer", &cv_grflashpal, 35}, + {IT_STRING | IT_CVAR, NULL, "Palette Rendering", &cv_grpaletterendering, 30}, + //{IT_STRING | IT_CVAR, NULL, "Flashpals in Palette Renderer", &cv_grflashpal, 35}, {IT_STRING | IT_CVAR, NULL, "Min Shader Brightness", &cv_secbright, 40}, {IT_STRING|IT_CVAR, NULL, "Texture Quality", &cv_scr_depth, 50}, @@ -1511,8 +1508,6 @@ static menuitem_t OP_OpenGLOptionsMenu[] = {IT_STRING|IT_CVAR, NULL, "Sprite Billboarding", &cv_grspritebillboarding, 85}, {IT_STRING|IT_CVAR, NULL, "Software Perspective", &cv_grshearing, 90}, {IT_STRING|IT_CVAR, NULL, "Rendering Distance", &cv_grrenderdistance, 95}, - - {IT_SUBMENU|IT_STRING, NULL, "Gamma...", &OP_OpenGLColorDef, 105}, }; static const char* OP_OpenGLTooltips[] = @@ -1532,15 +1527,8 @@ static const char* OP_OpenGLTooltips[] = "Should sprites always face the camera?", "Recreates the look of software mode camera perspective.", "How far the game world should be drawn.", - "Gamma (brightness) of colors.", }; -static menuitem_t OP_OpenGLColorMenu[] = -{ - {IT_STRING|IT_CVAR|IT_CV_SLIDER, NULL, "Red", &cv_grgammared, 10}, - {IT_STRING|IT_CVAR|IT_CV_SLIDER, NULL, "Green", &cv_grgammagreen, 20}, - {IT_STRING|IT_CVAR|IT_CV_SLIDER, NULL, "Blue", &cv_grgammablue, 30}, -}; #endif static menuitem_t OP_SoundOptionsMenu[] = @@ -2835,19 +2823,6 @@ menu_t OP_MonitorToggleDef = #ifdef HWRENDER menu_t OP_OpenGLOptionsDef = DEFAULTSCROLLSTYLE("M_VIDEO", OP_OpenGLOptionsMenu, &OP_VideoOptionsDef, 30, 30); - -menu_t OP_OpenGLColorDef = -{ - "M_VIDEO", - sizeof (OP_OpenGLColorMenu)/sizeof (menuitem_t), - &OP_OpenGLOptionsDef, - OP_OpenGLColorMenu, - M_OGL_DrawColorMenu, - 60, 40, - 0, - NULL, - NULL -}; #endif menu_t OP_ExpOptionsDef = DEFAULTMENUSTYLE("M_VIDEO", OP_ExpOptionsMenu, &OP_VideoOptionsDef, 30, 30); @@ -14296,20 +14271,6 @@ static void M_QuitSRB2(INT32 choice) // ===================================================================== // OpenGL specific options // ===================================================================== - -// ===================== -// M_OGL_DrawColorMenu() -// ===================== -static void M_OGL_DrawColorMenu(void) -{ - INT32 mx, my; - - mx = currentMenu->x; - my = currentMenu->y; - M_DrawGenericMenu(); // use generic drawer for cursor, items and title - V_DrawString(mx, my + currentMenu->menuitems[0].alphaKey - 10, - highlightflags, "Gamma correction"); -} #endif #ifdef HAVE_DISCORDRPC diff --git a/src/p_setup.c b/src/p_setup.c index d85488c9f..3fb2fae12 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3149,6 +3149,9 @@ boolean P_SetupLevel(boolean skipprecip) HWR_CorrectSWTricks(); HWR_CreatePlanePolygons((INT32)numnodes - 1); } + + if (HWR_ShouldUsePaletteRendering()) + HWR_SetMapPalette(); #endif // oh god I hope this helps diff --git a/src/r_data.c b/src/r_data.c index 48a421170..597ee0052 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -28,6 +28,8 @@ #ifdef HWRENDER #include "hardware/hw_main.h" + +#include "hardware/hw_glob.h" // HWR_ClearLightTables #endif #ifdef _WIN32 @@ -1139,8 +1141,8 @@ void R_ClearColormaps(void) memset(extra_colormaps, 0, sizeof (extra_colormaps)); #ifdef HWRENDER - HWR_ClearLightTableCache(); -#endif + HWR_ClearLightTables(); +#endif } /*INT32 R_ColormapNumForName(char *name) diff --git a/src/r_defs.h b/src/r_defs.h index 8811d64e2..085d25e0b 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -63,7 +63,6 @@ typedef struct INT32 fadergba; // The colour the colourmaps fade to lighttable_t *colormap; - #ifdef HWRENDER // The id of the hardware lighttable. Zero means it does not exist yet. diff --git a/src/sdl/hwsym_sdl.c b/src/sdl/hwsym_sdl.c index 96b7b0679..bbb5d9df3 100644 --- a/src/sdl/hwsym_sdl.c +++ b/src/sdl/hwsym_sdl.c @@ -74,7 +74,7 @@ void *hwSym(const char *funcName,void *handle) { void *funcPointer = NULL; #ifdef HWRENDER - if (0 == strcmp("SetPalette", funcName)) + if (0 == strcmp("SetTexturePalette", funcName)) funcPointer = &OglSdlSetPalette; GETFUNC(Init); @@ -118,9 +118,10 @@ void *hwSym(const char *funcName,void *handle) GETFUNC(StartBatching); GETFUNC(RenderBatches); - GETFUNC(InitPalette); - GETFUNC(AddLightTable); - GETFUNC(ClearLightTableCache); + GETFUNC(SetPaletteLookup); + GETFUNC(CreateLightTable); + GETFUNC(ClearLightTables); + GETFUNC(SetScreenPalette); #else //HWRENDER if (0 == strcmp("FinishUpdate", funcName)) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index dd2953716..335353976 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2121,7 +2121,7 @@ void I_StartupGraphics(void) HWD.pfnGClipRect = hwSym("GClipRect",NULL); HWD.pfnClearMipMapCache = hwSym("ClearMipMapCache",NULL); HWD.pfnSetSpecialState = hwSym("SetSpecialState",NULL); - HWD.pfnSetPalette = hwSym("SetPalette",NULL); + HWD.pfnSetTexturePalette= hwSym("SetTexturePalette",NULL); HWD.pfnGetTextureUsed = hwSym("GetTextureUsed",NULL); HWD.pfnDrawModel = hwSym("DrawModel",NULL); HWD.pfnCreateModelVBOs = hwSym("CreateModelVBOs",NULL); @@ -2151,9 +2151,10 @@ void I_StartupGraphics(void) HWD.pfnStartBatching = hwSym("StartBatching",NULL); HWD.pfnRenderBatches = hwSym("RenderBatches",NULL); - HWD.pfnInitPalette = hwSym("InitPalette",NULL); - HWD.pfnAddLightTable = hwSym("AddLightTable",NULL); - HWD.pfnClearLightTableCache = hwSym("ClearLightTableCache",NULL); + HWD.pfnSetPaletteLookup = hwSym("SetPaletteLookup",NULL); + HWD.pfnCreateLightTable = hwSym("CreateLightTable",NULL); + HWD.pfnClearLightTables = hwSym("ClearLightTables",NULL); + HWD.pfnSetScreenPalette = hwSym("SetScreenPalette",NULL); if (!HWD.pfnInit()) // load the OpenGL library rendermode = render_soft; diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index b3f7be3fa..9cc2d1a94 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -236,17 +236,15 @@ void OglSdlFinishUpdate(boolean waitvbl) HWR_DrawScreenFinalTexture(realwidth, realheight); } -EXPORT void HWRAPI(OglSdlSetPalette) (RGBA_t *palette, RGBA_t *pgamma) +EXPORT void HWRAPI(OglSdlSetPalette) (RGBA_t *palette) { - INT32 i = -1; - UINT32 redgamma = pgamma->s.red, greengamma = pgamma->s.green, - bluegamma = pgamma->s.blue; + INT32 i = 1; for (i = 0; i < 256; i++) { - myPaletteData[i].s.red = (UINT8)MIN((palette[i].s.red * redgamma) /127, 255); - myPaletteData[i].s.green = (UINT8)MIN((palette[i].s.green * greengamma)/127, 255); - myPaletteData[i].s.blue = (UINT8)MIN((palette[i].s.blue * bluegamma) /127, 255); + myPaletteData[i].s.red = palette[i].s.red; + myPaletteData[i].s.green = palette[i].s.green; + myPaletteData[i].s.blue = palette[i].s.blue; myPaletteData[i].s.alpha = palette[i].s.alpha; } Flush(); diff --git a/src/sdl/ogl_sdl.h b/src/sdl/ogl_sdl.h index 2d6209f2b..1a547f09c 100644 --- a/src/sdl/ogl_sdl.h +++ b/src/sdl/ogl_sdl.h @@ -30,5 +30,5 @@ extern Uint16 realwidth; extern Uint16 realheight; #ifdef _CREATE_DLL_ -EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette, RGBA_t *pgamma); +EXPORT void HWRAPI( OglSdlSetPalette ) (RGBA_t *palette); #endif diff --git a/src/st_stuff.c b/src/st_stuff.c index 17788d6a6..104fb0609 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -245,7 +245,7 @@ void ST_doPaletteStuff(void) palette = 0; #ifdef HWRENDER - if ((rendermode == render_opengl) && (!HWR_PalRenderFlashpal())) + if (rendermode == render_opengl && !HWR_ShouldUsePaletteRendering()) palette = 0; // No flashpals here in OpenGL #endif @@ -254,7 +254,7 @@ void ST_doPaletteStuff(void) st_palette = palette; #ifdef HWRENDER - if (rendermode == render_soft || (rendermode == render_opengl && HWR_PalRenderFlashpal())) + if (rendermode == render_soft || (rendermode == render_opengl && HWR_ShouldUsePaletteRendering())) #else if (rendermode != render_none) #endif @@ -2207,7 +2207,7 @@ void ST_Drawer(void) //25/08/99: Hurdler: palette changes is done for all players, // not only player1! That's why this part // of code is moved somewhere else. - if (rendermode == render_soft || (rendermode == render_opengl && HWR_PalRenderFlashpal())) + if (rendermode == render_soft || HWR_ShouldUsePaletteRendering()) #endif if (rendermode != render_none) ST_doPaletteStuff(); diff --git a/src/v_video.c b/src/v_video.c index 28a02bcff..04424c9cb 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -203,17 +203,8 @@ void V_SetPalette(INT32 palettenum) LoadMapPalette(); #ifdef HWRENDER - if (rendermode != render_soft && rendermode != render_none) { - // in palette rendering mode, we already manage our palette ourselves - if (HWR_ShouldUsePaletteRendering()) - { - // reset our palette lookups n shit - gl_palette_initialized = false; - HWR_InitPalette(palettenum, true); - } - else - HWR_SetPalette(&pLocalPalette[palettenum*256]); - } + if (rendermode != render_soft && rendermode != render_none) + HWR_SetPalette(&pLocalPalette[palettenum*256]); #if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) else #endif @@ -226,16 +217,8 @@ void V_SetPaletteLump(const char *pal) { LoadPalette(pal); #ifdef HWRENDER - if (rendermode != render_soft && rendermode != render_none) { - if (HWR_ShouldUsePaletteRendering()) - { - // reset our palette lookups n shit - gl_palette_initialized = false; - HWR_InitPalette(0, false); - } - + if (rendermode != render_soft && rendermode != render_none) HWR_SetPalette(pLocalPalette); - } #if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) else #endif From 3635d4adb170eab4f52cc409d2053cbcfdccdd76 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 10:42:30 +0100 Subject: [PATCH 05/50] Fix Flashpal toggle --- src/hardware/hw_main.c | 10 +++++----- src/m_menu.c | 2 +- src/st_stuff.c | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 19e146368..a06d0b969 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -147,7 +147,7 @@ consvar_t cv_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE consvar_t cv_grpaletterendering = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL}; -//consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grmdls = {"gr_mdls", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grfallbackplayermodel = {"gr_fallbackplayermodel", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -437,10 +437,10 @@ boolean HWR_ShouldUsePaletteRendering(void) return (cv_grpaletterendering.value && HWR_UseShader()); } -/*boolean HWR_PalRenderFlashpal(void) +boolean HWR_PalRenderFlashpal(void) { return (cv_grpaletterendering.value && HWR_UseShader() && cv_grflashpal.value); -}*/ +} void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap) { @@ -6400,7 +6400,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_secbright); CV_RegisterVar(&cv_grpaletterendering); - //CV_RegisterVar(&cv_grflashpal); + CV_RegisterVar(&cv_grflashpal); CV_RegisterVar(&cv_grvhseffect); } @@ -6514,7 +6514,7 @@ void HWR_DoPostProcessor(player_t *player) // Armageddon Blast Flash! // Could this even be considered postprocessor? - if (player->flashcount) + if ((player->flashcount) && (!HWR_PalRenderFlashpal())) { FOutVector v[4]; FSurfaceInfo Surf; diff --git a/src/m_menu.c b/src/m_menu.c index 201391727..6e2a9b5ba 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1495,7 +1495,7 @@ static menuitem_t OP_OpenGLOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Shaders", &cv_grshaders, 25}, //{IT_STRING|IT_CVAR, NULL, "Use custom Shaders", &cv_grusecustomshaders, 35}, {IT_STRING | IT_CVAR, NULL, "Palette Rendering", &cv_grpaletterendering, 30}, - //{IT_STRING | IT_CVAR, NULL, "Flashpals in Palette Renderer", &cv_grflashpal, 35}, + {IT_STRING | IT_CVAR, NULL, "Flashpals in Palette Renderer", &cv_grflashpal, 35}, {IT_STRING | IT_CVAR, NULL, "Min Shader Brightness", &cv_secbright, 40}, {IT_STRING|IT_CVAR, NULL, "Texture Quality", &cv_scr_depth, 50}, diff --git a/src/st_stuff.c b/src/st_stuff.c index 104fb0609..37b75d586 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -245,7 +245,7 @@ void ST_doPaletteStuff(void) palette = 0; #ifdef HWRENDER - if (rendermode == render_opengl && !HWR_ShouldUsePaletteRendering()) + if (rendermode == render_opengl && !HWR_PalRenderFlashpal()) palette = 0; // No flashpals here in OpenGL #endif @@ -254,7 +254,7 @@ void ST_doPaletteStuff(void) st_palette = palette; #ifdef HWRENDER - if (rendermode == render_soft || (rendermode == render_opengl && HWR_ShouldUsePaletteRendering())) + if (rendermode == render_soft || (rendermode == render_opengl && HWR_PalRenderFlashpal())) #else if (rendermode != render_none) #endif @@ -2207,7 +2207,7 @@ void ST_Drawer(void) //25/08/99: Hurdler: palette changes is done for all players, // not only player1! That's why this part // of code is moved somewhere else. - if (rendermode == render_soft || HWR_ShouldUsePaletteRendering()) + if (rendermode == render_soft || HWR_PalRenderFlashpal()) #endif if (rendermode != render_none) ST_doPaletteStuff(); From f8979ed80aba7e6f2e7a00dafe6adb9f7035417b Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 10:47:05 +0100 Subject: [PATCH 06/50] forgor --- src/hardware/hw_main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 25c69c1d8..2e88f9336 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -191,7 +191,7 @@ extern consvar_t cv_grrenderdistance; extern consvar_t cv_grusecustomshaders; extern consvar_t cv_grpaletterendering; extern consvar_t cv_grscreentextures; -//extern consvar_t cv_grflashpal; +extern consvar_t cv_grflashpal; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright; From 0ef4edc2579c7c07e9143fd9f502b36a28a27cd1 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 10:48:59 +0100 Subject: [PATCH 07/50] Fix Pal water shader TODO: make this not half the pal shader again --- src/hardware/hw_main.c | 3 +-- src/hardware/r_opengl/r_opengl.c | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a06d0b969..b133c1bc5 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -846,8 +846,7 @@ void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isc if (PolyFlags & PF_Fog) HWD.pfnSetShader(6); // fog shader else if (PolyFlags & PF_Ripple) - //HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 11 : 5); // water shader - HWD.pfnSetShader(5); // water shader + HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 11 : 5); // water shader else HWD.pfnSetShader(HWR_ShouldUsePaletteRendering() ? 9 : 1); // floor shader diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 45ed02269..5d7e536ea 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -861,16 +861,15 @@ static float shader_leveltime = 0; "gl_FragColor = final_color;\n" \ "}\0" -/*#define GLSL_PALETTE_WATER_FRAGMENT_SHADER \ +#define GLSL_PALETTE_WATER_FRAGMENT_SHADER \ GLSL_FLOOR_FUDGES \ "const float freq = 0.025;\n" \ "const float amp = 0.025;\n" \ "const float speed = 2.0;\n" \ "const float pi = 3.14159;\n" \ "uniform sampler2D tex;\n" \ + "uniform sampler3D palette_lookup_tex;\n" \ "uniform sampler2D lighttable_tex;\n" \ - "uniform sampler3D lookup_tex;\n" \ - "uniform int palette[768];\n" \ "uniform vec4 poly_color;\n" \ "uniform float lighting;\n" \ "uniform float leveltime;\n" \ @@ -881,16 +880,15 @@ static float shader_leveltime = 0; "float sdistort = sin(a) * amp;\n" \ "float cdistort = cos(a) * amp;\n" \ "vec4 texel = texture2D(tex, vec2(gl_TexCoord[0].s - sdistort, gl_TexCoord[0].t - cdistort));\n" \ - "int tex_pal_idx = int(texture3D(lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0);\n" \ + "float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \ "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ - "int light_y = int(clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0));\n" \ - "vec2 lighttable_coord = vec2((float(tex_pal_idx) + 0.5) / 256.0, (float(light_y) + 0.5) / 32.0);\n" \ - "int final_idx = int(texture2D(lighttable_tex, lighttable_coord)[0] * 255.0);\n" \ - "vec4 final_color = vec4(float(palette[final_idx*3])/255.0, float(palette[final_idx*3+1])/255.0, float(palette[final_idx*3+2])/255.0, 1.0);\n" \ + "float light_y = clamp(floor(R_DoomColormap(lighting, z)), 0.0, 31.0);\n" \ + "vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (light_y + 0.5) / 32.0);\n" \ + "vec4 final_color = texture2D(lighttable_tex, lighttable_coord);\n" \ "final_color.a = texel.a * poly_color.a;\n" \ "gl_FragColor = final_color;\n" \ - "}\0"*/ - + "}\0" + // // Fog block shader // @@ -976,7 +974,7 @@ static const char *fragment_shaders[] = { GLSL_SOFTWARE_PAL_FRAGMENT_SHADER_WALLS, // Palette water shader - //GLSL_PALETTE_WATER_FRAGMENT_SHADER, + GLSL_PALETTE_WATER_FRAGMENT_SHADER, NULL, }; @@ -1027,7 +1025,7 @@ static const char *vertex_shaders[] = { GLSL_DEFAULT_VERTEX_SHADER, GLSL_DEFAULT_VERTEX_SHADER, GLSL_DEFAULT_VERTEX_SHADER, - //GLSL_DEFAULT_VERTEX_SHADER, + GLSL_DEFAULT_VERTEX_SHADER, NULL, }; From bb24b767a6b0e05aa0dd94d3b93b2292434e7515 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 10:57:29 +0100 Subject: [PATCH 08/50] we need this stuff but do it like new palshader --- src/hardware/r_opengl/r_opengl.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 5d7e536ea..432a56990 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -82,6 +82,9 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; static GLuint tex_downloaded = 0; +static GLuint lt_downloaded = 0; // currently bound lighttable texture - currentSurfaceInfo +static GLuint lt_downloaded2 = 0; // currently bound lighttable texture - nextSurfaceInfo +static GLuint lt_downloaded3 = 0; // currently bound lighttable texture - pSurf static GLfloat fov = 90.0f; static FBITFIELD CurrentPolyFlags; @@ -1632,9 +1635,6 @@ EXPORT void HWRAPI(ClearBuffer) (FBOOLEAN ColorMask, pglClear(ClearMask); pglEnableClientState(GL_VERTEX_ARRAY); // We always use this one pglEnableClientState(GL_TEXTURE_COORD_ARRAY); // And mostly this one, too - - //if ((!gl_palette_initialized) && (gl_palshader)) - //InitPalette(0, false); // just gonna put this here for now } @@ -2402,11 +2402,12 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i { Shader_Load(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade); - if (HWR_ShouldUsePaletteRendering()) + if (currentSurfaceInfo.LightTableId && currentSurfaceInfo.LightTableId != lt_downloaded) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId); pglActiveTexture(GL_TEXTURE0); + lt_downloaded = currentSurfaceInfo.LightTableId; } } @@ -2664,12 +2665,13 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i fade.alpha = byte2float[nextSurfaceInfo.FadeColor.s.alpha]; Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade); - - if (HWR_ShouldUsePaletteRendering()) + + if (nextSurfaceInfo.LightTableId && nextSurfaceInfo.LightTableId != lt_downloaded2) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId); pglActiveTexture(GL_TEXTURE0); + lt_downloaded2 = nextSurfaceInfo.LightTableId; } } @@ -2775,11 +2777,12 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.blue = byte2float[pSurf->FadeColor.s.blue]; fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; - if (HWR_ShouldUsePaletteRendering()) + if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded3) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); pglActiveTexture(GL_TEXTURE0); + lt_downloaded3 = pSurf->LightTableId; } } } @@ -4401,6 +4404,11 @@ EXPORT void HWRAPI(ClearLightTables)(void) } LightTablesTail = NULL; + + // we no longer have a bound light table (if we had one), we just deleted it! + lt_downloaded = 0; + lt_downloaded2 = 0; + lt_downloaded3 = 0; } // This palette is used for the palette rendering postprocessing step. From f4ded02c23200d6751241dedac029a5562865c42 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 12:48:13 +0100 Subject: [PATCH 09/50] change some thing + cleanup also changed added nearestpalettecolor its entirely backwards compat but works better for the pal lookup in pal rendermode --- src/hardware/hw_cache.c | 21 +-------------------- src/hardware/r_opengl/r_opengl.c | 15 +++++++-------- src/r_data.c | 12 ++++++++---- src/r_data.h | 3 ++- src/sdl/i_video.c | 12 ++++++++++++ 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 9b43fca46..a13d5c658 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -577,25 +577,6 @@ void HWR_PrepLevelCache(size_t pnumtextures) I_Error("HWR_PrepLevelCache: can't alloc gr_textures"); } -/*void HWR_SetPalette(RGBA_t *palette) -{ - //Hudler: 16/10/99: added for OpenGL gamma correction - RGBA_t gamma_correction = {0x7F7F7F7F}; - - //Hurdler 16/10/99: added for OpenGL gamma correction - gamma_correction.s.red = (UINT8)cv_grgammared.value; - gamma_correction.s.green = (UINT8)cv_grgammagreen.value; - gamma_correction.s.blue = (UINT8)cv_grgammablue.value; - HWD.pfnSetPalette(palette, &gamma_correction); - - // hardware driver will flush there own cache if cache is non paletized - // now flush data texture cache so 32 bit texture are recomputed - if (patchformat == GR_RGBA || textureformat == GR_RGBA) - { - Z_FreeTags(PU_HWRCACHE, PU_HWRCACHE); - Z_FreeTags(PU_HWRCACHE_UNLOCKED, PU_HWRCACHE_UNLOCKED); - } -}*/ // -------------------------------------------------------------------------- // Make sure texture is downloaded and set it as the source // -------------------------------------------------------------------------- @@ -1000,7 +981,7 @@ static void HWR_SetPaletteLookup(RGBA_t *palette) for (r = 0; r < HWR_PALETTE_LUT_SIZE; r++) { lut[b*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE+g*HWR_PALETTE_LUT_SIZE+r] = - NearestColor(r*STEP_SIZE, g*STEP_SIZE, b*STEP_SIZE); + NearestPaletteColor(r*STEP_SIZE, g*STEP_SIZE, b*STEP_SIZE, palette); } } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 432a56990..f9d0e44e9 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3127,10 +3127,6 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) break; } break; - - //case HWD_PAL_SHADER: - //gl_palshader = Value; - //break; case HWD_SET_TEXTUREFILTERMODE: switch (Value) @@ -4324,19 +4320,22 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) clearColour.red = clearColour.green = clearColour.blue = 0; clearColour.alpha = 1; ClearBuffer(true, false, false, &clearColour); - /*if (gl_palshader) + if (HWR_ShouldUsePaletteRendering()) { SetBlend(PF_NoDepthTest); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); } - else*/ + else pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - //if (gl_palshader) + if (HWR_ShouldUsePaletteRendering()) { pglUseProgram(gl_shaderprograms[8].program); // palette postprocess shader pglActiveTexture(GL_TEXTURE2); } + + // prepare shader, if it is enabled + //Shader_SetUniforms(NULL, NULL, NULL, NULL); pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); @@ -4346,7 +4345,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; - //if (gl_palshader) + if (HWR_ShouldUsePaletteRendering()) { pglUseProgram(0); pglActiveTexture(GL_TEXTURE0); diff --git a/src/r_data.c b/src/r_data.c index 597ee0052..23629af03 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1414,16 +1414,20 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) // Thanks to quake2 source! // utils3/qdata/images.c -UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b) +UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette) { int dr, dg, db; int distortion, bestdistortion = 256 * 256 * 4, bestcolor = 0, i; + // Use local palette if none specified + if (palette == NULL) + palette = pLocalPalette; + for (i = 0; i < 256; i++) { - dr = r - pLocalPalette[i].s.red; - dg = g - pLocalPalette[i].s.green; - db = b - pLocalPalette[i].s.blue; + dr = r - palette[i].s.red; + dg = g - palette[i].s.green; + db = b - palette[i].s.blue; distortion = dr*dr + dg*dg + db*db; if (distortion < bestdistortion) { diff --git a/src/r_data.h b/src/r_data.h index 6a8806988..ec1146322 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -100,7 +100,8 @@ void R_MakeInvertmap(void); #endif const char *R_ColormapNameForNum(INT32 num); -UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b); +UINT8 NearestPaletteColor(UINT8 r, UINT8 g, UINT8 b, RGBA_t *palette); +#define NearestColor(r, g, b) NearestPaletteColor(r, g, b, NULL) extern INT32 numtextures; diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 335353976..d3a7c8ae3 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1483,6 +1483,18 @@ void I_FinishUpdate(void) #ifdef HWRENDER else if (rendermode == render_opengl) { + /*// Final postprocess step of palette rendering, after everything else has been drawn. + if (HWR_ShouldUsePaletteRendering()) + { + // not using the function for its original named purpose but can be used like this too + HWR_MakeScreenFinalTexture(); + HWD.pfnSetSpecialState(HWD_SET_SHADERS, 1); + HWD.pfnSetShader(8); + HWR_DrawScreenFinalTexture(vid.width, vid.height); + HWD.pfnUnSetShader(); + HWD.pfnSetSpecialState(HWD_SET_SHADERS, 0); + }*/ //for some reason this does not work here,so ill keep it in DrawScreenFinalTexture itself for now + OglSdlFinishUpdate(cv_vidwait.value); } #endif From 2c69f67d3907105728b235ffdcc0275c64cf05ab Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 12:53:38 +0100 Subject: [PATCH 10/50] Decrease the amount of texture clearing when switching palette rendering state --- src/hardware/hw_main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b133c1bc5..befe25b26 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6334,10 +6334,11 @@ void HWR_TogglePaletteRendering(void) HWR_SetMapPalette(); HWR_SetPalette(pLocalPalette); - // If the r_opengl "texture palette" stays the same during this switch, the textures + // If the r_opengl "texture palette" stays the same during this switch, these textures // will not be cleared out. However they are still out of date since the // composite texture blending method has changed. Therefore they need to be cleared. - HWD.pfnClearMipMapCache(); + //HWD.pfnClearMipMapCache(); + HWR_PrepLevelCache(numtextures); } } else @@ -6348,15 +6349,15 @@ void HWR_TogglePaletteRendering(void) gr_palette_rendering_state = false; textureformat = GR_RGBA; HWR_SetPalette(pLocalPalette); - // If the r_opengl "texture palette" stays the same during this switch, the textures + // If the r_opengl "texture palette" stays the same during this switch, these textures // will not be cleared out. However they are still out of date since the // composite texture blending method has changed. Therefore they need to be cleared. - HWD.pfnClearMipMapCache(); + //HWD.pfnClearMipMapCache(); + HWR_PrepLevelCache(numtextures); } } } - //added by Hurdler: console varibale that are saved void HWR_AddCommands(void) { From fba1c118612fe6ee93c593b88fe4c0c4aa060a96 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 13:26:29 +0100 Subject: [PATCH 11/50] fix 2d draw brightness issue + fix some other things --- src/hardware/hw_cache.c | 13 +++++++++---- src/hardware/hw_draw.c | 29 +++++++++++++++++------------ src/hardware/hw_main.c | 19 +++++++++++++------ src/hardware/hw_main.h | 5 ++++- 4 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index a13d5c658..39fd7a9fb 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -36,7 +36,7 @@ INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole RGBA_t mapPalette[256] = {0}; // the palette for the currently loaded level or menu etc. // Returns a pointer to the palette which should be used for caching textures. -static RGBA_t *HWR_GetTexturePalette(void) +RGBA_t *HWR_GetTexturePalette(void) { return HWR_ShouldUsePaletteRendering() ? mapPalette : pLocalPalette; } @@ -926,6 +926,7 @@ void HWR_SetPalette(RGBA_t *palette) { // set the palette for palette postprocessing + if (cv_grpalettedepth.value == 16) { // crush to 16-bit rgb565, like software currently does in the standard configuration // Note: Software's screenshots have the 24-bit palette, but the screen gets @@ -945,9 +946,13 @@ void HWR_SetPalette(RGBA_t *palette) } HWD.pfnSetScreenPalette(crushed_palette); } + else + { + HWD.pfnSetScreenPalette(palette); + } // this part is responsible for keeping track of the palette OUTSIDE of a level. - if (!(gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN))) + if ((!(gamestate == GS_LEVEL)) || (gamestate == GS_TITLESCREEN)) HWR_SetMapPalette(); } else @@ -999,11 +1004,11 @@ void HWR_SetMapPalette(void) RGBA_t *palette; int i; - if (!(gamestate == GS_LEVEL || (gamestate == GS_TITLESCREEN))) //we dont have a master palette + if ((!(gamestate == GS_LEVEL)) || (gamestate == GS_TITLESCREEN)) //we dont have a master palette { // outside of a level, pMasterPalette should have PLAYPAL ready for us //palette = pMasterPalette; // we dont have this in kart so just use plocalpalette as before - + palette = pLocalPalette; } else diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 99c90243e..5c43b0206 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -567,12 +567,13 @@ void HWR_FadeScreenMenuBack(UINT16 color, UINT8 strength) } else // Do TRANSMAP** fade. { - if (HWR_ShouldUsePaletteRendering()) - Surf.PolyColor.rgba = pLocalPalette[color&0xFF].rgba; - else - Surf.PolyColor.rgba = pLocalPalette[color].rgba; + RGBA_t *palette = HWR_GetTexturePalette(); + Surf.PolyColor.rgba = palette[color&0xFF].rgba; - Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f); + if (HWR_ShouldUsePaletteRendering()) + Surf.PolyColor.s.alpha = softwaretranstogl[strength]; + else + Surf.PolyColor.s.alpha = (UINT8)(strength*25.5f); } HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); @@ -748,9 +749,10 @@ void HWR_drawAMline(const fline_t *fl, INT32 color) { F2DCoord v1, v2; RGBA_t color_rgba; - - color_rgba = V_GetColor(color); - + RGBA_t *palette = HWR_GetTexturePalette(); + + color_rgba = palette[color&0xFF]; + v1.x = ((float)fl->a.x-(vid.width/2.0f))*(2.0f/vid.width); v1.y = ((float)fl->a.y-(vid.height/2.0f))*(2.0f/vid.height); @@ -768,6 +770,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) FOutVector v[4]; FSurfaceInfo Surf; float fx, fy, fw, fh, fwait = 0; + RGBA_t *palette = HWR_GetTexturePalette(); if (wh < 0) return; // consistency w/ software @@ -848,7 +851,7 @@ void HWR_DrawDiag(INT32 x, INT32 y, INT32 wh, INT32 color) v[0].t = v[1].t = 0.0f; v[2].t = v[3].t = 1.0f; - Surf.PolyColor = V_GetColor(color); + Surf.PolyColor = palette[color&0xFF]; HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest, false); @@ -862,6 +865,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 FOutVector v[4]; FSurfaceInfo Surf; float fx, fy, fw, fh; + RGBA_t *palette = HWR_GetTexturePalette(); if (w < 0 || h < 0) return; // consistency w/ software @@ -882,7 +886,7 @@ void HWR_DrawConsoleFill(INT32 x, INT32 y, INT32 w, INT32 h, UINT32 color, INT32 if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { - RGBA_t rgbaColour = V_GetColor(color); + RGBA_t rgbaColour = palette[color&0xFF]; FRGBAFloat clearColour; clearColour.red = (float)rgbaColour.s.red / 255; clearColour.green = (float)rgbaColour.s.green / 255; @@ -972,6 +976,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) FSurfaceInfo Surf; float fx, fy, fw, fh; UINT8 alphalevel = ((color & V_ALPHAMASK) >> V_ALPHASHIFT); + RGBA_t *palette = HWR_GetTexturePalette(); if (w < 0 || h < 0) return; // consistency w/ software @@ -992,7 +997,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { - RGBA_t rgbaColour = V_GetColor(color); + RGBA_t rgbaColour = palette[color&0xFF]; FRGBAFloat clearColour; clearColour.red = (float)rgbaColour.s.red / 255; clearColour.green = (float)rgbaColour.s.green / 255; @@ -1066,7 +1071,7 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) v[0].t = v[1].t = 0.0f; v[2].t = v[3].t = 1.0f; - Surf.PolyColor = V_GetColor(color); + Surf.PolyColor = palette[color&0xFF]; if (alphalevel) { diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index befe25b26..e6e4688cc 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -73,6 +73,7 @@ static void CV_screentextures_ONChange(void); static void CV_useCustomShaders_ONChange(void); static void CV_grshaders_OnChange(void); static void CV_grpaletterendering_OnChange(void); +static void CV_grpalettedepth_OnChange(void); static CV_PossibleValue_t grfakecontrast_cons_t[] = {{0, "Off"}, {1, "Standard"}, {2, "Smooth"}, {0, NULL}}; @@ -147,6 +148,9 @@ consvar_t cv_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE consvar_t cv_grpaletterendering = {"gr_paletteshader", "Off", CV_CALL|CV_SAVE, CV_OnOff, CV_grpaletterendering_OnChange, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t glpalettedepth_cons_t[] = {{16, "16 bits"}, {24, "24 bits"}, {0, NULL}}; +consvar_t cv_grpalettedepth = {"gr_palettedepth", "16 bits", CV_SAVE|CV_CALL, glpalettedepth_cons_t, CV_grpalettedepth_OnChange, 0, NULL, NULL, 0, 0, NULL}; + consvar_t cv_grflashpal = {"gr_flashpal", "On", CV_CALL|CV_SAVE, CV_OnOff, CV_grshaders_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_grmdls = {"gr_mdls", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -178,10 +182,7 @@ static void CV_screentextures_ONChange(void) static void CV_grshaders_OnChange(void) { - if (rendermode == render_opengl) - V_SetPalette(0); - - if (cv_grpaletterendering.value) + if ((rendermode == render_opengl) && (cv_grpaletterendering.value)) { // can't do palette rendering without shaders, so update the state if needed HWR_TogglePaletteRendering(); @@ -197,15 +198,20 @@ static void CV_useCustomShaders_ONChange(void) } } - static void CV_grpaletterendering_OnChange(void) { - if (gr_shadersavailable) + if ((rendermode == render_opengl) && (gr_shadersavailable)) { HWR_TogglePaletteRendering(); } } +static void CV_grpalettedepth_OnChange(void) +{ + if (HWR_ShouldUsePaletteRendering()) + HWR_SetPalette(pLocalPalette); +} + // ========================================================================== // Globals // ========================================================================== @@ -6400,6 +6406,7 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_secbright); CV_RegisterVar(&cv_grpaletterendering); + CV_RegisterVar(&cv_grpalettedepth); CV_RegisterVar(&cv_grflashpal); CV_RegisterVar(&cv_grvhseffect); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 2e88f9336..2939a4e59 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -92,6 +92,7 @@ void HWR_ClearClipper(void); boolean HWR_UseShader(void); boolean HWR_ShouldUsePaletteRendering(void); boolean HWR_PalRenderFlashpal(void); +void HWR_TogglePaletteRendering(void); // My original intention was to split hw_main.c // into files like hw_bsp.c, hw_sprites.c... @@ -162,6 +163,7 @@ extern boolean gr_maphasportals; // hw_cache.c void HWR_PrepLevelCache(size_t pnumtextures); +RGBA_t *HWR_GetTexturePalette(void); // hw_trick.c void HWR_CorrectSWTricks(void); @@ -190,8 +192,9 @@ extern consvar_t cv_grbatching; extern consvar_t cv_grrenderdistance; extern consvar_t cv_grusecustomshaders; extern consvar_t cv_grpaletterendering; -extern consvar_t cv_grscreentextures; +extern consvar_t cv_grpalettedepth; extern consvar_t cv_grflashpal; +extern consvar_t cv_grscreentextures; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright; From 558963c57c8b25766c055b075bb82a4f24e9cebe Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 13:27:25 +0100 Subject: [PATCH 12/50] Use GL_LUMINANCE8 for 3d palette lookup texture on OpenGL versions older than 3.0 --- src/hardware/r_opengl/r_opengl.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index f9d0e44e9..83f5c3b31 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -4355,13 +4355,27 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) EXPORT void HWRAPI(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. + // so use GL_LUMINANCE8 instead to get a single component 8-bit format + // (it is possible to have access to shaders even in some OpenGL 1.x systems, + // so palette rendering can still possibly be achieved there) + internalFormat = GL_LUMINANCE8; + } + else + { + internalFormat = GL_R8; + } + if (!paletteLookupTex) pglGenTextures(1, &paletteLookupTex); pglActiveTexture(GL_TEXTURE1); pglBindTexture(GL_TEXTURE_3D, paletteLookupTex); pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - pglTexImage3D(GL_TEXTURE_3D, 0, GL_R8, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, + pglTexImage3D(GL_TEXTURE_3D, 0, internalFormat, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, 0, GL_RED, GL_UNSIGNED_BYTE, lut); pglActiveTexture(GL_TEXTURE0); } From 1be27dc8683845fd5f597dab698244d36983ac7a Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 13:38:30 +0100 Subject: [PATCH 13/50] more smol changes --- src/hardware/hw_cache.c | 27 +++++++++++++++++++++++++++ src/hardware/hw_glob.h | 1 + src/hardware/hw_main.c | 25 +------------------------ src/hardware/r_opengl/r_opengl.c | 14 +++++++------- 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 39fd7a9fb..2aeb497bb 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1067,6 +1067,33 @@ UINT32 HWR_CreateLightTable(UINT8 *lighttable) return id; } + +// get hwr lighttable id for colormap, create it if it doesn't already exist +UINT32 HWR_GetLightTableID(extracolormap_t *colormap) +{ + boolean default_colormap = false; + if (!colormap) + { + colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id + // alternatively could just store the id in a global variable if there are issues + default_colormap = true; + } + + // create hw lighttable if there isn't one + if (!colormap->gl_lighttable_id) + { + UINT8 *colormap_pointer; + + if (default_colormap) + colormap_pointer = colormaps; // don't actually use the data from the "default colormap" + else + colormap_pointer = colormap->colormap; + colormap->gl_lighttable_id = HWR_CreateLightTable(colormap_pointer); + } + + return colormap->gl_lighttable_id; +} + // Note: all hardware lighttable ids assigned before this // call become invalid and must not be used. void HWR_ClearLightTables(void) diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 3423bd09c..082a6a78c 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -71,6 +71,7 @@ void HWR_SetPalette(RGBA_t *palette); void HWR_SetMapPalette(void); UINT32 HWR_CreateLightTable(UINT8 *lighttable); +UINT32 HWR_GetLightTableID(extracolormap_t *colormap); void HWR_ClearLightTables(void); GLPatch_t *HWR_GetCachedGLPatchPwad(UINT16 wad, UINT16 lump); GLPatch_t *HWR_GetCachedGLPatch(lumpnum_t lumpnum); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index e6e4688cc..820da8673 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -451,7 +451,6 @@ boolean HWR_PalRenderFlashpal(void) void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *colormap) { RGBA_t poly_color, tint_color, fade_color; - boolean default_colormap = false; poly_color.rgba = 0xFFFFFFFF; tint_color.rgba = (colormap != NULL) ? (UINT32)colormap->rgba : GL_DEFAULTMIX; @@ -505,31 +504,9 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col Surface->LightInfo.fade_end = (colormap != NULL) ? colormap->fadeend : 31; if (HWR_ShouldUsePaletteRendering()) - { - boolean default_colormap = false; - if (!colormap) - { - colormap = &extra_colormaps[num_extra_colormaps]; // a place to store the hw lighttable id - // alternatively could just store the id in a global variable if there are issues - default_colormap = true; - } - // create hw lighttable if there isn't one - if (!colormap->gl_lighttable_id) - { - UINT8 *colormap_pointer; - - if (default_colormap) - colormap_pointer = colormaps; // don't actually use the data from the "default colormap" - else - colormap_pointer = colormap->colormap; - colormap->gl_lighttable_id = HWR_CreateLightTable(colormap_pointer); - } - Surface->LightTableId = colormap->gl_lighttable_id; - } + Surface->LightTableId = HWR_GetLightTableID(colormap); else - { Surface->LightTableId = 0; - } } UINT8 HWR_FogBlockAlpha(INT32 light, extracolormap_t *colormap) // Let's see if this can work diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 83f5c3b31..899b122c5 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -671,9 +671,9 @@ typedef enum gluniform_fade_end, // palette rendering - gluniform_screen_palette_tex, - gluniform_palette_lookup_tex, - gluniform_lighttable_tex, + gluniform_palette_tex, // 1d texture containing a palette + gluniform_palette_lookup_tex, // 3d texture containing the rgb->index lookup table + gluniform_lighttable_tex, // 2d texture containing a light table // misc. gluniform_leveltime, @@ -922,12 +922,12 @@ static float shader_leveltime = 0; #define GLSL_PALETTE_FRAGMENT_SHADER \ "uniform sampler2D tex;\n" \ "uniform sampler3D palette_lookup_tex;\n" \ - "uniform sampler1D screen_palette_tex;\n" \ + "uniform sampler1D palette_tex;\n" \ "void main(void) {\n" \ "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ "float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \ "float palette_coord = (tex_pal_idx + 0.5) / 256.0;\n" \ - "vec4 final_color = texture1D(screen_palette_tex, palette_coord);\n" \ + "vec4 final_color = texture1D(palette_tex, palette_coord);\n" \ "gl_FragColor = final_color;\n" \ "}\0" @@ -1209,7 +1209,7 @@ EXPORT boolean HWRAPI(LoadShaders) (void) shader->uniforms[gluniform_fade_end] = GETUNI("fade_end"); // palette rendering - shader->uniforms[gluniform_screen_palette_tex] = GETUNI("screen_palette_tex"); + shader->uniforms[gluniform_palette_tex] = GETUNI("palette_tex"); shader->uniforms[gluniform_palette_lookup_tex] = GETUNI("palette_lookup_tex"); shader->uniforms[gluniform_lighttable_tex] = GETUNI("lighttable_tex"); @@ -1225,7 +1225,7 @@ EXPORT boolean HWRAPI(LoadShaders) (void) pglUseProgram(shader->program); // texture unit numbers for the samplers used for palette rendering - UNIFORM_1(shader->uniforms[gluniform_screen_palette_tex], 2, pglUniform1i); + UNIFORM_1(shader->uniforms[gluniform_palette_tex], 2, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_palette_lookup_tex], 1, pglUniform1i); UNIFORM_1(shader->uniforms[gluniform_lighttable_tex], 2, pglUniform1i); From 61897cdc4ac7e76e2930a544475c75f312b6b773 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 13:40:14 +0100 Subject: [PATCH 14/50] bleh --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 820da8673..3024e677f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -208,7 +208,7 @@ static void CV_grpaletterendering_OnChange(void) static void CV_grpalettedepth_OnChange(void) { - if (HWR_ShouldUsePaletteRendering()) + if ((rendermode == render_opengl) && (HWR_ShouldUsePaletteRendering())) HWR_SetPalette(pLocalPalette); } From fc34fd708c1e7b237acf6e029f212a51eb7398d3 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 14:14:46 +0100 Subject: [PATCH 15/50] fix lighttable batching issues ugh --- src/hardware/r_opengl/r_opengl.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 899b122c5..98dded171 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -82,9 +82,9 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; static GLuint tex_downloaded = 0; -static GLuint lt_downloaded = 0; // currently bound lighttable texture - currentSurfaceInfo -static GLuint lt_downloaded2 = 0; // currently bound lighttable texture - nextSurfaceInfo -static GLuint lt_downloaded3 = 0; // currently bound lighttable texture - pSurf +//static GLuint lt_downloaded = 0; // currently bound lighttable texture - currentSurfaceInfo +//static GLuint lt_downloaded2 = 0; // currently bound lighttable texture - nextSurfaceInfo +//static GLuint lt_downloaded3 = 0; // currently bound lighttable texture - pSurf static GLfloat fov = 90.0f; static FBITFIELD CurrentPolyFlags; @@ -2402,12 +2402,13 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i { Shader_Load(¤tSurfaceInfo, &firstPoly, &firstTint, &firstFade); - if (currentSurfaceInfo.LightTableId && currentSurfaceInfo.LightTableId != lt_downloaded) + //if (currentSurfaceInfo.LightTableId && currentSurfaceInfo.LightTableId != lt_downloaded) + if (HWR_ShouldUsePaletteRendering()) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, currentSurfaceInfo.LightTableId); pglActiveTexture(GL_TEXTURE0); - lt_downloaded = currentSurfaceInfo.LightTableId; + //lt_downloaded = currentSurfaceInfo.LightTableId; } } @@ -2666,12 +2667,13 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i Shader_Load(&nextSurfaceInfo, &poly, &tint, &fade); - if (nextSurfaceInfo.LightTableId && nextSurfaceInfo.LightTableId != lt_downloaded2) + //if (nextSurfaceInfo.LightTableId && nextSurfaceInfo.LightTableId != lt_downloaded2) + if (HWR_ShouldUsePaletteRendering()) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, nextSurfaceInfo.LightTableId); pglActiveTexture(GL_TEXTURE0); - lt_downloaded2 = nextSurfaceInfo.LightTableId; + //lt_downloaded2 = nextSurfaceInfo.LightTableId; } } @@ -2777,12 +2779,13 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI fade.blue = byte2float[pSurf->FadeColor.s.blue]; fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; - if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded3) + //if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded3) + if (HWR_ShouldUsePaletteRendering()) { pglActiveTexture(GL_TEXTURE2); pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); pglActiveTexture(GL_TEXTURE0); - lt_downloaded3 = pSurf->LightTableId; + //lt_downloaded3 = pSurf->LightTableId; } } } @@ -4419,9 +4422,9 @@ EXPORT void HWRAPI(ClearLightTables)(void) LightTablesTail = NULL; // we no longer have a bound light table (if we had one), we just deleted it! - lt_downloaded = 0; - lt_downloaded2 = 0; - lt_downloaded3 = 0; + //lt_downloaded = 0; + //lt_downloaded2 = 0; + //lt_downloaded3 = 0; } // This palette is used for the palette rendering postprocessing step. From f7b8c5b3ac7ccb4f279666ca7b3126127d38e867 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 10 Jan 2024 14:16:09 +0100 Subject: [PATCH 16/50] move this --- src/p_setup.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 3fb2fae12..20ad65644 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3148,10 +3148,11 @@ boolean P_SetupLevel(boolean skipprecip) // Correct missing sidedefs & deep water trick HWR_CorrectSWTricks(); HWR_CreatePlanePolygons((INT32)numnodes - 1); + + if (HWR_ShouldUsePaletteRendering()) + HWR_SetMapPalette(); } - - if (HWR_ShouldUsePaletteRendering()) - HWR_SetMapPalette(); + #endif // oh god I hope this helps From f5b4d7c314a9deb70c60e4f6e5675e0683c9ba4e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 00:39:20 +0100 Subject: [PATCH 17/50] small cleanup --- src/hardware/r_opengl/r_opengl.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 98dded171..410c08775 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -27,9 +27,6 @@ #include "r_opengl.h" #include "r_vbo.h" -#include "../../v_video.h" // pLocalPalette -#include "../../r_data.h" // NearestColor - //#include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) #include "../../i_system.h" // for I_GetPreciseTime (batching time measurements) @@ -80,7 +77,6 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; // GLOBALS // ************************************************************************** - static GLuint tex_downloaded = 0; //static GLuint lt_downloaded = 0; // currently bound lighttable texture - currentSurfaceInfo //static GLuint lt_downloaded2 = 0; // currently bound lighttable texture - nextSurfaceInfo @@ -206,7 +202,6 @@ FUNCPRINTF void GL_DBG_Printf(const char *format, ...) #endif } - // -----------------+ // GL_MSG_Warning : Raises a warning. // : @@ -258,7 +253,6 @@ static void GL_MSG_Error(const char *format, ...) #endif } - #ifdef STATIC_OPENGL /* 1.0 functions */ /* Miscellaneous */ @@ -607,7 +601,6 @@ typedef void (APIENTRY *PFNglLinkProgram) (GLuint); typedef void (APIENTRY *PFNglGetProgramiv) (GLuint, GLenum, GLint*); typedef void (APIENTRY *PFNglUseProgram) (GLuint); typedef void (APIENTRY *PFNglUniform1i) (GLint, GLint); -typedef void (APIENTRY *PFNglUniform1iv) (GLint, GLsizei, const GLint*); typedef void (APIENTRY *PFNglUniform1f) (GLint, GLfloat); typedef void (APIENTRY *PFNglUniform2f) (GLint, GLfloat, GLfloat); typedef void (APIENTRY *PFNglUniform3f) (GLint, GLfloat, GLfloat, GLfloat); @@ -629,7 +622,6 @@ static PFNglLinkProgram pglLinkProgram; static PFNglGetProgramiv pglGetProgramiv; static PFNglUseProgram pglUseProgram; static PFNglUniform1i pglUniform1i; -static PFNglUniform1iv pglUniform1iv; static PFNglUniform1f pglUniform1f; static PFNglUniform2f pglUniform2f; static PFNglUniform3f pglUniform3f; @@ -1026,8 +1018,14 @@ static const char *vertex_shaders[] = { // Palette vertex shader GLSL_DEFAULT_VERTEX_SHADER, + + // Palette floor vertex shader GLSL_DEFAULT_VERTEX_SHADER, + + // Palette wall vertex shader GLSL_DEFAULT_VERTEX_SHADER, + + // Palette water vertex shader GLSL_DEFAULT_VERTEX_SHADER, NULL, @@ -1066,7 +1064,6 @@ void SetupGLFunc4(void) pglGetProgramiv = GetGLFunc("glGetProgramiv"); pglUseProgram = GetGLFunc("glUseProgram"); pglUniform1i = GetGLFunc("glUniform1i"); - pglUniform1iv = GetGLFunc("glUniform1iv"); pglUniform1f = GetGLFunc("glUniform1f"); pglUniform2f = GetGLFunc("glUniform2f"); pglUniform3f = GetGLFunc("glUniform3f"); From ad87f7f895e2cc8167e0baf2cea6b4a53870c767 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 00:51:19 +0100 Subject: [PATCH 18/50] dont initialize this to 1 oopsie --- src/sdl/ogl_sdl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/ogl_sdl.c b/src/sdl/ogl_sdl.c index 9cc2d1a94..dc831fce0 100644 --- a/src/sdl/ogl_sdl.c +++ b/src/sdl/ogl_sdl.c @@ -238,7 +238,7 @@ void OglSdlFinishUpdate(boolean waitvbl) EXPORT void HWRAPI(OglSdlSetPalette) (RGBA_t *palette) { - INT32 i = 1; + INT32 i; for (i = 0; i < 256; i++) { From cdef315866def995d1bb1279f2c6a3328f26a68f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 01:09:51 +0100 Subject: [PATCH 19/50] fix software more crash --- src/hardware/hw_cache.c | 1 + src/r_data.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 2aeb497bb..18a2d20fe 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1099,6 +1099,7 @@ UINT32 HWR_GetLightTableID(extracolormap_t *colormap) void HWR_ClearLightTables(void) { //if (vid.glstate == VID_GL_LIBRARY_LOADED) + if (rendermode == render_opengl) HWD.pfnClearLightTables(); } diff --git a/src/r_data.c b/src/r_data.c index 23629af03..7c6697298 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -28,7 +28,6 @@ #ifdef HWRENDER #include "hardware/hw_main.h" - #include "hardware/hw_glob.h" // HWR_ClearLightTables #endif @@ -1141,7 +1140,8 @@ void R_ClearColormaps(void) memset(extra_colormaps, 0, sizeof (extra_colormaps)); #ifdef HWRENDER - HWR_ClearLightTables(); + if (rendermode == render_opengl) + HWR_ClearLightTables(); #endif } From b082f71ca7d5673c7d22edde1ff68a18b6f037a0 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 08:42:56 +0100 Subject: [PATCH 20/50] change this back --- src/st_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 37b75d586..b4b4a3d49 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -2207,7 +2207,7 @@ void ST_Drawer(void) //25/08/99: Hurdler: palette changes is done for all players, // not only player1! That's why this part // of code is moved somewhere else. - if (rendermode == render_soft || HWR_PalRenderFlashpal()) + if (rendermode == render_soft || (rendermode == render_opengl && HWR_PalRenderFlashpal())) #endif if (rendermode != render_none) ST_doPaletteStuff(); From d2a361c250357b7c011fb17de8ca85ab5b232ca8 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 09:06:23 +0100 Subject: [PATCH 21/50] remove unecessary glActiveTexture calls --- src/hardware/r_opengl/r_opengl.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 410c08775..a15243852 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -4329,10 +4329,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); if (HWR_ShouldUsePaletteRendering()) - { pglUseProgram(gl_shaderprograms[8].program); // palette postprocess shader - pglActiveTexture(GL_TEXTURE2); - } // prepare shader, if it is enabled //Shader_SetUniforms(NULL, NULL, NULL, NULL); @@ -4346,10 +4343,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) tex_downloaded = finalScreenTexture; if (HWR_ShouldUsePaletteRendering()) - { pglUseProgram(0); - pglActiveTexture(GL_TEXTURE0); - } } From a1f7914c5e7ca631cbc507e0a61bf97a8b78e4e1 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 09:51:58 +0100 Subject: [PATCH 22/50] more cleanup --- src/hardware/r_opengl/r_opengl.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index a15243852..b98db642f 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -4321,18 +4321,12 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) clearColour.alpha = 1; ClearBuffer(true, false, false, &clearColour); if (HWR_ShouldUsePaletteRendering()) - { SetBlend(PF_NoDepthTest); - pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - } - else - pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); + + pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); if (HWR_ShouldUsePaletteRendering()) pglUseProgram(gl_shaderprograms[8].program); // palette postprocess shader - - // prepare shader, if it is enabled - //Shader_SetUniforms(NULL, NULL, NULL, NULL); pglColor4ubv(white); pglTexCoordPointer(2, GL_FLOAT, 0, fix); From e03a17869e186c72d5a387e23e18765d49c0e240 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 12:27:10 +0100 Subject: [PATCH 23/50] add some comments --- src/hardware/hw_main.c | 2 +- src/hardware/r_opengl/r_opengl.c | 13 ++++++++----- src/p_setup.c | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3024e677f..47caacd8e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -189,7 +189,7 @@ static void CV_grshaders_OnChange(void) } } -static void CV_useCustomShaders_ONChange(void) +static void CV_useCustomShaders_ONChange(void) // should we do a call to HWR_TogglePaletteRendering here aswell in pal rendering mode? { if (rendermode == render_opengl) { diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index b98db642f..a0e94aed1 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -78,6 +78,7 @@ static float NEAR_CLIPPING_PLANE = NZCLIP_PLANE; // ************************************************************************** static GLuint tex_downloaded = 0; +// these didnt work with karts batching system, hope this is not an issue //static GLuint lt_downloaded = 0; // currently bound lighttable texture - currentSurfaceInfo //static GLuint lt_downloaded2 = 0; // currently bound lighttable texture - nextSurfaceInfo //static GLuint lt_downloaded3 = 0; // currently bound lighttable texture - pSurf @@ -762,6 +763,7 @@ static float shader_leveltime = 0; "}\n" // hand tuned adjustments for light level calculation +// do those even work correctly without the preprocessor? #define GLSL_FLOOR_FUDGES \ "#define STARTMAP_FUDGE 1.06\n" \ "#define SCALE_FUDGE 1.15\n" @@ -855,7 +857,8 @@ static float shader_leveltime = 0; "final_color.a = texel.a * poly_color.a;\n" \ "gl_FragColor = final_color;\n" \ "}\0" - + +//TODO: make this not a hacky copy of two shaders mixed together #define GLSL_PALETTE_WATER_FRAGMENT_SHADER \ GLSL_FLOOR_FUDGES \ "const float freq = 0.025;\n" \ @@ -1229,7 +1232,7 @@ EXPORT boolean HWRAPI(LoadShaders) (void) // restore gl shader state //pglUseProgram(gl_shaderstate.program); pglUseProgram(gl_currentshaderprogram); - //pglUseProgram(0); + //pglUseProgram(0); // dont remember why this was here in the first place, but seems fine? #undef UNIFORM_1 } #endif @@ -4305,7 +4308,6 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) off[10] = -yoff; off[11] = 1.0f; - fix[0] = 0.0f; fix[1] = 0.0f; fix[2] = 0.0f; @@ -4320,12 +4322,13 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int width, int height) clearColour.red = clearColour.green = clearColour.blue = 0; clearColour.alpha = 1; ClearBuffer(true, false, false, &clearColour); + if (HWR_ShouldUsePaletteRendering()) SetBlend(PF_NoDepthTest); pglBindTexture(GL_TEXTURE_2D, finalScreenTexture); - if (HWR_ShouldUsePaletteRendering()) + if (HWR_ShouldUsePaletteRendering()) // still quite hacky, but the replacement code in i_video didnt work and killed performance instead. somehow need to figure out whats up with that. pglUseProgram(gl_shaderprograms[8].program); // palette postprocess shader pglColor4ubv(white); @@ -4364,7 +4367,7 @@ EXPORT void HWRAPI(SetPaletteLookup)(UINT8 *lut) pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); pglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); pglTexImage3D(GL_TEXTURE_3D, 0, internalFormat, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, HWR_PALETTE_LUT_SIZE, - 0, GL_RED, GL_UNSIGNED_BYTE, lut); + 0, GL_RED, GL_UNSIGNED_BYTE, lut); // should there be a safety guard here aswell as the old one had? cant really test since i dont have hardware which doesent support 3D textures pglActiveTexture(GL_TEXTURE0); } diff --git a/src/p_setup.c b/src/p_setup.c index 20ad65644..7b4a3db2b 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3149,7 +3149,7 @@ boolean P_SetupLevel(boolean skipprecip) HWR_CorrectSWTricks(); HWR_CreatePlanePolygons((INT32)numnodes - 1); - if (HWR_ShouldUsePaletteRendering()) + if (HWR_ShouldUsePaletteRendering()) //unsure if this is the right place, but seems to work since we dont have HWR_LoadLevel like srb2 HWR_SetMapPalette(); } From 5e3b6a753ea909bda3a3d3941b08e6d3524fa880 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 12:30:29 +0100 Subject: [PATCH 24/50] update some comments --- src/hardware/hw_cache.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 18a2d20fe..642e28354 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -925,7 +925,6 @@ void HWR_SetPalette(RGBA_t *palette) if (HWR_ShouldUsePaletteRendering()) { // set the palette for palette postprocessing - if (cv_grpalettedepth.value == 16) { // crush to 16-bit rgb565, like software currently does in the standard configuration @@ -963,6 +962,7 @@ void HWR_SetPalette(RGBA_t *palette) memset(mapPalette, 0, sizeof(mapPalette)); // hardware driver will flush there own cache if cache is non paletized // now flush data texture cache so 32 bit texture are recomputed + //if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA) if (patchformat == GR_RGBA || textureformat == GR_RGBA) { @@ -1004,16 +1004,16 @@ void HWR_SetMapPalette(void) RGBA_t *palette; int i; - if ((!(gamestate == GS_LEVEL)) || (gamestate == GS_TITLESCREEN)) //we dont have a master palette + if ((!(gamestate == GS_LEVEL)) || (gamestate == GS_TITLESCREEN)) { // outside of a level, pMasterPalette should have PLAYPAL ready for us - //palette = pMasterPalette; // we dont have this in kart so just use plocalpalette as before + //palette = pMasterPalette; // we dont have this in kart so just use pLocalPalette as before palette = pLocalPalette; } else { - // in a level pMasterPalette might have a flash palette, but we + // in a level pLocalPalette might have a flash palette, but we // want the map's original palette. lumpnum_t lumpnum = W_GetNumForName(GetPalette()); size_t palsize = W_LumpLength(lumpnum); @@ -1040,6 +1040,7 @@ void HWR_SetMapPalette(void) // and the lookup table is outdated HWR_SetPaletteLookup(mapPalette); HWD.pfnSetTexturePalette(mapPalette); + //if (patchformat == GL_TEXFMT_RGBA || textureformat == GL_TEXFMT_RGBA) if (patchformat == GR_RGBA || textureformat == GR_RGBA) { @@ -1098,7 +1099,7 @@ UINT32 HWR_GetLightTableID(extracolormap_t *colormap) // call become invalid and must not be used. void HWR_ClearLightTables(void) { - //if (vid.glstate == VID_GL_LIBRARY_LOADED) + //if (vid.glstate == VID_GL_LIBRARY_LOADED) // we have pfnInit which is essentially the same, but it doesent work here for whatever reason, since this should not be done in software renderer ever! if (rendermode == render_opengl) HWD.pfnClearLightTables(); } From b7ffaf424384e4ea882b132964b07fd6e486d332 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Jan 2024 20:13:13 +0300 Subject: [PATCH 25/50] Warn about possible crash for vanilla when failing to spawn mapthing --- src/p_mobj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 541529c9e..b577ac32d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11507,7 +11507,7 @@ void P_SpawnMapThing(mapthing_t *mthing) mobj = P_SpawnMobj(x, y, z, i); if (!mobj || P_MobjWasRemoved(mobj)) { - CONS_Alert(CONS_WARNING, "Failed to spawn map thing #%d at %d, %d\n", mthing->type, x>>FRACBITS, y>>FRACBITS); + CONS_Alert(CONS_ERROR, "Failed to spawn map thing #%d at %d, %d. This will crash vanilla clients!\n", mthing->type, x>>FRACBITS, y>>FRACBITS); return; } From 0a6a40741b35b7ab00a733f8bdb2f65be7ad049c Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 12 Jan 2024 14:55:40 +0300 Subject: [PATCH 26/50] Don't reload addfilelocal'd files if md5 matches --- src/w_wad.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 6739d7824..4989f497b 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -769,13 +769,10 @@ UINT16 W_InitFile(const char *filename, const char *lumpname, UINT16 *wadnump, b { if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) { - if (!local) { - CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); - if (handle) - fclose(handle); - return INT16_MAX; - } - CONS_Alert(CONS_WARNING, M_GetText("%s is a local skin that is already loaded\n"), filename); + CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); + if (handle) + fclose(handle); + return INT16_MAX; } } #endif From 252062608243938d17239f63d92fdf0fe18aac25 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 13 Jan 2024 13:12:55 +0100 Subject: [PATCH 27/50] more cleanup of things i missed --- src/hardware/hw_defs.h | 1 - src/hardware/hw_main.h | 3 --- src/hardware/r_opengl/r_opengl.h | 3 --- 3 files changed, 7 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 87e6b33cc..1313d80aa 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -240,7 +240,6 @@ typedef struct FSurfaceInfo FSurfaceInfo; enum hwdsetspecialstate { HWD_SET_SHADERS, - HWD_PAL_SHADER, HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 2939a4e59..a39224542 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -115,7 +115,6 @@ void HWR_DoWipe(UINT8 wipenum, UINT8 scrnnum); void HWR_RenderVhsEffect(fixed_t upbary, fixed_t downbary, UINT8 updistort, UINT8 downdistort, UINT8 barsize); void HWR_MakeScreenFinalTexture(void); void HWR_DrawScreenFinalTexture(int width, int height); -void HWR_InitPalette(int flashnum, boolean skiplut); // hw_main.c: Planes void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap); @@ -149,8 +148,6 @@ void HWR_AddLine(seg_t *line); boolean HWR_CheckBBox(fixed_t *bspcoord); void HWR_RenderDrawNodes(void); -void HWR_ClearLightTableCache(void); - // hw_main.c: Sprites void HWR_AddSprites(sector_t *sec); void HWR_ProjectSprite(mobj_t *thing); diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index a65c085a5..6d11bf4e3 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -133,7 +133,4 @@ typedef enum GLF_NOTEXENV = 0x02, } oglflags_t; -// in order for custom playpals n shit to work properly -extern boolean gl_palette_initialized; - #endif From e1f821e121c5032fbafee7d0eefc9f2cbd3efc20 Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Sun, 26 Nov 2023 10:16:16 +0800 Subject: [PATCH 28/50] Localskins on replays --- src/g_game.c | 29 +++++++++++++++++++++++++++-- src/g_game.h | 1 + src/r_things.c | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 38f063f62..dceaafa29 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3012,6 +3012,9 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost) } P_MovePlayerToSpawn(playernum, spawnpoint); + // TODO: This is so dumb. + demo_extradata[playernum] |= DXD_LOCALSKIN; + #ifdef HAVE_BLUA LUAh_PlayerSpawn(&players[playernum]); // Lua hook for player spawning :) #endif @@ -3347,7 +3350,7 @@ void G_AddPlayer(INT32 playernum) p->jointime = 0; p->playerstate = PST_REBORN; - demo_extradata[playernum] |= DXD_PLAYSTATE|DXD_COLOR|DXD_NAME|DXD_SKIN; // Set everything + demo_extradata[playernum] |= DXD_PLAYSTATE|DXD_COLOR|DXD_NAME|DXD_SKIN|DXD_LOCALSKIN; // Set everything } void G_ExitLevel(void) @@ -5346,7 +5349,14 @@ void G_ReadDemoExtraData(void) else if (G_RaceGametype()) P_CheckRacers(); // also SRB2Kart } - + if (extradata & DXD_LOCALSKIN) + { + // TODO: Does this work just fine? + M_Memcpy(name, demo_p, 16); + //CONS_Printf("Loaded localskin data from replay: %s\n", name); + demo_p += 16; + SetLocalPlayerSkin(p, name, NULL); + } p = READUINT8(demo_p); } @@ -5433,6 +5443,21 @@ void G_WriteDemoExtraData(void) else WRITEUINT8(demo_p, DXD_PST_PLAYING); } + if (demo_extradata[i] & DXD_LOCALSKIN) + { + // Skin + memset(name, 0, 16); + // check for different localskin conditions + if (players[i].skinlocal && players[i].localskin > 0) + strncpy(name, localskins[players[i].localskin - 1].name, 16); + else if (!players[i].skinlocal && players[i].localskin > 0) + strncpy(name, skins[players[i].localskin - 1].name, 16); + else + strncpy(name, "none", 16); + //CONS_Printf("Saved localskin data to replay: %s\n", name); + M_Memcpy(demo_p,name,16); + demo_p += 16; + } } demo_extradata[i] = 0; diff --git a/src/g_game.h b/src/g_game.h index b45e42875..372801f65 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -297,6 +297,7 @@ extern UINT8 demo_writerng; #define DXD_NAME 0x04 // name changed #define DXD_COLOR 0x08 // color changed #define DXD_PLAYSTATE 0x10 // state changed between playing, spectating, or not in-game +#define DXD_LOCALSKIN 0x20 // localskin changed #define DXD_PST_PLAYING 0x01 #define DXD_PST_SPECTATING 0x02 diff --git a/src/r_things.c b/src/r_things.c index 41bd5c6e1..498c46bf4 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3274,6 +3274,8 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) CV_StealthSet(cvar, "none"); } } + + demo_extradata[playernum] |= DXD_LOCALSKIN; } // Same as SetPlayerSkin, but uses the skin #. From 76a233148b508a48c93f88a7f27f7521a066f230 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 14 Jan 2024 18:03:20 +0300 Subject: [PATCH 29/50] Restore old speedometer offset cvar names Changed from "speed" to "spdm" in refactor accidently oops --- src/g_game.h | 2 +- src/k_kart.c | 8 ++++---- src/m_menu.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/g_game.h b/src/g_game.h index b45e42875..a57468a2e 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -141,7 +141,7 @@ DECL_HUD_OFFSET(item); // Item box DECL_HUD_OFFSET(time); // Time DECL_HUD_OFFSET(laps); // Number of laps DECL_HUD_OFFSET(dnft); // Countdown (did not finish timer) -DECL_HUD_OFFSET(spdm); // Speedometer +DECL_HUD_OFFSET(speed); // Speedometer DECL_HUD_OFFSET(posi); // Position in race DECL_HUD_OFFSET(face); // Mini rankings DECL_HUD_OFFSET(stcd); // Starting countdown diff --git a/src/k_kart.c b/src/k_kart.c index 46d891890..3170bc143 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -40,7 +40,7 @@ IMPL_HUD_OFFSET(item); // Item box IMPL_HUD_OFFSET(time); // Time IMPL_HUD_OFFSET(laps); // Number of laps IMPL_HUD_OFFSET(dnft); // Countdown (did not finish timer) -IMPL_HUD_OFFSET(spdm); // Speedometer +IMPL_HUD_OFFSET(speed); // Speedometer IMPL_HUD_OFFSET(posi); // Position in race IMPL_HUD_OFFSET(face); // Mini rankings IMPL_HUD_OFFSET(stcd); // Starting countdown @@ -685,7 +685,7 @@ void K_RegisterKartStuff(void) REG_HUD_OFFSET(time); // Time REG_HUD_OFFSET(laps); // Number of laps REG_HUD_OFFSET(dnft); // Countdown (did not finish timer) - REG_HUD_OFFSET(spdm); // Speedometer + REG_HUD_OFFSET(speed); // Speedometer REG_HUD_OFFSET(posi); // Position in race REG_HUD_OFFSET(face); // Mini rankings REG_HUD_OFFSET(stcd); // Starting countdown @@ -7451,8 +7451,8 @@ static void K_initKartHUD(void) LAPS_X = 9 + cv_laps_xoffset.value; // 9 LAPS_Y = BASEVIDHEIGHT - 29 + cv_laps_yoffset.value; // 171 // Speedometer - SPDM_X = 9 + cv_spdm_xoffset.value; // 9 - SPDM_Y = BASEVIDHEIGHT - 45 + cv_spdm_yoffset.value; // 155 + SPDM_X = 9 + cv_speed_xoffset.value; // 9 + SPDM_Y = BASEVIDHEIGHT - 45 + cv_speed_yoffset.value; // 155 // Position Number POSI_X = BASEVIDWIDTH - 9 + cv_posi_xoffset.value; // 268 POSI_Y = BASEVIDHEIGHT - 9 + cv_posi_yoffset.value; // 138 diff --git a/src/m_menu.c b/src/m_menu.c index c46cf9cca..d851801a4 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2120,8 +2120,8 @@ static menuitem_t OP_HudOffsetMenu[] = {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_laps_yoffset, 60}, {IT_HEADER, NULL, "Speedometer", NULL, 70}, - {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_spdm_xoffset, 75}, - {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_spdm_yoffset, 80}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_speed_xoffset, 75}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_speed_yoffset, 80}, {IT_HEADER, NULL, "Mini Rankings", NULL, 90}, {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_face_xoffset, 95}, From d0761d00441fa62f1a1c25ae3145df8870244a82 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 21:29:14 +0100 Subject: [PATCH 30/50] background for missing 4th player screen in 4 player splitscreen just like software does c: --- src/hardware/hw_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9ba76a32b..a0999bfd1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6177,6 +6177,20 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) gr_windowcenterx += gr_viewwidth; } + if (splitscreen == 2 && player == &players[displayplayers[2]]) + { + // V_DrawPatchFill, but for the fourth screen only + GLPatch_t *gpatch = W_CachePatchName("SRB2BACK", PU_CACHE); + INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); + INT32 x, y, pw = SHORT(gpatch->width) * dupz, ph = SHORT(gpatch->height) * dupz; + + 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, gpatch); + } + } + // check for new console commands. NetUpdate(); From 2ffe7aa854f1b92c188753c27698c4f25cb42a20 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 22:13:30 +0100 Subject: [PATCH 31/50] use hwr_drawpatch to fix compiler warning and casting wrong things --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a0999bfd1..be4a6ca0d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6187,7 +6187,7 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) 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, gpatch); + HWR_DrawStretchyFixedPatch(gpatch, (x)< Date: Sun, 14 Jan 2024 22:30:27 +0100 Subject: [PATCH 32/50] remove gr_vhseffect cvar the vhs effect can be toggled off in opengl with cv_vhseffect anyways, so having cvars to do the same thing is kinda unecessary --- src/hardware/hw_main.c | 3 --- src/hardware/hw_main.h | 1 - src/m_menu.c | 7 +------ src/v_video.c | 2 +- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index be4a6ca0d..8ecc6975f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -124,7 +124,6 @@ consvar_t cv_secbright = {"secbright", "0", CV_SAVE, secbright_cons_t, consvar_t cv_grfovchange = {"gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grvhseffect = {"gr_vhseffect", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // values for the far clipping plane static float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f}; @@ -6392,8 +6391,6 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grpaletteshader); CV_RegisterVar(&cv_grflashpal); - - CV_RegisterVar(&cv_grvhseffect); } // -------------------------------------------------------------------------- diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 3dc18ccf8..6a62295f8 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -198,7 +198,6 @@ extern consvar_t cv_grflashpal; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright; -extern consvar_t cv_grvhseffect; extern CV_PossibleValue_t granisotropicmode_cons_t[]; diff --git a/src/m_menu.c b/src/m_menu.c index d851801a4..a35b68a7d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1443,8 +1443,7 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 85}, {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 95}, #ifdef HWRENDER - {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 65}, - {IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_grvhseffect, 75}, + {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 75}, {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 95}, {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 105}, @@ -1463,7 +1462,6 @@ static const char* OP_ExpTooltips[] = "Hides Sprites which are not visible\npotentially resulting in a performance boost.", #ifdef HWRENDER "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", - "Show a VHS-like effect when the game is paused or youre rewinding replays.", "Fixes issues that resulted in Textures sticking from the ground sometimes.\n This may be CPU heavy and result in worse performance in some cases.", "Fixes issues that resulted in Textures not being properly skewed\n example: Fences on slopes that didnt show proper.\n This may be CPU heavy and result in worse performance in some cases.", "Fixes issues that resulted in Textures on Floor over Floors ZFighting heavily.", @@ -1481,7 +1479,6 @@ enum op_exp_sprclip, #ifdef HWRENDER op_exp_grscrtx, - op_exp_grvhs, op_exp_spltwal, op_exp_pegging, op_exp_fofzfight, @@ -4426,7 +4423,6 @@ void M_Init(void) { OP_VideoOptionsMenu[op_video_ogl].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_grscrtx].status = IT_DISABLED; - OP_ExpOptionsMenu[op_exp_grvhs].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_spltwal].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_pegging].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_fofzfight].status = IT_DISABLED; @@ -4434,7 +4430,6 @@ void M_Init(void) } if (rendermode == render_opengl){ - OP_ExpOptionsMenu[op_exp_vhs].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_sprclip].status = IT_DISABLED; } diff --git a/src/v_video.c b/src/v_video.c index 28a02bcff..53a41c216 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1205,7 +1205,7 @@ void V_DrawVhsEffect(boolean rewind) if (downbary > vid.height) downbary = -barsize; #ifdef HWRENDER - if ((rendermode == render_opengl) && (cv_grvhseffect.value)) + if (rendermode == render_opengl) { HWR_RenderVhsEffect(upbary, downbary, updistort, downdistort, barsize); return; From c1223d767d1e6503ed165f434c7b78961b53aade Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 22:39:50 +0100 Subject: [PATCH 33/50] remove this hacky stuff, just dont interpolate it it barely looked any better, it was actually just faster than it shouldve been --- src/v_video.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 53a41c216..c1f1e21f0 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1186,21 +1186,12 @@ void V_DrawVhsEffect(boolean rewind) if (rewind) V_DrawVhsEffect(false); // experimentation - if (R_UsingFrameInterpolation()) // omg i fucking hate interp so much, its a bit smoother but still not great whatever, atleast like this shit wont completely go nuts when youre on high framerates + if (renderisnewtic) { - if (renderisnewtic) - { - upbary -= FixedMul(vid.dupy * (rewind ? 3 : 1.8f), 22937*3); - downbary += FixedMul(vid.dupy * (rewind ? 2 : 1), 22937*3); - } - } - else - { - upbary -= vid.dupy * (rewind ? 3 : 1.8f); - downbary += vid.dupy * (rewind ? 2 : 1); + upbary -= (vid.dupy * (rewind ? 3 : 1.8f)); + downbary += (vid.dupy * (rewind ? 2 : 1)); } - if (upbary < -barsize) upbary = vid.height; if (downbary > vid.height) downbary = -barsize; From d2bf2bc5810a92bf64e8f8b5329a9d730eb2a298 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 22:53:20 +0100 Subject: [PATCH 34/50] forgor --- src/v_video.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index c1f1e21f0..f54bddfdc 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -20,8 +20,6 @@ #include "r_draw.h" #include "console.h" -#include "r_fps.h" //vhs effect stuff - #include "i_video.h" // rendermode #include "z_zone.h" #include "m_misc.h" From 79a594f6eede26f3beb65616bbe84c29b4a9640d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 22:57:00 +0100 Subject: [PATCH 35/50] tooltips greenres fixed by nepdisk c: --- src/m_menu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index a35b68a7d..11fa9624d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1457,14 +1457,14 @@ static const char* OP_ExpTooltips[] = NULL, "Should weather be interpolated? Weather should look about the\nsame but perform a bit better when disabled.", "When weather is on this will cut the object amount used in half.", - "Show a VHS-like effect when the game is paused or youre rewinding replays.", + "Show a VHS-like effect when the game is paused\n or youre rewinding replays.", "Hides 3DFloors which are not visible\npotentially resulting in a performance boost.", "Hides Sprites which are not visible\npotentially resulting in a performance boost.", #ifdef HWRENDER "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", - "Fixes issues that resulted in Textures sticking from the ground sometimes.\n This may be CPU heavy and result in worse performance in some cases.", + "Fixes issues that resulted in Textures sticking from the\nground sometimes.\nThis may be CPU heavy and result in worse performance in some cases.", "Fixes issues that resulted in Textures not being properly skewed\n example: Fences on slopes that didnt show proper.\n This may be CPU heavy and result in worse performance in some cases.", - "Fixes issues that resulted in Textures on Floor over Floors ZFighting heavily.", + "Fixes issues that resulted in Textures on Floor over Floors\nZFighting heavily.", "Toggle for FOF wall cutoff with slopes.", #endif }; From a36e633555f317947fc5fa3ef8d03fe47d4ad732 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 23:49:48 +0100 Subject: [PATCH 36/50] Revert "Optimize HWR_RenderBatches polygon sorting" This reverts commit 5201ccd6d203e8b81434edc12368c41a9f83f24f. --- src/hardware/r_opengl/r_opengl.c | 58 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 7ef8aed94..2fbd9071e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2390,7 +2390,7 @@ int finalVertexArrayAllocSize = 65536; PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed int polygonArraySize = 0; -PolygonArrayEntry **polygonArraySorted = NULL;// contains sorted pointers to polygonArray +UINT32* polygonIndexArray = NULL;// contains sorting pointers for polygonArray int polygonArrayAllocSize = 65536; FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon @@ -2406,7 +2406,7 @@ EXPORT void HWRAPI(StartBatching) (void) finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); - polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); + polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32)); unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); } // drawing functions will now collect the drawing data instead of passing it to opengl @@ -2416,8 +2416,10 @@ EXPORT void HWRAPI(StartBatching) (void) static int comparePolygons(const void *p1, const void *p2) { - PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; - PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; + unsigned int index1 = *(const unsigned int*)p1; + unsigned int index2 = *(const unsigned int*)p2; + PolygonArrayEntry* poly1 = &polygonArray[index1]; + PolygonArrayEntry* poly2 = &polygonArray[index2]; int diff; INT64 diff64; @@ -2433,7 +2435,7 @@ static int comparePolygons(const void *p1, const void *p2) // skywalls and horizon lines must retain their order for horizon lines to work if (shader1 == -1 && shader2 == -1) - return poly1 - poly2; + return index1 - index2; diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; @@ -2464,8 +2466,10 @@ static int comparePolygons(const void *p1, const void *p2) static int comparePolygonsNoShaders(const void *p1, const void *p2) { - PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; - PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; + unsigned int index1 = *(const unsigned int*)p1; + unsigned int index2 = *(const unsigned int*)p2; + PolygonArrayEntry* poly1 = &polygonArray[index1]; + PolygonArrayEntry* poly2 = &polygonArray[index2]; int diff; INT64 diff64; @@ -2480,7 +2484,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) // skywalls and horizon lines must retain their order for horizon lines to work if (texNum1 == 0 && texNum2 == 0) - return poly1 - poly2; + return index1 - index2; diff = poly1->polyFlags - poly2->polyFlags; if (diff != 0) return diff; @@ -2497,7 +2501,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i int finalVertexWritePos = 0;// position in finalVertexArray int finalIndexWritePos = 0;// position in finalVertexIndexArray - int polygonReadPos = 0;// position in polygonArraySorted + int polygonReadPos = 0;// position in polygonIndexArray GLuint currentShader; GLuint currentTexture; @@ -2523,19 +2527,19 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i *sNumPolys = polygonArraySize; *sNumCalls = *sNumVerts = 0; *sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 1; - // init polygonArraySorted + // init polygonIndexArray for (i = 0; i < polygonArraySize; i++) { - polygonArraySorted[i] = &polygonArray[i]; + polygonIndexArray[i] = i; } // sort polygons //CONS_Printf("qsort polys\n"); *sSortTime = I_GetPreciseTime(); if (gl_allowshaders) - qsort(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygons); + qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons); else - qsort(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygonsNoShaders); + qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders); *sSortTime = I_GetPreciseTime() - *sSortTime; //CONS_Printf("sort done\n"); // sort order @@ -2547,10 +2551,10 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i *sDrawTime = I_GetPreciseTime(); - currentShader = polygonArraySorted[0]->shader; - currentTexture = polygonArraySorted[0]->texNum; - currentPolyFlags = polygonArraySorted[0]->polyFlags; - currentSurfaceInfo = polygonArraySorted[0]->surf; + currentShader = polygonArray[polygonIndexArray[0]].shader; + currentTexture = polygonArray[polygonIndexArray[0]].texNum; + currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags; + currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf; // For now, will sort and track the colors. Vertex attributes could be used instead of uniforms // and a color array could replace the color calls. @@ -2628,8 +2632,8 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i // reset write pos // repeat loop - PolygonArrayEntry *entry = polygonArraySorted[polygonReadPos++]; - int numVerts = entry->numVerts; + int index = polygonIndexArray[polygonReadPos++]; + int numVerts = polygonArray[index].numVerts; // before writing, check if there is enough room // using 'while' instead of 'if' here makes sure that there will *always* be enough room. // probably never will this loop run more than once though @@ -2654,7 +2658,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i } //CONS_Printf("write verts to final\n"); // write the vertices of the polygon - memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[entry->vertsIndex], + memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[polygonArray[index].vertsIndex], numVerts * sizeof(FOutVector)); // write the indexes, pointing to the fan vertexes but in triangles format firstIndex = finalVertexWritePos; @@ -2676,11 +2680,11 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i { //CONS_Printf("state change check\n"); // check if a state change is required, set the change bools and next vars - PolygonArrayEntry *nextEntry = polygonArraySorted[polygonReadPos]; - nextShader = nextEntry->shader; - nextTexture = nextEntry->texNum; - nextPolyFlags = nextEntry->polyFlags; - nextSurfaceInfo = nextEntry->surf; + int nextIndex = polygonIndexArray[polygonReadPos]; + nextShader = polygonArray[nextIndex].shader; + nextTexture = polygonArray[nextIndex].texNum; + nextPolyFlags = polygonArray[nextIndex].polyFlags; + nextSurfaceInfo = polygonArray[nextIndex].surf; if (nextPolyFlags & PF_NoTexture) nextTexture = 0; if (currentShader != nextShader) @@ -2885,8 +2889,8 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI free(polygonArray); polygonArray = new_array; // also need to redo the index array, dont need to copy it though - free(polygonArraySorted); - polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); + free(polygonIndexArray); + polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(unsigned int)); } while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize) From 2093bf27b9e3b89595569e9cb69ef89c9086fd64 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 08:12:40 +0100 Subject: [PATCH 37/50] clean up drawfill transparency --- src/hardware/hw_draw.c | 5 ++--- src/v_video.c | 30 ++++++++++++++---------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 99c90243e..8feb7c050 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1074,10 +1074,9 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) else if (alphalevel == 14) Surf.PolyColor.s.alpha = softwaretranstogl[hudtrans]; else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans]; else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); } - else - HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest, false); + + HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); } #ifdef HAVE_PNG diff --git a/src/v_video.c b/src/v_video.c index f54bddfdc..d0ccefa1e 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -698,8 +698,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) { UINT8 *dest; const UINT8 *deststop; - INT32 u, v; - UINT32 alphalevel = 0; + UINT32 alphalevel = ((c & V_ALPHAMASK) >> V_ALPHASHIFT); if (rendermode == render_none) return; @@ -776,7 +775,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) dest = screens[0] + y*vid.width + x; deststop = screens[0] + vid.rowbytes * vid.height; - if ((alphalevel = ((c & V_ALPHAMASK) >> V_ALPHASHIFT))) + if (alphalevel) { if (alphalevel == 13) alphalevel = hudminusalpha[cv_translucenthud.value]; @@ -790,21 +789,20 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) } c &= 255; - - if (!alphalevel) { + + if (alphalevel) + { + const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<= 0) && dest < deststop; dest += vid.width) + { + for (x = 0; x < w; x++) + dest[x] = fadetable[dest[x]]; + } + } + else + { for (;(--h >= 0) && dest < deststop; dest += vid.width) memset(dest, c, w * vid.bpp); - } else { // holy fuck i hope this doesent break lmao - const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<y) ? y : x - w = clip(w,vid.width); - h = clip(h,vid.height); -#undef clip - for (v = 0; v < h; v++, dest += vid.width) { - for (u = 0; u < w; u++) { - dest[u] = fadetable[dest[u]]; - } - } } } From be3a57c8abb11a114d03e5925524307914304c6f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 08:59:04 +0100 Subject: [PATCH 38/50] proper big room fix no idea what i was doing here, pointtoangle64 does all we need, no need for a hacky 64bit pointtoangleex --- src/hardware/hw_main.c | 8 ++++---- src/r_bsp.c | 8 ++++---- src/r_main.c | 43 +++++++++++++++++------------------------- src/r_main.h | 2 +- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 8ecc6975f..b2a4bdde8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2891,8 +2891,8 @@ void HWR_AddLine(seg_t *line) } // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngleEx64(viewx, viewy, v1x, v1y); - angle2 = R_PointToAngleEx64(viewx, viewy, v2x, v2y); + angle1 = R_PointToAngle64(v1x, v1y); + angle2 = R_PointToAngle64(v2x, v2y); // do an extra culling check when rendering portals // check if any line vertex is on the viewable side of the portal target line @@ -3085,8 +3085,8 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) if (mindist > current_bsp_culling_distance) return false; } - angle1 = R_PointToAngleEx64(viewx, viewy, px1, py1); - angle2 = R_PointToAngleEx64(viewx, viewy, px2, py2); + angle1 = R_PointToAngle64(px1, py1); + angle2 = R_PointToAngle64(px2, py2); return gld_clipper_SafeCheckRange(angle2, angle1); } diff --git a/src/r_bsp.c b/src/r_bsp.c index 795ef459c..8750c2ee3 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -410,8 +410,8 @@ static void R_AddLine(seg_t *line) return; // big room fix - angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); - angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y); + angle1 = R_PointToAngle64(line->v1->x, line->v1->y); + angle2 = R_PointToAngle64(line->v2->x, line->v2->y); curline = line; // Clip to view edges. @@ -613,8 +613,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) check = checkcoord[boxpos]; // big room fix - angle1 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; - angle2 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; if ((signed)angle1 < (signed)angle2) { diff --git a/src/r_main.c b/src/r_main.c index 08bd34cb6..f067558e4 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -395,6 +395,23 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y) 0; } +// This version uses 64-bit variables to avoid overflows with large values. +angle_t R_PointToAngle64(INT64 x, INT64 y) +{ + return (y -= viewy, (x -= viewx) || y) ? + x >= 0 ? + y >= 0 ? + (x > y) ? tantoangle[SlopeDivEx(y,x)] : // octant 0 + ANGLE_90-tantoangle[SlopeDivEx(x,y)] : // octant 1 + x > (y = -y) ? 0-tantoangle[SlopeDivEx(y,x)] : // octant 8 + ANGLE_270+tantoangle[SlopeDivEx(x,y)] : // octant 7 + y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDivEx(y,x)] : // octant 3 + ANGLE_90 + tantoangle[SlopeDivEx(x,y)] : // octant 2 + (x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDivEx(y,x)] : // octant 4 + ANGLE_270-tantoangle[SlopeDivEx(x,y)] : // octant 5 + 0; +} + angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) { return (y -= pviewy, (x -= pviewx) || y) ? @@ -489,32 +506,6 @@ angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1) 0; } -angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1) -{ - INT64 dx = x1 - x2; - INT64 dy = y1 - y2; - - // Check for potential overflow or underflow - if (dx < INT64_MIN || dx > INT64_MAX || dy < INT64_MIN || dy > INT64_MAX) - { - x1 = (INT64)(dx / 2 + x2); - y1 = (INT64)(dy / 2 + y2); - } - - return (y1 -= y2, (x1 -= x2) || y1) ? - x1 >= 0 ? - y1 >= 0 ? - (x1 > y1) ? tantoangle[SlopeDivEx(y1, x1)] : // octant 0 - ANGLE_90 - tantoangle[SlopeDivEx(x1, y1)] : // octant 1 - x1 > (y1 = -y1) ? 0 - tantoangle[SlopeDivEx(y1, x1)] : // octant 8 - ANGLE_270 + tantoangle[SlopeDivEx(x1, y1)] : // octant 7 - y1 >= 0 ? (x1 = -x1) > y1 ? ANGLE_180 - tantoangle[SlopeDivEx(y1, x1)] : // octant 3 - ANGLE_90 + tantoangle[SlopeDivEx(x1, y1)] : // octant 2 - (x1 = -x1) > (y1 = -y1) ? ANGLE_180 + tantoangle[SlopeDivEx(y1, x1)] : // octant 4 - ANGLE_270 - tantoangle[SlopeDivEx(x1, y1)] : // octant 5 - 0; -} - // // R_ScaleFromGlobalAngle // Returns the texture mapping scale for the current line (horizontal span) diff --git a/src/r_main.h b/src/r_main.h index 6a7ea7da6..dadb1c9cf 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -68,9 +68,9 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); +angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1); -angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1); fixed_t R_PointToDist(fixed_t x, fixed_t y); fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player); From 48320b5f96d1cb98c6b72618a1a1aa234f4a6db9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 08:35:45 +0100 Subject: [PATCH 39/50] this can be static --- src/r_things.c | 2 +- src/r_things.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 498c46bf4..e7670ce88 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2669,7 +2669,7 @@ static boolean R_CheckSpriteVisible(vissprite_t *spr, INT32 x1, INT32 x2) // R_ClipVisSprite // Clips vissprites without drawing, so that portals can work. -Red -void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2) +static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2) { drawseg_t *ds; INT32 x; diff --git a/src/r_things.h b/src/r_things.h index 966ff3df1..823bad9a8 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -182,7 +182,6 @@ typedef struct vissprite_s extern UINT32 visspritecount, numvisiblesprites; void R_ClipSprites(void); -void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2); UINT8 *R_GetSpriteTranslation(vissprite_t *vis); From 7edfdf932577b8576776ade8ea2f49b715bbe084 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 13:47:13 +0100 Subject: [PATCH 40/50] forgor --- src/hardware/hw_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b2a4bdde8..49a9a6ce7 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5945,8 +5945,8 @@ static void HWR_PortalClipping(gl_portal_t *portal) line_t *line = &lines[portal->clipline]; - angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); - angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y); + angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); // clip things that are not inside the portal window from our viewpoint gld_clipper_SafeAddClipRange(angle2, angle1); From e2a4fdc39525109b64e799671fd6b9cb9913abfc Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 15:57:17 +0100 Subject: [PATCH 41/50] Revert "Localskins on replays" This reverts commit e1f821e121c5032fbafee7d0eefc9f2cbd3efc20. --- src/g_game.c | 29 ++--------------------------- src/g_game.h | 1 - src/r_things.c | 2 -- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index dceaafa29..38f063f62 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3012,9 +3012,6 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost) } P_MovePlayerToSpawn(playernum, spawnpoint); - // TODO: This is so dumb. - demo_extradata[playernum] |= DXD_LOCALSKIN; - #ifdef HAVE_BLUA LUAh_PlayerSpawn(&players[playernum]); // Lua hook for player spawning :) #endif @@ -3350,7 +3347,7 @@ void G_AddPlayer(INT32 playernum) p->jointime = 0; p->playerstate = PST_REBORN; - demo_extradata[playernum] |= DXD_PLAYSTATE|DXD_COLOR|DXD_NAME|DXD_SKIN|DXD_LOCALSKIN; // Set everything + demo_extradata[playernum] |= DXD_PLAYSTATE|DXD_COLOR|DXD_NAME|DXD_SKIN; // Set everything } void G_ExitLevel(void) @@ -5349,14 +5346,7 @@ void G_ReadDemoExtraData(void) else if (G_RaceGametype()) P_CheckRacers(); // also SRB2Kart } - if (extradata & DXD_LOCALSKIN) - { - // TODO: Does this work just fine? - M_Memcpy(name, demo_p, 16); - //CONS_Printf("Loaded localskin data from replay: %s\n", name); - demo_p += 16; - SetLocalPlayerSkin(p, name, NULL); - } + p = READUINT8(demo_p); } @@ -5443,21 +5433,6 @@ void G_WriteDemoExtraData(void) else WRITEUINT8(demo_p, DXD_PST_PLAYING); } - if (demo_extradata[i] & DXD_LOCALSKIN) - { - // Skin - memset(name, 0, 16); - // check for different localskin conditions - if (players[i].skinlocal && players[i].localskin > 0) - strncpy(name, localskins[players[i].localskin - 1].name, 16); - else if (!players[i].skinlocal && players[i].localskin > 0) - strncpy(name, skins[players[i].localskin - 1].name, 16); - else - strncpy(name, "none", 16); - //CONS_Printf("Saved localskin data to replay: %s\n", name); - M_Memcpy(demo_p,name,16); - demo_p += 16; - } } demo_extradata[i] = 0; diff --git a/src/g_game.h b/src/g_game.h index 6491472e6..a57468a2e 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -297,7 +297,6 @@ extern UINT8 demo_writerng; #define DXD_NAME 0x04 // name changed #define DXD_COLOR 0x08 // color changed #define DXD_PLAYSTATE 0x10 // state changed between playing, spectating, or not in-game -#define DXD_LOCALSKIN 0x20 // localskin changed #define DXD_PST_PLAYING 0x01 #define DXD_PST_SPECTATING 0x02 diff --git a/src/r_things.c b/src/r_things.c index e7670ce88..b9fb384f8 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3274,8 +3274,6 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) CV_StealthSet(cvar, "none"); } } - - demo_extradata[playernum] |= DXD_LOCALSKIN; } // Same as SetPlayerSkin, but uses the skin #. From 6346ac0a9617ce8d4ca0ed598fa606b7f20da5d2 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 16 Jan 2024 07:11:43 +0100 Subject: [PATCH 42/50] Revert "invert encore remap is 12 not 15?" This reverts commit 8e6023d85060a82b0311a3e862b56f53d6440272. --- src/r_bsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index 8750c2ee3..2de30d2ab 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -39,7 +39,7 @@ INT32 doorclosed; boolean R_NoEncore(sector_t *sector, boolean ceiling) { - boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 12); + boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 15); #if 0 // perfect implementation INT32 val = GETSECSPECIAL(sector->special, 3); if (val != 1 && val != 3 // spring panel From a0eab7d5f80ba7ee86b87202d2eb568c5d49eca6 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 16 Jan 2024 07:17:05 +0100 Subject: [PATCH 43/50] Revert "invert encore remap is 12 not 15?" This reverts commit 8e6023d85060a82b0311a3e862b56f53d6440272. --- src/r_bsp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index 8750c2ee3..2de30d2ab 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -39,7 +39,7 @@ INT32 doorclosed; boolean R_NoEncore(sector_t *sector, boolean ceiling) { - boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 12); + boolean invertencore = (GETSECSPECIAL(sector->special, 2) == 15); #if 0 // perfect implementation INT32 val = GETSECSPECIAL(sector->special, 3); if (val != 1 && val != 3 // spring panel From 8f6cc895a016504f82f5e7062c15c3fecd924093 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 16 Jan 2024 16:22:30 +0100 Subject: [PATCH 44/50] fix ogl shearing with flipcam --- src/hardware/r_opengl/r_opengl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 2fbd9071e..965e55513 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -3951,6 +3951,8 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) if (shearing) { float dy = FIXED_TO_FLOAT(AIMINGTODY(stransform->viewaiming)) * 2; //screen_width/BASEVIDWIDTH; + if (stransform->flip) + dy *= -1.0f; pglTranslatef(0.0f, -dy/BASEVIDHEIGHT, 0.0f); } From 68354baf283f461d38e2231c91bb55b8922cd04c Mon Sep 17 00:00:00 2001 From: Chearii Date: Tue, 16 Jan 2024 13:46:30 -0500 Subject: [PATCH 45/50] Add ``getSpritePatch`` --- src/lua_hudlib.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 04bbaa928..da798ccbc 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -11,6 +11,7 @@ /// \brief custom HUD rendering library for Lua scripting #include "doomdef.h" +#include "fastcmp.h" #ifdef HAVE_BLUA #include "r_defs.h" #include "r_local.h" @@ -346,6 +347,79 @@ static int libd_cachePatch(lua_State *L) return 1; } +// v.getSpritePatch(sprite, [frame, [angle, [rollangle]]]) +static int libd_getSpritePatch(lua_State *L) +{ + UINT32 i; // sprite prefix + UINT32 frame = 0; // 'A' + UINT8 angle = 0; + spritedef_t *sprdef; + spriteframe_t *sprframe; + HUDONLY + + if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR_THOK + { + i = lua_tonumber(L, 1); + if (i >= NUMSPRITES) + return 0; + } + else if (lua_isstring(L, 1)) // sprite prefix name given, e.g. "THOK" + { + const char *name = lua_tostring(L, 1); + for (i = 0; i < NUMSPRITES; i++) + if (fastcmp(name, sprnames[i])) + break; + if (i >= NUMSPRITES) + return 0; + } + else + return 0; + + // TODO: figure out a means of getting playersprites without crashes + if (i == SPR_PLAY) // not for players + return luaL_error(L, "Player sprites are not supported."); + + sprdef = &sprites[i]; + + // set frame number + frame = luaL_optinteger(L, 2, 0); + frame &= FF_FRAMEMASK; // ignore any bits that are not the actual frame, just in case + if (frame >= sprdef->numframes) + return 0; + // set angle number + sprframe = &sprdef->spriteframes[frame]; + angle = luaL_optinteger(L, 3, 1); + + // convert WAD editor angle numbers (1-8) to internal angle numbers (0-7) + // keep 0 the same since we'll make it default to angle 1 (which is internally 0) + // in case somebody didn't know that angle 0 really just maps all 8 angles to the same patch + if (angle != 0) + angle--; + + if (angle >= 8) // out of range? + angle = (angle & 7); // modulus angle by 8 + + // rotsprite????? + if (lua_isnumber(L, 4) && (cv_spriteroll.value)) + { + angle_t rollangle = luaL_checkangle(L, 4); + INT32 rot = R_GetRollAngle(rollangle); + + if (rot) { + patch_t *rotsprite = Patch_GetRotatedSprite(sprframe, frame, angle, sprframe->flip & (1<lumppat[angle], PU_STATIC), META_PATCH); + lua_pushboolean(L, (sprframe->flip & (1< Date: Tue, 16 Jan 2024 14:47:48 -0500 Subject: [PATCH 46/50] Player sprite support. --- src/lua_hudlib.c | 51 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index da798ccbc..e272bef59 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -347,16 +347,46 @@ static int libd_cachePatch(lua_State *L) return 1; } -// v.getSpritePatch(sprite, [frame, [angle, [rollangle]]]) +// this is structured like getSprite2Patch in vanilla 2.2 +// v.getSpritePatch(skin, sprite, [frame, [angle, [rollangle]]]) static int libd_getSpritePatch(lua_State *L) { UINT32 i; // sprite prefix + INT32 skn = -1; // skin number UINT32 frame = 0; // 'A' UINT8 angle = 0; spritedef_t *sprdef; spriteframe_t *sprframe; +#ifdef ROTSPRITE + spriteinfo_t *sprinfo; +#endif HUDONLY + // mashing together the stuff from getSprite2Patch: + // get skin first! + if (!lua_isnoneornil(L, 1)) // ONLY do this if we have a skin + { + if (lua_isnumber(L, 1)) // find skin by number + { + skn = lua_tonumber(L, 1); + if (skn < 0 || skn >= MAXSKINS) + return luaL_error(L, "skin number %d out of range (0 - %d)", skn, MAXSKINS-1); + if (skn >= numskins) + return 0; + } + else // find skin by name + { + const char *name = luaL_checkstring(L, 1); + for (skn = 0; skn < numskins; skn++) + if (fastcmp(skins[skn].name, name)) + break; + if (skn >= numskins) + return 0; + } + } + + lua_remove(L, 1); // remove skin now + if (lua_isnumber(L, 1)) // sprite number given, e.g. SPR_THOK { i = lua_tonumber(L, 1); @@ -375,11 +405,20 @@ static int libd_getSpritePatch(lua_State *L) else return 0; - // TODO: figure out a means of getting playersprites without crashes - if (i == SPR_PLAY) // not for players - return luaL_error(L, "Player sprites are not supported."); + // get outta dodge if we're a playersprite and have no skin + if ((i == SPR_PLAY) && (skn < 0)) + return luaL_error(L, "You must provide a skin for player sprites!"); - sprdef = &sprites[i]; + if (skn < 0) + { + sprdef = &sprites[i]; + sprinfo = &spriteinfo[i]; + } + else + { + sprdef = &skins[skn].spritedef; + sprinfo = &skins[skn].sprinfo; + } // set frame number frame = luaL_optinteger(L, 2, 0); @@ -406,7 +445,7 @@ static int libd_getSpritePatch(lua_State *L) INT32 rot = R_GetRollAngle(rollangle); if (rot) { - patch_t *rotsprite = Patch_GetRotatedSprite(sprframe, frame, angle, sprframe->flip & (1<flip & (1< Date: Tue, 16 Jan 2024 15:01:08 -0500 Subject: [PATCH 47/50] Add some labeling --- src/lua_hudlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index e272bef59..c7b1ec38e 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -409,12 +409,12 @@ static int libd_getSpritePatch(lua_State *L) if ((i == SPR_PLAY) && (skn < 0)) return luaL_error(L, "You must provide a skin for player sprites!"); - if (skn < 0) + if (skn < 0) // standard sprite { sprdef = &sprites[i]; sprinfo = &spriteinfo[i]; } - else + else // player skin { sprdef = &skins[skn].spritedef; sprinfo = &skins[skn].sprinfo; From b9115aa5f8c422d047081cf6911a72404d433e04 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 17 Jan 2024 12:11:32 +0100 Subject: [PATCH 48/50] (hopefully) fix overflow in R_DrawRepeatMaskedColumn MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit well this fixes the game hanging in software renderer on Marsh´s Marble Zone --- src/r_segs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_segs.c b/src/r_segs.c index 4623d3b0e..8eb3c9b41 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -690,7 +690,7 @@ static void R_DrawRepeatMaskedColumn(column_t *col) { while (sprtopscreen < sprbotscreen) { R_DrawMaskedColumn(col); - if ((INT64)sprtopscreen + dc_texheight*spryscale > (INT64)INT32_MAX) // prevent overflow + if (sprtopscreen + (INT64)dc_texheight*spryscale > (INT64)INT32_MAX) // prevent overflow sprtopscreen = INT32_MAX; else sprtopscreen += dc_texheight*spryscale; From 6d642b124aca31421692395639f2ea3df600c090 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 17 Jan 2024 16:48:11 +0300 Subject: [PATCH 49/50] Fix typo --- src/sdl/i_system.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 48ea7fea3..c04434347 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -466,9 +466,9 @@ static void I_ReportSignal(int num, int coredumped) } #ifdef HAVE_LIBBACKTRACE - strncat(msg, "\n\nCrash report have been saved into srb2kart-crash-log.txt", 255); + strncat(msg, "\n\nCrash report has been saved into srb2kart-crash-log.txt", 255); #elif defined(_WIN32) && !defined(__MINGW64__) - strncat(msg, "\n\nCrash report have been saved into srb2kart.rpt", 255); + strncat(msg, "\n\nCrash report has been saved into srb2kart.rpt", 255); #endif I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); From 9a8d6efcd7f4e650b30dc17e36dda728bb87a114 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 18 Jan 2024 15:21:20 +0100 Subject: [PATCH 50/50] make thundershield follow player offset this allows the to stay on the player when saltyhopping etc. --- src/p_mobj.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/p_mobj.c b/src/p_mobj.c index b577ac32d..bacf6fce6 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -8308,6 +8308,8 @@ void P_MobjThinker(mobj_t *mobj) } P_MoveOrigin(mobj, destx, desty, mobj->target->z); + mobj->spriteyoffset = mobj->target->spriteyoffset; + mobj->spritexoffset = mobj->target->spritexoffset; break; } case MT_ROCKETSNEAKER: