Voxel support in true color mode

This commit is contained in:
Magnus Norddahl 2016-06-22 00:22:06 +02:00
parent f81042b3e2
commit e294906d69
6 changed files with 171 additions and 13 deletions

View file

@ -100,6 +100,8 @@ void (*R_DrawFogBoundary)(int x1, int x2, short *uclip, short *dclip);
void (*R_MapTiltedPlane)(int y, int x1);
void (*R_MapColoredPlane)(int y, int x1);
void (*R_DrawParticle)(vissprite_t *);
void (*R_SetupDrawSlab)(FColormap *base_colormap, float light, int shade);
void (*R_DrawSlab)(int dx, fixed_t v, int dy, fixed_t vi, const BYTE *vptr, BYTE *p);
fixed_t (*tmvline1_add)();
void (*tmvline4_add)();
fixed_t (*tmvline1_addclamp)();
@ -2306,6 +2308,9 @@ void R_InitColumnDrawers ()
R_MapColoredPlane = R_MapColoredPlane_rgba;
R_DrawParticle = R_DrawParticle_rgba;
R_SetupDrawSlab = R_SetupDrawSlab_rgba;
R_DrawSlab = R_DrawSlab_rgba;
tmvline1_add = tmvline1_add_rgba;
tmvline4_add = tmvline4_add_rgba;
tmvline1_addclamp = tmvline1_addclamp_rgba;
@ -2403,6 +2408,14 @@ void R_InitColumnDrawers ()
R_MapColoredPlane = R_MapColoredPlane_C;
R_DrawParticle = R_DrawParticle_C;
#ifdef X86_ASM
R_SetupDrawSlab = [](FColormap *colormap, float light, int shade) { R_SetupDrawSlabA(colormap->Maps + (GETPALOOKUP(light, shade) << COLORMAPSHIFT)); };
R_DrawSlab = R_DrawSlabA;
#else
R_SetupDrawSlab = [](FColormap *colormap, float light, int shade) { R_SetupDrawSlabC(colormap->Maps + (GETPALOOKUP(light, shade) << COLORMAPSHIFT)); };
R_DrawSlab = R_DrawSlabC;
#endif
tmvline1_add = tmvline1_add_C;
tmvline4_add = tmvline4_add_C;
tmvline1_addclamp = tmvline1_addclamp_C;

View file

@ -286,16 +286,16 @@ void R_FillColumnP_C (void);
void R_FillColumnHorizP_C (void);
void R_FillSpan_C (void);
#ifdef X86_ASM
#define R_SetupDrawSlab R_SetupDrawSlabA
#define R_DrawSlab R_DrawSlabA
#else
#define R_SetupDrawSlab R_SetupDrawSlabC
#define R_DrawSlab R_DrawSlabC
#endif
extern void(*R_SetupDrawSlab)(FColormap *base_colormap, float light, int shade);
extern void(*R_DrawSlab)(int dx, fixed_t v, int dy, fixed_t vi, const BYTE *vptr, BYTE *p);
extern "C" void R_SetupDrawSlab(const BYTE *colormap);
extern "C" void R_DrawSlab(int dx, fixed_t v, int dy, fixed_t vi, const BYTE *vptr, BYTE *p);
#ifdef X86_ASM
extern "C" void R_SetupDrawSlabA(const BYTE *colormap);
extern "C" void R_DrawSlabA(int dx, fixed_t v, int dy, fixed_t vi, const BYTE *vptr, BYTE *p);
#else
extern "C" void R_SetupDrawSlabC(const BYTE *colormap);
extern "C" void R_DrawSlabC(int dx, fixed_t v, int dy, fixed_t vi, const BYTE *vptr, BYTE *p);
#endif
extern "C" int ds_y;
extern "C" int ds_x1;

View file

