use one function for any mip levels

This commit is contained in:
Denis Pauk 2018-04-06 00:21:53 +03:00
parent cd6c686980
commit 14c934762d
2 changed files with 13 additions and 176 deletions

View File

@ -56,11 +56,11 @@ D_ViewChanged (void)
d_zwidth = vid.width;
d_pix_min = r_refdef.vrect.width / 320;
d_pix_min = r_refdef.vrect.height / 240;
if (d_pix_min < 1)
d_pix_min = 1;
d_pix_max = (int)((float)r_refdef.vrect.width / (320.0 / 4.0) + 0.5);
d_pix_max = (int)((float)r_refdef.vrect.height / (240.0 / 4.0) + 0.5);
if (d_pix_max < 1)
d_pix_max = 1;

View File

@ -33,18 +33,7 @@ static int r_numhblocks, r_numvblocks;
static unsigned char *r_source, *r_sourcemax;
static unsigned *r_lightptr;
static void R_DrawSurfaceBlock8_mip0 (void);
static void R_DrawSurfaceBlock8_mip1 (void);
static void R_DrawSurfaceBlock8_mip2 (void);
static void R_DrawSurfaceBlock8_mip3 (void);
static void (*surfmiptable[4])(void) = {
R_DrawSurfaceBlock8_mip0,
R_DrawSurfaceBlock8_mip1,
R_DrawSurfaceBlock8_mip2,
R_DrawSurfaceBlock8_mip3
};
static void R_DrawSurfaceBlock8_anymip (int level);
void R_BuildLightMap (void);
extern unsigned blocklights[1024]; // allow some very large lightmaps
@ -93,7 +82,6 @@ static void R_DrawSurface (void)
int soffset, basetoffset, texwidth;
int horzblockstep;
unsigned char *pcolumndest;
void (*pblockdrawer)(void);
image_t *mt;
surfrowbytes = r_drawsurf.rowbytes;
@ -117,7 +105,6 @@ static void R_DrawSurface (void)
//==============================
pblockdrawer = surfmiptable[r_drawsurf.surfmip];
// TODO: only needs to be set when there is a display settings change
horzblockstep = blocksize;
@ -147,7 +134,7 @@ static void R_DrawSurface (void)
pbasesource = basetptr + soffset;
(*pblockdrawer)();
R_DrawSurfaceBlock8_anymip(4-r_drawsurf.surfmip);
soffset = soffset + blocksize;
if (soffset >= smax)
@ -162,14 +149,15 @@ static void R_DrawSurface (void)
/*
================
R_DrawSurfaceBlock8_mip0
R_DrawSurfaceBlock8_anymip
================
*/
static void R_DrawSurfaceBlock8_mip0 (void)
static void R_DrawSurfaceBlock8_anymip (int level)
{
int v, i, b, lightstep, lighttemp, light;
int v, i, b, lightstep, lighttemp, light, size;
unsigned char pix, *psource, *prowdest;
size = 1 << level;
psource = pbasesource;
prowdest = prowdestbase;
@ -180,17 +168,17 @@ static void R_DrawSurfaceBlock8_mip0 (void)
lightleft = r_lightptr[0];
lightright = r_lightptr[1];
r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> 4;
lightrightstep = (r_lightptr[1] - lightright) >> 4;
lightleftstep = (r_lightptr[0] - lightleft) >> level;
lightrightstep = (r_lightptr[1] - lightright) >> level;
for (i=0 ; i<16 ; i++)
for (i=0 ; i<size ; i++)
{
lighttemp = lightleft - lightright;
lightstep = lighttemp >> 4;
lightstep = lighttemp >> level;
light = lightright;
for (b=15; b>=0; b--)
for (b=(size-1); b>=0; b--)
{
pix = psource[b];
prowdest[b] = ((unsigned char *)vid_colormap)
@ -209,157 +197,6 @@ static void R_DrawSurfaceBlock8_mip0 (void)
}
}
/*
================
R_DrawSurfaceBlock8_mip1
================
*/
static void R_DrawSurfaceBlock8_mip1 (void)
{
int v, i, b, lightstep, lighttemp, light;
unsigned char pix, *psource, *prowdest;
psource = pbasesource;
prowdest = prowdestbase;
for (v=0 ; v<r_numvblocks ; v++)
{
// FIXME: make these locals?
// FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[0];
lightright = r_lightptr[1];
r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> 3;
lightrightstep = (r_lightptr[1] - lightright) >> 3;
for (i=0 ; i<8 ; i++)
{
lighttemp = lightleft - lightright;
lightstep = lighttemp >> 3;
light = lightright;
for (b=7; b>=0; b--)
{
pix = psource[b];
prowdest[b] = ((unsigned char *)vid_colormap)
[(light & 0xFF00) + pix];
light += lightstep;
}
psource += sourcetstep;
lightright += lightrightstep;
lightleft += lightleftstep;
prowdest += surfrowbytes;
}
if (psource >= r_sourcemax)
psource -= r_stepback;
}
}
/*
================
R_DrawSurfaceBlock8_mip2
================
*/
static void R_DrawSurfaceBlock8_mip2 (void)
{
int v, i, b, lightstep, lighttemp, light;
unsigned char pix, *psource, *prowdest;
psource = pbasesource;
prowdest = prowdestbase;
for (v=0 ; v<r_numvblocks ; v++)
{
// FIXME: make these locals?
// FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[0];
lightright = r_lightptr[1];
r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> 2;
lightrightstep = (r_lightptr[1] - lightright) >> 2;
for (i=0 ; i<4 ; i++)
{
lighttemp = lightleft - lightright;
lightstep = lighttemp >> 2;
light = lightright;
for (b=3; b>=0; b--)
{
pix = psource[b];
prowdest[b] = ((unsigned char *)vid_colormap)
[(light & 0xFF00) + pix];
light += lightstep;
}
psource += sourcetstep;
lightright += lightrightstep;
lightleft += lightleftstep;
prowdest += surfrowbytes;
}
if (psource >= r_sourcemax)
psource -= r_stepback;
}
}
/*
================
R_DrawSurfaceBlock8_mip3
================
*/
static void R_DrawSurfaceBlock8_mip3 (void)
{
int v, i, b, lightstep, lighttemp, light;
unsigned char pix, *psource, *prowdest;
psource = pbasesource;
prowdest = prowdestbase;
for (v=0 ; v<r_numvblocks ; v++)
{
// FIXME: make these locals?
// FIXME: use delta rather than both right and left, like ASM?
lightleft = r_lightptr[0];
lightright = r_lightptr[1];
r_lightptr += r_lightwidth;
lightleftstep = (r_lightptr[0] - lightleft) >> 1;
lightrightstep = (r_lightptr[1] - lightright) >> 1;
for (i=0 ; i<2 ; i++)
{
lighttemp = lightleft - lightright;
lightstep = lighttemp >> 1;
light = lightright;
for (b=1; b>=0; b--)
{
pix = psource[b];
prowdest[b] = ((unsigned char *)vid_colormap)
[(light & 0xFF00) + pix];
light += lightstep;
}
psource += sourcetstep;
lightright += lightrightstep;
lightleft += lightleftstep;
prowdest += surfrowbytes;
}
if (psource >= r_sourcemax)
psource -= r_stepback;
}
}
//============================================================================