Added bilinear filtering
This commit is contained in:
parent
6daeb5a158
commit
c70aa1fe99
5 changed files with 241 additions and 61 deletions
|
|
@ -58,6 +58,7 @@ extern float rw_lightstep;
|
|||
extern int wallshade;
|
||||
|
||||
CVAR(Bool, r_multithreaded, true, 0)
|
||||
CVAR(Bool, r_bilinear, false, 0)
|
||||
|
||||
#ifndef NO_SSE
|
||||
|
||||
|
|
@ -1547,41 +1548,72 @@ public:
|
|||
uint32_t light = calc_light_multiplier(_light);
|
||||
ShadeConstants shade_constants = _shade_constants;
|
||||
|
||||
if (_xbits == 6 && _ybits == 6)
|
||||
fixed_t xmagnitude = abs((fixed_t)xstep) >> (32 - _xbits - FRACBITS);
|
||||
fixed_t ymagnitude = abs((fixed_t)ystep) >> (32 - _ybits - FRACBITS);
|
||||
fixed_t magnitude = xmagnitude + ymagnitude;
|
||||
|
||||
bool magnifying = !r_bilinear || magnitude >> (FRACBITS - 1) == 0;
|
||||
if (magnifying)
|
||||
{
|
||||
// 64x64 is the most common case by far, so special case it.
|
||||
|
||||
do
|
||||
if (_xbits == 6 && _ybits == 6)
|
||||
{
|
||||
// Current texture index in u,v.
|
||||
spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6));
|
||||
// 64x64 is the most common case by far, so special case it.
|
||||
|
||||
// Lookup pixel from flat texture tile
|
||||
*dest++ = shade_bgra(source[spot], light, shade_constants);
|
||||
do
|
||||
{
|
||||
// Current texture index in u,v.
|
||||
spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6));
|
||||
|
||||
// Next step in u,v.
|
||||
xfrac += xstep;
|
||||
yfrac += ystep;
|
||||
} while (--count);
|
||||
// Lookup pixel from flat texture tile
|
||||
*dest++ = shade_bgra(source[spot], light, shade_constants);
|
||||
|
||||
// Next step in u,v.
|
||||
xfrac += xstep;
|
||||
yfrac += ystep;
|
||||
} while (--count);
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE yshift = 32 - _ybits;
|
||||
BYTE xshift = yshift - _xbits;
|
||||
int xmask = ((1 << _xbits) - 1) << _ybits;
|
||||
|
||||
do
|
||||
{
|
||||
// Current texture index in u,v.
|
||||
spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift);
|
||||
|
||||
// Lookup pixel from flat texture tile
|
||||
*dest++ = shade_bgra(source[spot], light, shade_constants);
|
||||
|
||||
// Next step in u,v.
|
||||
xfrac += xstep;
|
||||
yfrac += ystep;
|
||||
} while (--count);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE yshift = 32 - _ybits;
|
||||
BYTE xshift = yshift - _xbits;
|
||||
int xmask = ((1 << _xbits) - 1) << _ybits;
|
||||
|
||||
do
|
||||
if (_xbits == 6 && _ybits == 6)
|
||||
{
|
||||
// Current texture index in u,v.
|
||||
spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift);
|
||||
// 64x64 is the most common case by far, so special case it.
|
||||
|
||||
// Lookup pixel from flat texture tile
|
||||
*dest++ = shade_bgra(source[spot], light, shade_constants);
|
||||
|
||||
// Next step in u,v.
|
||||
xfrac += xstep;
|
||||
yfrac += ystep;
|
||||
} while (--count);
|
||||
do
|
||||
{
|
||||
*dest++ = shade_bgra(sample_bilinear(source, xfrac, yfrac, 26, 26), light, shade_constants);
|
||||
xfrac += xstep;
|
||||
yfrac += ystep;
|
||||
} while (--count);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
*dest++ = shade_bgra(sample_bilinear(source, xfrac, yfrac, 32 - _xbits, 32 - _ybits), light, shade_constants);
|
||||
xfrac += xstep;
|
||||
yfrac += ystep;
|
||||
} while (--count);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -2253,6 +2285,8 @@ class Vlinec1RGBACommand : public DrawerCommand
|
|||
DWORD _texturefrac;
|
||||
int _count;
|
||||
const BYTE * RESTRICT _source;
|
||||
const BYTE * RESTRICT _source2;
|
||||
uint32_t _texturefracx;
|
||||
BYTE * RESTRICT _dest;
|
||||
int vlinebits;
|
||||
int _pitch;
|
||||
|
|
@ -2266,6 +2300,8 @@ public:
|
|||
_texturefrac = dc_texturefrac;
|
||||
_count = dc_count;
|
||||
_source = dc_source;
|
||||
_source2 = dc_source2;
|
||||
_texturefracx = dc_texturefracx;
|
||||
_dest = dc_dest;
|
||||
vlinebits = ::vlinebits;
|
||||
_pitch = dc_pitch;
|
||||
|
|
@ -2282,6 +2318,8 @@ public:
|
|||
DWORD fracstep = _iscale * thread->num_cores;
|
||||
DWORD frac = _texturefrac + _iscale * thread->skipped_by_thread(_dest_y);
|
||||
const uint32 *source = (const uint32 *)_source;
|
||||
const uint32 *source2 = (const uint32 *)_source2;
|
||||
uint32_t texturefracx = _texturefracx;
|
||||
uint32_t *dest = thread->dest_for_thread(_dest_y, _pitch, (uint32_t*)_dest);
|
||||
int bits = vlinebits;
|
||||
int pitch = _pitch * thread->num_cores;
|
||||
|
|
@ -2289,12 +2327,24 @@ public:
|
|||
uint32_t light = calc_light_multiplier(_light);
|
||||
ShadeConstants shade_constants = _shade_constants;
|
||||
|
||||
do
|
||||
if (_source2 == nullptr)
|
||||
{
|
||||
*dest = shade_bgra(source[frac >> bits], light, shade_constants);
|
||||
frac += fracstep;
|
||||
dest += pitch;
|
||||
} while (--count);
|
||||
do
|
||||
{
|
||||
*dest = shade_bgra(source[frac >> bits], light, shade_constants);
|
||||
frac += fracstep;
|
||||
dest += pitch;
|
||||
} while (--count);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
*dest = shade_bgra(sample_bilinear(source, source2, texturefracx, frac, bits), light, shade_constants);
|
||||
frac += fracstep;
|
||||
dest += pitch;
|
||||
} while (--count);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -2308,7 +2358,9 @@ class Vlinec4RGBACommand : public DrawerCommand
|
|||
fixed_t palookuplight[4];
|
||||
DWORD vplce[4];
|
||||
DWORD vince[4];
|
||||
const uint32 * RESTRICT bufplce[4];
|
||||
const uint32_t * RESTRICT bufplce[4];
|
||||
const uint32_t * RESTRICT bufplce2[4];
|
||||
uint32_t buftexturefracx[4];
|
||||
|
||||
public:
|
||||
Vlinec4RGBACommand()
|
||||
|
|
@ -2323,7 +2375,9 @@ public:
|
|||
palookuplight[i] = ::palookuplight[i];
|
||||
vplce[i] = ::vplce[i];
|
||||
vince[i] = ::vince[i];
|
||||
bufplce[i] = (const uint32 *)::bufplce[i];
|
||||
bufplce[i] = (const uint32_t *)::bufplce[i];
|
||||
bufplce2[i] = (const uint32_t *)::bufplce2[i];
|
||||
buftexturefracx[i] = ::buftexturefracx[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2354,14 +2408,28 @@ public:
|
|||
local_vince[i] *= thread->num_cores;
|
||||
}
|
||||
|
||||
do
|
||||
if (bufplce2[0] == nullptr)
|
||||
{
|
||||
dest[0] = shade_bgra(bufplce[0][(place = local_vplce[0]) >> bits], light0, shade_constants); local_vplce[0] = place + local_vince[0];
|
||||
dest[1] = shade_bgra(bufplce[1][(place = local_vplce[1]) >> bits], light1, shade_constants); local_vplce[1] = place + local_vince[1];
|
||||
dest[2] = shade_bgra(bufplce[2][(place = local_vplce[2]) >> bits], light2, shade_constants); local_vplce[2] = place + local_vince[2];
|
||||
dest[3] = shade_bgra(bufplce[3][(place = local_vplce[3]) >> bits], light3, shade_constants); local_vplce[3] = place + local_vince[3];
|
||||
dest += pitch;
|
||||
} while (--count);
|
||||
do
|
||||
{
|
||||
dest[0] = shade_bgra(bufplce[0][(place = local_vplce[0]) >> bits], light0, shade_constants); local_vplce[0] = place + local_vince[0];
|
||||
dest[1] = shade_bgra(bufplce[1][(place = local_vplce[1]) >> bits], light1, shade_constants); local_vplce[1] = place + local_vince[1];
|
||||
dest[2] = shade_bgra(bufplce[2][(place = local_vplce[2]) >> bits], light2, shade_constants); local_vplce[2] = place + local_vince[2];
|
||||
dest[3] = shade_bgra(bufplce[3][(place = local_vplce[3]) >> bits], light3, shade_constants); local_vplce[3] = place + local_vince[3];
|
||||
dest += pitch;
|
||||
} while (--count);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
dest[0] = shade_bgra(sample_bilinear(bufplce[0], bufplce2[0], buftexturefracx[0], place = local_vplce[0], bits), light0, shade_constants); local_vplce[0] = place + local_vince[0];
|
||||
dest[1] = shade_bgra(sample_bilinear(bufplce[1], bufplce2[1], buftexturefracx[1], place = local_vplce[1], bits), light1, shade_constants); local_vplce[1] = place + local_vince[1];
|
||||
dest[2] = shade_bgra(sample_bilinear(bufplce[2], bufplce2[2], buftexturefracx[2], place = local_vplce[2], bits), light2, shade_constants); local_vplce[2] = place + local_vince[2];
|
||||
dest[3] = shade_bgra(sample_bilinear(bufplce[3], bufplce2[3], buftexturefracx[3], place = local_vplce[3], bits), light3, shade_constants); local_vplce[3] = place + local_vince[3];
|
||||
dest += pitch;
|
||||
} while (--count);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -3651,7 +3719,10 @@ void R_DrawSpan_rgba()
|
|||
#ifdef NO_SSE
|
||||
DrawerCommandQueue::QueueCommand<DrawSpanRGBACommand>();
|
||||
#else
|
||||
DrawerCommandQueue::QueueCommand<DrawSpanRGBA_SSE_Command>();
|
||||
if (!r_bilinear)
|
||||
DrawerCommandQueue::QueueCommand<DrawSpanRGBA_SSE_Command>();
|
||||
else
|
||||
DrawerCommandQueue::QueueCommand<DrawSpanRGBACommand>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -3705,7 +3776,10 @@ void vlinec4_rgba()
|
|||
#ifdef NO_SSE
|
||||
DrawerCommandQueue::QueueCommand<Vlinec4RGBACommand>();
|
||||
#else
|
||||
DrawerCommandQueue::QueueCommand<Vlinec4RGBA_SSE_Command>();
|
||||
if (!r_bilinear)
|
||||
DrawerCommandQueue::QueueCommand<Vlinec4RGBA_SSE_Command>();
|
||||
else
|
||||
DrawerCommandQueue::QueueCommand<Vlinec4RGBACommand>();
|
||||
#endif
|
||||
for (int i = 0; i < 4; i++)
|
||||
vplce[i] += vince[i] * dc_count;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue