From c5227aa2171a8a3611069bf4e72531964dd124ad Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 24 May 2024 15:16:16 -0500 Subject: [PATCH] RENDERER: Remove packAlign from R_LevelShot() Filling the resample buffer didn't correctly handling packAlign other than 1. There isn't SIMD or something that the code wants a specific alignment. Hunk_AllocateTempMemory() is aligned to sizeof(intptr_t) anyway so there isn't a reason to add a memory alignment. --- code/renderergl1/tr_init.c | 27 +++++++++------------------ code/renderergl2/tr_init.c | 31 +++++++++++-------------------- 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/code/renderergl1/tr_init.c b/code/renderergl1/tr_init.c index e3f91d43f..07c2e2f17 100644 --- a/code/renderergl1/tr_init.c +++ b/code/renderergl1/tr_init.c @@ -484,11 +484,10 @@ sampled down from full screen distorted images static void R_LevelShot(screenshotType_e type, const char *ext) { char fileName[MAX_OSPATH]; byte *source, *allsource; - byte *resample, *resamplestart; + byte *resample; size_t offset = 0, memcount; - int spadlen, rpadlen; - int padwidth, linelen; - GLint packAlign = 1; + int spadlen; + int linelen; byte *src, *dst; int x, y; int r, g, b; @@ -515,15 +514,9 @@ static void R_LevelShot(screenshotType_e type, const char *ext) { source = allsource + offset; linelen = width * 3; - padwidth = spadlen + linelen; - - // Allocate a few more bytes so that we can choose an alignment we like - resample = ri.Hunk_AllocateTempMemory(padwidth * height + offset + packAlign - 1); + memcount = linelen * height; - resamplestart = PADP((intptr_t) resample + offset, packAlign); - - offset = resamplestart - resample; - rpadlen = padwidth - linelen; + resample = ri.Hunk_AllocateTempMemory(memcount); // resample from source xScale = glConfig.vidWidth / (float)(width * 4.0f); @@ -547,18 +540,16 @@ static void R_LevelShot(screenshotType_e type, const char *ext) { } } - memcount = (width * 3 + rpadlen) * height; - // gamma correct if (glConfig.deviceSupportsGamma) - R_GammaCorrect(resample + offset, memcount); + R_GammaCorrect(resample, memcount); if (type == ST_TGA) - RE_SaveTGA(fileName, width, height, resample + offset, rpadlen); + RE_SaveTGA(fileName, width, height, resample, 0); else if (type == ST_JPEG) - RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample + offset, rpadlen); + RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample, 0); else if (type == ST_PNG) - RE_SavePNG(fileName, width, height, resample + offset, rpadlen); + RE_SavePNG(fileName, width, height, resample, 0); ri.Hunk_FreeTempMemory(resample); ri.Hunk_FreeTempMemory(allsource); diff --git a/code/renderergl2/tr_init.c b/code/renderergl2/tr_init.c index 0414d2320..7304a564e 100644 --- a/code/renderergl2/tr_init.c +++ b/code/renderergl2/tr_init.c @@ -573,11 +573,10 @@ the menu system, sampled down from full screen distorted images static void R_LevelShot(screenshotType_e type, const char *ext) { char fileName[MAX_OSPATH]; byte *source, *allsource; - byte *resample, *resamplestart; + byte *resample; size_t offset = 0, memcount; - int spadlen, rpadlen; - int padwidth, linelen; - GLint packAlign = 1; + int spadlen; + int linelen; byte *src, *dst; int x, y; int r, g, b; @@ -604,15 +603,9 @@ static void R_LevelShot(screenshotType_e type, const char *ext) { source = allsource + offset; linelen = width * 3; - padwidth = spadlen + linelen; - - // Allocate a few more bytes so that we can choose an alignment we like - resample = ri.Hunk_AllocateTempMemory(padwidth * height + offset + packAlign - 1); + memcount = linelen * height; - resamplestart = PADP((intptr_t) resample + offset, packAlign); - - offset = resamplestart - resample; - rpadlen = padwidth - linelen; + resample = ri.Hunk_AllocateTempMemory(memcount); // resample from source xScale = glConfig.vidWidth / (float)(width * 4.0f); @@ -622,8 +615,8 @@ static void R_LevelShot(screenshotType_e type, const char *ext) { r = g = b = 0; for (yy = 0; yy < 3; yy++) { for (xx = 0; xx < 4; xx++) { - src = source + (3 * glConfig.vidWidth + spadlen) * (int)((y * 3 + yy) * yScale) + - 3 * (int)((x * 4 + xx) * xScale); + src = source + (3 * glConfig.vidWidth + spadlen) * (int)((y*3 + yy) * yScale) + + 3 * (int) ((x*4 + xx) * xScale); r += src[0]; g += src[1]; b += src[2]; @@ -636,19 +629,17 @@ static void R_LevelShot(screenshotType_e type, const char *ext) { } } - memcount = (width * 3 + rpadlen) * height; - // gamma correction if (glConfig.deviceSupportsGamma) { - R_GammaCorrect(resample + offset, memcount); + R_GammaCorrect(resample, memcount); } if (type == ST_TGA) - RE_SaveTGA(fileName, width, height, resample + offset, rpadlen); + RE_SaveTGA(fileName, width, height, resample, 0); else if (type == ST_JPEG) - RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample + offset, rpadlen); + RE_SaveJPG(fileName, r_screenshotJpegQuality->integer, width, height, resample, 0); else if (type == ST_PNG) - RE_SavePNG(fileName, width, height, resample + offset, rpadlen); + RE_SavePNG(fileName, width, height, resample, 0); ri.Hunk_FreeTempMemory(resample); ri.Hunk_FreeTempMemory(allsource);