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 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.
  • Loading branch information
zturtleman committed May 24, 2024
1 parent 6b1dd17 commit c5227aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 38 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
31 changes: 11 additions & 20 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 @@ -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];
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 c5227aa

Please sign in to comment.