From af7812f1a04fe2cc2bbee777cf9fad095f528446 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Fri, 24 May 2024 17:13:29 -0500 Subject: [PATCH] Remove packAlign from R_LevelShot() Filling the resample buffer didn't correctly handle offset for packAlign if it didn't match the alignment returned by Hunk_AllocateTempMemory(). 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 here. --- code/renderergl1/tr_init.c | 32 +++++++++----------------------- code/renderergl2/tr_init.c | 32 +++++++++----------------------- 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/code/renderergl1/tr_init.c b/code/renderergl1/tr_init.c index 425f84ae..a93af56b 100644 --- a/code/renderergl1/tr_init.c +++ b/code/renderergl1/tr_init.c @@ -532,11 +532,10 @@ the menu system, sampled down from full screen distorted images 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; + int spadlen; + int linelen; byte *src, *dst; int x, y; int r, g, b; @@ -562,21 +561,10 @@ void R_LevelShot( screenshotType_e type, const char *ext ) { allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen); source = allsource + offset; - // - // Based on RB_ReadPixels - qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign); - linelen = width * 3; - padwidth = PAD(linelen, packAlign); + memcount = linelen * height; - // Allocate a few more bytes so that we can choose an alignment we like - resample = ri.Hunk_AllocateTempMemory(padwidth * height + offset + packAlign - 1); - - 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); @@ -600,18 +588,16 @@ 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 b4a57af7..9e78e51c 100644 --- a/code/renderergl2/tr_init.c +++ b/code/renderergl2/tr_init.c @@ -623,11 +623,10 @@ the menu system, sampled down from full screen distorted images 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; + int spadlen; + int linelen; byte *src, *dst; int x, y; int r, g, b; @@ -653,21 +652,10 @@ void R_LevelShot( screenshotType_e type, const char *ext ) { allsource = RB_ReadPixels(0, 0, glConfig.vidWidth, glConfig.vidHeight, &offset, &spadlen); source = allsource + offset; - // - // Based on RB_ReadPixels - qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign); - linelen = width * 3; - padwidth = PAD(linelen, packAlign); + memcount = linelen * height; - // Allocate a few more bytes so that we can choose an alignment we like - resample = ri.Hunk_AllocateTempMemory(padwidth * height + offset + packAlign - 1); - - 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); @@ -691,18 +679,16 @@ 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);