From e03a17869e186c72d5a387e23e18765d49c0e240 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 11 Jan 2024 12:27:10 +0100 Subject: [PATCH 1/2] 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 2/2] 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(); }