@ -2303,6 +2303,123 @@ public:
}
};
class DrawSlabRGBACommand : public DrawerCommand
{
int _dx;
fixed_t _v;
int _dy;
fixed_t _vi;
const BYTE *_vptr;
uint32_t *_p;
ShadeConstants _shade_constants;
const BYTE *_colormap;
fixed_t _light;
int _pitch;
int _start_y;
public:
DrawSlabRGBACommand(int dx, fixed_t v, int dy, fixed_t vi, const BYTE *vptr, BYTE *p, ShadeConstants shade_constants, const BYTE *colormap, fixed_t light)
{
_dx = dx;
_v = v;
_dy = dy;
_vi = vi;
_vptr = vptr;
_p = (uint32_t *)p;
_shade_constants = shade_constants;
_colormap = colormap;
_light = light;
_pitch = dc_pitch;
_start_y = static_cast<int>((p - dc_destorg) / (dc_pitch * 4));
assert(dx > 0);
}
void Execute(DrawerThread *thread) override
{
int dx = _dx;
fixed_t v = _v;
int dy = _dy;
fixed_t vi = _vi;
const BYTE *vptr = _vptr;
uint32_t *p = _p;
ShadeConstants shade_constants = _shade_constants;
const BYTE *colormap = _colormap;
uint32_t light = calc_light_multiplier(_light);
int pitch = _pitch;
int x;
dy = thread->count_for_thread(_start_y, dy);
p = thread->dest_for_thread(_start_y, pitch, p);
v += vi * thread->skipped_by_thread(_start_y);
vi *= thread->num_cores;
pitch *= thread->num_cores;
if (dx == 1)
{
while (dy > 0)
{
*p = shade_pal_index(colormap[vptr[v >> FRACBITS]], light, shade_constants);
p += pitch;
v += vi;
dy--;
}
}
else if (dx == 2)
{
while (dy > 0)
{
uint32_t color = shade_pal_index(colormap[vptr[v >> FRACBITS]], light, shade_constants);
p[0] = color;
p[1] = color;
p += pitch;
v += vi;
dy--;
}
}
else if (dx == 3)
{
while (dy > 0)
{
uint32_t color = shade_pal_index(colormap[vptr[v >> FRACBITS]], light, shade_constants);
p[0] = color;
p[1] = color;
p[2] = color;
p += pitch;
v += vi;
dy--;
}
}
else if (dx == 4)
{
while (dy > 0)
{
uint32_t color = shade_pal_index(colormap[vptr[v >> FRACBITS]], light, shade_constants);
p[0] = color;
p[1] = color;
p[2] = color;
p[3] = color;
p += pitch;
v += vi;
dy--;
}
}
else while (dy > 0)
{
uint32_t color = shade_pal_index(colormap[vptr[v >> FRACBITS]], light, shade_constants);
// The optimizer will probably turn this into a memset call.
// Since dx is not likely to be large, I'm not sure that's a good thing,
// hence the alternatives above.
for (x = 0; x < dx; x++)
{
p[x] = color;
}
p += pitch;
v += vi;
dy--;
}
}
};
class Vlinec1RGBACommand : public DrawerCommand
{
DWORD _iscale;
@ -3813,6 +3930,31 @@ void R_FillSpan_rgba()
DrawerCommandQueue::QueueCommand<FillSpanRGBACommand>();
}
static ShadeConstants slab_rgba_shade_constants;
static const BYTE *slab_rgba_colormap;
static fixed_t slab_rgba_light;
void R_SetupDrawSlab_rgba(FColormap *base_colormap, float light, int shade)
{
slab_rgba_shade_constants.light_red = base_colormap->Color.r * 256 / 255;
slab_rgba_shade_constants.light_green = base_colormap->Color.g * 256 / 255;
slab_rgba_shade_constants.light_blue = base_colormap->Color.b * 256 / 255;
slab_rgba_shade_constants.light_alpha = base_colormap->Color.a * 256 / 255;
slab_rgba_shade_constants.fade_red = base_colormap->Fade.r;
slab_rgba_shade_constants.fade_green = base_colormap->Fade.g;
slab_rgba_shade_constants.fade_blue = base_colormap->Fade.b;
slab_rgba_shade_constants.fade_alpha = base_colormap->Fade.a;
slab_rgba_shade_constants.desaturate = MIN(abs(base_colormap->Desaturate), 255) * 255 / 256;
slab_rgba_shade_constants.simple_shade = (base_colormap->Color.d == 0x00ffffff && base_colormap->Fade.d == 0x00000000 && base_colormap->Desaturate == 0);
slab_rgba_colormap = base_colormap->Maps;
slab_rgba_light = LIGHTSCALE(light, shade);
}
void R_DrawSlab_rgba(int dx, fixed_t v, int dy, fixed_t vi, const BYTE *vptr, BYTE *p)
{
DrawerCommandQueue::QueueCommand<DrawSlabRGBACommand>(dx, v, dy, vi, vptr, p, slab_rgba_shade_constants, slab_rgba_colormap, slab_rgba_light);
}
//extern FTexture *rw_pic; // For the asserts below
DWORD vlinec1_rgba()

