Skip to content

Commit

Permalink
use one function for any mip levels
Browse files Browse the repository at this point in the history
  • Loading branch information
0lvin committed Apr 10, 2018
1 parent cd6c686 commit 14c9347
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 176 deletions.
4 changes: 2 additions & 2 deletions src/client/refresh/soft/sw_misc.c
Expand Up @@ -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;

Expand Down
185 changes: 11 additions & 174 deletions src/client/refresh/soft/sw_surf.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand All @@ -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;

Expand All @@ -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)
Expand All @@ -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;
}
}


//============================================================================


Expand Down

0 comments on commit 14c9347

Please sign in to comment.