Skip to content

Commit

Permalink
RENDERER: Remove packAlign from R_LevelShot()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zturtleman committed May 24, 2024
1 parent 6b74bdb commit e491f51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
27 changes: 9 additions & 18 deletions code/renderergl1/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
27 changes: 9 additions & 18 deletions code/renderergl2/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit e491f51

Please sign in to comment.