From b2b03ecbb5750f86042cd52b58eee251d3020a0c Mon Sep 17 00:00:00 2001 From: Eidolon Date: Tue, 12 Dec 2023 07:10:32 -0600 Subject: [PATCH 1/7] Fix GLENCORE memory leak, re-enable --- src/hardware/hw_cache.c | 30 +++++++++--------------------- src/hardware/hw_glob.h | 1 - src/hardware/hw_main.c | 8 ++------ src/r_data.c | 4 +--- 4 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index df3c663ff..636836a64 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -452,9 +452,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex) UINT8 *pdata; INT32 blockwidth, blockheight, blocksize; -#ifdef GLENCORE UINT8 *colormap = colormaps; -#endif INT32 i; boolean skyspecial = false; //poor hack for Legacy large skies.. @@ -479,14 +477,12 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *grtex) grtex->mipmap.height = (UINT16)texture->height; grtex->mipmap.format = textureformat; -#ifdef GLENCORE if (encoremap) colormap += COLORMAP_REMAPOFFSET; grtex->mipmap.colormap = Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); grtex->mipmap.colormap->source = colormap; M_Memcpy(grtex->mipmap.colormap->data, colormap, 256 * sizeof(UINT8)); -#endif blockwidth = texture->width; blockheight = texture->height; @@ -816,10 +812,8 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex) static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) { -#ifdef GLENCORE UINT8 *flat; size_t steppy; -#endif size_t size, pflatsize; @@ -861,12 +855,10 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) W_ReadLump(flatlumpnum, Z_Malloc(W_LumpLength(flatlumpnum), PU_HWRCACHE, &grMipmap->data)); -#ifdef GLENCORE flat = grMipmap->data; for (steppy = 0; steppy < size; steppy++) if (flat[steppy] != HWR_PATCHES_CHROMAKEY_COLORINDEX) flat[steppy] = grMipmap->colormap->source[flat[steppy]]; -#endif } static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum) @@ -895,9 +887,7 @@ void HWR_GetRawFlat(lumpnum_t flatlumpnum, boolean noencoremap) GLMipmap_t *grmip; patch_t *patch; -#ifdef GLENCORE UINT8 *colormap = colormaps; -#endif if (flatlumpnum == LUMPERROR) return; @@ -905,19 +895,17 @@ void HWR_GetRawFlat(lumpnum_t flatlumpnum, boolean noencoremap) patch = HWR_GetCachedGLPatch(flatlumpnum); grmip = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; -#ifdef GLENCORE - if (!noencoremap && encoremap) - colormap += COLORMAP_REMAPOFFSET; - - grmip->colormap = Z_Calloc(sizeof(*grmip->colormap), PU_HWRPATCHCOLMIPMAP, NULL); - grmip->colormap->source = colormap; - M_Memcpy(grmip->colormap->data, colormap, 256 * sizeof(UINT8)); -#else - (void)noencoremap; -#endif - if (!grmip->downloaded && !grmip->data) + { + if (!noencoremap && encoremap) + colormap += COLORMAP_REMAPOFFSET; + + grmip->colormap = Z_Calloc(sizeof(*grmip->colormap), PU_HWRPATCHCOLMIPMAP, NULL); + grmip->colormap->source = colormap; + M_Memcpy(grmip->colormap->data, colormap, 256 * sizeof(UINT8)); + HWR_CacheFlat(grmip, flatlumpnum); + } // If hardware does not have the texture, then call pfnSetTexture to upload it if (!grmip->downloaded) diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 12d998084..bf9205c1f 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -30,7 +30,6 @@ extern "C" { //#define HWR_LOADING_SCREEN // SRB2Kart -//#define GLENCORE // ----------- // structures diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5bb4c2990..7a7e93d5b 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -4828,7 +4828,7 @@ static void HWR_ProjectSprite(mobj_t *thing) { interpmobjstate_t casterinterp = {0}; fixed_t groundz; - fixed_t floordiff; + fixed_t floordiff; if (R_UsingFrameInterpolation() && !paused) { @@ -4838,7 +4838,7 @@ static void HWR_ProjectSprite(mobj_t *thing) { R_InterpolateMobjState(caster, FRACUNIT, &casterinterp); } - + groundz = R_GetShadowZ(thing, NULL); floordiff = abs(((thing->eflags & MFE_VERTICALFLIP) ? caster->height : 0) + casterinterp.z - groundz); @@ -5038,10 +5038,8 @@ static void HWR_ProjectSprite(mobj_t *thing) { vis->colormap = colormaps; -#ifdef GLENCORE if (encoremap && (thing->flags & (MF_SCENERY|MF_NOTHINK)) && !(thing->flags & MF_DONTENCOREMAP)) vis->colormap += COLORMAP_REMAPOFFSET; -#endif } // set top/bottom coords @@ -5176,10 +5174,8 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) vis->colormap = NULL; -#ifdef GLENCORE if (encoremap && !(thing->flags & MF_DONTENCOREMAP)) vis->colormap += COLORMAP_REMAPOFFSET; -#endif // set top/bottom coords vis->gzt = FIXED_TO_FLOAT(interp.z) + (FIXED_TO_FLOAT(spritecachedinfo[lumpoff].topoffset) * this_scale); diff --git a/src/r_data.c b/src/r_data.c index a0a0dea20..89e96ecac 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -897,16 +897,14 @@ extracolormap_t *R_CreateColormapFromLinedef(char *p1, char *p2, char *p3) #undef ALPHA2INT #undef HEX2INT -#ifdef GLENCORE if (encoremap) { - j = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)]; + UINT8 j = encoremap[NearestColor((UINT8)cr, (UINT8)cg, (UINT8)cb)]; //CONS_Printf("R_CreateColormap: encoremap[%d] = %d\n", j, encoremap[j]); cr = pLocalPalette[j].s.red; cg = pLocalPalette[j].s.green; cb = pLocalPalette[j].s.blue; } -#endif // Pack rgba values into combined var // OpenGL also uses this instead of lighttables for rendering From 9147aeaac70751bda3203b53e33baab8f29c6c96 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 14 Dec 2023 17:26:21 -0600 Subject: [PATCH 2/7] Add encoremap to textures-as-flats --- src/hardware/hw_cache.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 636836a64..bdb692fbb 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -895,7 +895,7 @@ void HWR_GetRawFlat(lumpnum_t flatlumpnum, boolean noencoremap) patch = HWR_GetCachedGLPatch(flatlumpnum); grmip = ((GLPatch_t *)Patch_AllocateHardwarePatch(patch))->mipmap; - if (!grmip->downloaded && !grmip->data) + if (!grmip->colormap) { if (!noencoremap && encoremap) colormap += COLORMAP_REMAPOFFSET; @@ -903,7 +903,10 @@ void HWR_GetRawFlat(lumpnum_t flatlumpnum, boolean noencoremap) grmip->colormap = Z_Calloc(sizeof(*grmip->colormap), PU_HWRPATCHCOLMIPMAP, NULL); grmip->colormap->source = colormap; M_Memcpy(grmip->colormap->data, colormap, 256 * sizeof(UINT8)); + } + if (!grmip->downloaded && !grmip->data) + { HWR_CacheFlat(grmip, flatlumpnum); } @@ -942,8 +945,17 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) // Generate flat if missing from the cache if (!grtex->mipmap.data && !grtex->mipmap.downloaded) + { HWR_CacheTextureAsFlat(&grtex->mipmap, texturenum); + if (!noencoremap && encoremap) + { + grtex->mipmap.colormap = Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); + grtex->mipmap.colormap->source = colormaps + COLORMAP_REMAPOFFSET; + M_Memcpy(grtex->mipmap.colormap->data, colormaps + COLORMAP_REMAPOFFSET, 256); + } + } + // If hardware does not have the texture, then call pfnSetTexture to upload it if (!grtex->mipmap.downloaded) HWD.pfnSetTexture(&grtex->mipmap); From 4654bb43bb60166b58a9537831881a202604ad76 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Thu, 14 Dec 2023 23:05:17 -0600 Subject: [PATCH 3/7] Workaround encore crash in HWR_GetMappedPatch --- src/hardware/hw_cache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index bdb692fbb..485da45f8 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1082,7 +1082,8 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) Patch_CreateGL(patch); grPatch = patch->hardware; - if (colormap == colormaps || colormap == NULL) + // Blatant hack for encore colormapping aside... + if (colormap == colormaps || colormap == NULL || colormap == COLORMAP_REMAPOFFSET) { // Load the default (green) color in hardware cache HWR_GetPatch(patch); From 016cc1e95fef6c5488c3719a151a354143d3781d Mon Sep 17 00:00:00 2001 From: Eidolon Date: Fri, 15 Dec 2023 11:19:34 -0600 Subject: [PATCH 4/7] Work around pointer-integer comparison in hw_cache --- src/hardware/hw_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 485da45f8..d43631f83 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -1083,7 +1083,7 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap) grPatch = patch->hardware; // Blatant hack for encore colormapping aside... - if (colormap == colormaps || colormap == NULL || colormap == COLORMAP_REMAPOFFSET) + if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) { // Load the default (green) color in hardware cache HWR_GetPatch(patch); From 5e8da61e5ed58e0b30be1690a4aeb5beb791d59a Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sat, 16 Dec 2023 17:37:40 -0600 Subject: [PATCH 5/7] Encore colormap textures-as-flats in GL --- src/hardware/hw_cache.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index d43631f83..27d928854 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -861,11 +861,18 @@ static void HWR_CacheFlat(GLMipmap_t *grMipmap, lumpnum_t flatlumpnum) flat[steppy] = grMipmap->colormap->source[flat[steppy]]; } -static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum) +static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum, boolean noencoremap) { UINT8 *flat; UINT8 *converted; size_t size; + size_t i; + UINT8 *colormap = colormaps; + + if (!noencoremap && encoremap) + { + colormap += COLORMAP_REMAPOFFSET; + } // setup the texture info grMipmap->format = GL_TEXFMT_P_8; @@ -878,6 +885,11 @@ static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum) flat = Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); converted = (UINT8 *)Picture_TextureToFlat(texturenum); M_Memcpy(flat, converted, size); + + for (i = 0; i < size; i++) + { + flat[i] = colormap[flat[i]]; + } Z_Free(converted); } @@ -946,14 +958,7 @@ void HWR_GetLevelFlat(levelflat_t *levelflat, boolean noencoremap) // Generate flat if missing from the cache if (!grtex->mipmap.data && !grtex->mipmap.downloaded) { - HWR_CacheTextureAsFlat(&grtex->mipmap, texturenum); - - if (!noencoremap && encoremap) - { - grtex->mipmap.colormap = Z_Calloc(sizeof(*grtex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL); - grtex->mipmap.colormap->source = colormaps + COLORMAP_REMAPOFFSET; - M_Memcpy(grtex->mipmap.colormap->data, colormaps + COLORMAP_REMAPOFFSET, 256); - } + HWR_CacheTextureAsFlat(&grtex->mipmap, texturenum, noencoremap); } // If hardware does not have the texture, then call pfnSetTexture to upload it From baad413cc3cd36e119c24d114f9c20f5b5a23b93 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sat, 16 Dec 2023 19:09:47 -0600 Subject: [PATCH 6/7] Remove unneeded memcpy in HWR_CacheTextureAsFlat --- src/hardware/hw_cache.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 27d928854..a0241666c 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -884,11 +884,9 @@ static void HWR_CacheTextureAsFlat(GLMipmap_t *grMipmap, INT32 texturenum, boole flat = Z_Malloc(size, PU_HWRCACHE, &grMipmap->data); converted = (UINT8 *)Picture_TextureToFlat(texturenum); - M_Memcpy(flat, converted, size); - for (i = 0; i < size; i++) { - flat[i] = colormap[flat[i]]; + flat[i] = colormap[converted[i]]; } Z_Free(converted); } From c24b6e9f0eebdade231bdb02aa9e29dacb51fb96 Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sun, 17 Dec 2023 11:15:40 -0600 Subject: [PATCH 7/7] Fix movie recorder config --- src/m_avrecorder.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/m_avrecorder.cpp b/src/m_avrecorder.cpp index ca5cd73a4..1db609c9a 100644 --- a/src/m_avrecorder.cpp +++ b/src/m_avrecorder.cpp @@ -91,12 +91,12 @@ static AVRecorder::Config configure() if (sound_started && cv_movie_sound.value) { - cfg.audio = { 44100 }; + cfg.audio = AVRecorder::Config::Audio { 44100 }; } - cfg.video = { cv_movie_fps.value }; - + cfg.video = AVRecorder::Config::Video { }; AVRecorder::Config::Video& v = *cfg.video; + v.frame_rate = cv_movie_fps.value; auto basex = [&v](int scale) {