mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-17 10:11:02 +00:00
Split the column caching code of HWR_DrawPatchInCache into a new function, HWR_DrawColumnInCache. This should make modifying the OpenGL caching code look a little less daunting, hopefully.
I also removed some "const"s for now, since I wasn't sure if they were needed or even correct to use or not here... if they're fine I could add them back later though. (Note: I have not tested if this compiles yet)
This commit is contained in:
parent
8cbac26653
commit
30a00c812c
1 changed files with 108 additions and 86 deletions
|
@ -41,90 +41,35 @@ static INT32 blocksize, blockwidth, blockheight;
|
|||
INT32 patchformat = GR_TEXFMT_AP_88; // use alpha for holes
|
||||
INT32 textureformat = GR_TEXFMT_P_8; // use chromakey for hole
|
||||
|
||||
// sprite, use alpha and chroma key for hole
|
||||
static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
|
||||
|
||||
// This code was originally placed directly in HWR_DrawPatchInCache.
|
||||
// It is now split from it for my sanity! (and the sanity of others)
|
||||
// -- Monster Iestyn (13/02/19)
|
||||
static void HWR_DrawColumnInCache(column_t *patchcol, UINT8 *block, GLMipmap_t *mipmap,
|
||||
INT32 pblockwidth, INT32 pblockheight, INT32 blockmodulo,
|
||||
INT32 ptexturewidth, INT32 ptextureheight,
|
||||
INT32 originx, INT32 originy, // where to draw patch in surface block
|
||||
const patch_t *realpatch, INT32 bpp)
|
||||
fixed_t yfracstep, fixed_t scale_y,
|
||||
INT32 originy,
|
||||
INT32 bpp
|
||||
)
|
||||
{
|
||||
INT32 x, x1, x2;
|
||||
INT32 col, ncols;
|
||||
fixed_t xfrac, xfracstep;
|
||||
fixed_t yfrac, yfracstep, position, count;
|
||||
fixed_t scale_y;
|
||||
RGBA_t colortemp;
|
||||
fixed_t yfrac, position, count;
|
||||
UINT8 *dest;
|
||||
const UINT8 *source;
|
||||
const column_t *patchcol;
|
||||
UINT8 *source;
|
||||
INT32 topdelta, prevdelta = -1;
|
||||
|
||||
// for writing a pixel to dest
|
||||
RGBA_t colortemp;
|
||||
UINT8 alpha;
|
||||
UINT8 *block = mipmap->grInfo.data;
|
||||
UINT8 texel;
|
||||
UINT16 texelu16;
|
||||
|
||||
if (!ptexturewidth)
|
||||
return;
|
||||
|
||||
x1 = originx;
|
||||
x2 = x1 + SHORT(realpatch->width);
|
||||
|
||||
if (x1 > ptexturewidth || x2 < 0)
|
||||
return; // patch not located within texture's x bounds, ignore
|
||||
|
||||
if (originy > ptextureheight || (originy + SHORT(realpatch->height)) < 0)
|
||||
return; // patch not located within texture's y bounds, ignore
|
||||
|
||||
// patch is actually inside the texture!
|
||||
// now check if texture is partly off-screen and adjust accordingly
|
||||
|
||||
// left edge
|
||||
if (x1 < 0)
|
||||
x = 0;
|
||||
else
|
||||
x = x1;
|
||||
|
||||
// right edge
|
||||
if (x2 > ptexturewidth)
|
||||
x2 = ptexturewidth;
|
||||
|
||||
|
||||
col = x * pblockwidth / ptexturewidth;
|
||||
ncols = ((x2 - x) * pblockwidth) / ptexturewidth;
|
||||
|
||||
/*
|
||||
CONS_Debug(DBG_RENDER, "patch %dx%d texture %dx%d block %dx%d\n", SHORT(realpatch->width),
|
||||
SHORT(realpatch->height),
|
||||
ptexturewidth,
|
||||
textureheight,
|
||||
pblockwidth,pblockheight);
|
||||
CONS_Debug(DBG_RENDER, " col %d ncols %d x %d\n", col, ncols, x);
|
||||
*/
|
||||
|
||||
// source advance
|
||||
xfrac = 0;
|
||||
if (x1 < 0)
|
||||
xfrac = -x1<<FRACBITS;
|
||||
|
||||
xfracstep = (ptexturewidth << FRACBITS) / pblockwidth;
|
||||
yfracstep = (ptextureheight<< FRACBITS) / pblockheight;
|
||||
if (bpp < 1 || bpp > 4)
|
||||
I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp);
|
||||
|
||||
for (block += col*bpp; ncols--; block += bpp, xfrac += xfracstep)
|
||||
{
|
||||
INT32 topdelta, prevdelta = -1;
|
||||
patchcol = (const column_t *)((const UINT8 *)realpatch
|
||||
+ LONG(realpatch->columnofs[xfrac>>FRACBITS]));
|
||||
|
||||
scale_y = (pblockheight << FRACBITS) / ptextureheight;
|
||||
|
||||
while (patchcol->topdelta != 0xff)
|
||||
{
|
||||
topdelta = patchcol->topdelta;
|
||||
if (topdelta <= prevdelta)
|
||||
topdelta += prevdelta;
|
||||
prevdelta = topdelta;
|
||||
source = (const UINT8 *)patchcol + 3;
|
||||
source = (UINT8 *)patchcol + 3;
|
||||
count = ((patchcol->length * scale_y) + (FRACUNIT/2)) >> FRACBITS;
|
||||
position = originy + topdelta;
|
||||
|
||||
|
@ -187,9 +132,86 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
|
|||
dest += blockmodulo;
|
||||
yfrac += yfracstep;
|
||||
}
|
||||
patchcol = (const column_t *)((const UINT8 *)patchcol + patchcol->length + 4);
|
||||
patchcol = (column_t *)((UINT8 *)patchcol + patchcol->length + 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// sprite, use alpha and chroma key for hole
|
||||
static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
|
||||
INT32 pblockwidth, INT32 pblockheight, INT32 blockmodulo,
|
||||
INT32 ptexturewidth, INT32 ptextureheight,
|
||||
INT32 originx, INT32 originy, // where to draw patch in surface block
|
||||
patch_t *realpatch, INT32 bpp)
|
||||
{
|
||||
INT32 x, x1, x2;
|
||||
INT32 col, ncols;
|
||||
fixed_t xfrac, xfracstep;
|
||||
column_t *patchcol;
|
||||
UINT8 *block = mipmap->grInfo.data;
|
||||
|
||||
if (!ptexturewidth)
|
||||
return;
|
||||
|
||||
x1 = originx;
|
||||
x2 = x1 + SHORT(realpatch->width);
|
||||
|
||||
if (x1 > ptexturewidth || x2 < 0)
|
||||
return; // patch not located within texture's x bounds, ignore
|
||||
|
||||
if (originy > ptextureheight || (originy + SHORT(realpatch->height)) < 0)
|
||||
return; // patch not located within texture's y bounds, ignore
|
||||
|
||||
// patch is actually inside the texture!
|
||||
// now check if texture is partly off-screen and adjust accordingly
|
||||
|
||||
// left edge
|
||||
if (x1 < 0)
|
||||
x = 0;
|
||||
else
|
||||
x = x1;
|
||||
|
||||
// right edge
|
||||
if (x2 > ptexturewidth)
|
||||
x2 = ptexturewidth;
|
||||
|
||||
|
||||
col = x * pblockwidth / ptexturewidth;
|
||||
ncols = ((x2 - x) * pblockwidth) / ptexturewidth;
|
||||
|
||||
/*
|
||||
CONS_Debug(DBG_RENDER, "patch %dx%d texture %dx%d block %dx%d\n", SHORT(realpatch->width),
|
||||
SHORT(realpatch->height),
|
||||
ptexturewidth,
|
||||
textureheight,
|
||||
pblockwidth,pblockheight);
|
||||
CONS_Debug(DBG_RENDER, " col %d ncols %d x %d\n", col, ncols, x);
|
||||
*/
|
||||
|
||||
// source advance
|
||||
xfrac = 0;
|
||||
if (x1 < 0)
|
||||
xfrac = -x1<<FRACBITS;
|
||||
|
||||
xfracstep = (ptexturewidth << FRACBITS) / pblockwidth;
|
||||
yfracstep = (ptextureheight<< FRACBITS) / pblockheight;
|
||||
scale_y = (pblockheight << FRACBITS) / ptextureheight;
|
||||
|
||||
if (bpp < 1 || bpp > 4)
|
||||
I_Error("HWR_DrawPatchInCache: no drawer defined for this bpp (%d)\n",bpp);
|
||||
|
||||
// Draw each column to the block cache
|
||||
for (block += col*bpp; ncols--; block += bpp, xfrac += xfracstep)
|
||||
{
|
||||
patchcol = (column_t *)((UINT8 *)realpatch + LONG(realpatch->columnofs[xfrac>>FRACBITS]));
|
||||
|
||||
HWR_DrawColumnInCache(patchcol, block, mipmap,
|
||||
pblockwidth, ptextureheight, blockmodulo,
|
||||
yfracstep, scale_y,
|
||||
originy,
|
||||
bpp
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue