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.
This commit is contained in:
Zack Middleton 2024-05-24 17:13:29 -05:00
parent c010b1ffee
commit af7812f1a0
2 changed files with 18 additions and 46 deletions

View File

@ -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);

View File

@ -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);