View file

@ -90,6 +90,9 @@ void R_DrawSpanAddClamp_rgba();
void R_DrawSpanMaskedAddClamp_rgba();
void R_FillSpan_rgba();
void R_SetupDrawSlab_rgba(FColormap *base_colormap, float light, int shade);
void R_DrawSlab_rgba(int dx, fixed_t v, int dy, fixed_t vi, const BYTE *vptr, BYTE *p);
void R_DrawFogBoundary_rgba(int x1, int x2, short *uclip, short *dclip);
DWORD vlinec1_rgba();

View file

@ -688,7 +688,7 @@ void R_DrawVisVoxel(vissprite_t *spr, int minslabz, int maxslabz, short *cliptop
// Render the voxel, either directly to the screen or offscreen.
R_DrawVoxel(spr->pa.vpos, spr->pa.vang, spr->gpos, spr->Angle,
spr->xscale, FLOAT2FIXED(spr->yscale), spr->voxel, spr->Style.BaseColormap->Maps + (spr->Style.ColormapNum << COLORMAPSHIFT), cliptop, clipbot,
spr->xscale, FLOAT2FIXED(spr->yscale), spr->voxel, spr->Style.BaseColormap, spr->Style.ColormapNum, cliptop, clipbot,
minslabz, maxslabz, flags);
// Blend the voxel, if that's what we need to do.
@ -2775,7 +2775,7 @@ extern double BaseYaspectMul;;
void R_DrawVoxel(const FVector3 &globalpos, FAngle viewangle,
const FVector3 &dasprpos, DAngle dasprang,
fixed_t daxscale, fixed_t dayscale, FVoxel *voxobj,
lighttable_t *colormap, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags)
FColormap *colormap, int colormapnum, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags)
{
int i, j, k, x, y, syoff, ggxstart, ggystart, nxoff;
fixed_t cosang, sinang, sprcosang, sprsinang;
@ -2812,7 +2812,7 @@ void R_DrawVoxel(const FVector3 &globalpos, FAngle viewangle,
sprcosang = FLOAT2FIXED(dasprang.Cos()) >> 2;
sprsinang = FLOAT2FIXED(-dasprang.Sin()) >> 2;
R_SetupDrawSlab(colormap);
R_SetupDrawSlab(colormap, 0.0f, colormapnum << FRACBITS);
int pixelsize = r_swtruecolor ? 4 : 1;

View file

@ -144,7 +144,7 @@ enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 };
void R_DrawVoxel(const FVector3 &viewpos, FAngle viewangle,
const FVector3 &sprpos, DAngle dasprang,
fixed_t daxscale, fixed_t dayscale, struct FVoxel *voxobj,
lighttable_t *colormap, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags);
FColormap *colormap, int colormapnum, short *daumost, short *dadmost, int minslabz, int maxslabz, int flags);
void R_ClipVisSprite (vissprite_t *vis, int xl, int xh);