Fixed fill column rgba drawers

This commit is contained in:
Magnus Norddahl 2016-06-17 12:38:00 +02:00
parent 35c078dc1e
commit f53e468f3f
3 changed files with 82 additions and 44 deletions

View file

@ -154,6 +154,7 @@ fixed_t dc_iscale;
fixed_t dc_texturefrac;
int dc_color; // [RH] Color for column filler
DWORD dc_srccolor;
uint32_t dc_srccolor_bgra;
DWORD *dc_srcblend; // [RH] Source and destination
DWORD *dc_destblend; // blending lookups
fixed_t dc_srcalpha; // Alpha value used by dc_srcblend
@ -2702,10 +2703,10 @@ ESPSResult R_SetPatchStyle (FRenderStyle style, fixed_t alpha, int translation,
if (style.Flags & STYLEF_ColorIsFixed)
{
int x = fglevel >> 10;
int r = RPART(color);
int g = GPART(color);
int b = BPART(color);
uint32_t x = fglevel >> 10;
uint32_t r = RPART(color);
uint32_t g = GPART(color);
uint32_t b = BPART(color);
// dc_color is used by the rt_* routines. It is indexed into dc_srcblend.
dc_color = RGB32k.RGB[r>>3][g>>3][b>>3];
if (style.Flags & STYLEF_InvertSource)
@ -2714,6 +2715,8 @@ ESPSResult R_SetPatchStyle (FRenderStyle style, fixed_t alpha, int translation,
g = 255 - g;
b = 255 - b;
}
uint32_t alpha = clamp(fglevel >> (FRACBITS - 8), 0, 255);
dc_srccolor_bgra = (alpha << 24) | (r << 16) | (g << 8) | b;
// dc_srccolor is used by the R_Fill* routines. It is premultiplied
// with the alpha.
dc_srccolor = ((((r*x)>>4)<<20) | ((g*x)>>4) | ((((b)*x)>>4)<<10)) & 0x3feffbff;

View file

@ -63,6 +63,7 @@ extern double dc_texturemid;
extern "C" fixed_t dc_texturefrac;
extern "C" int dc_color; // [RH] For flat colors (no texturing)
extern "C" DWORD dc_srccolor;
extern "C" uint32_t dc_srccolor_bgra;
extern "C" DWORD *dc_srcblend;
extern "C" DWORD *dc_destblend;
extern "C" fixed_t dc_srcalpha;

View file

@ -344,8 +344,7 @@ class FillAddColumnRGBACommand : public DrawerCommand
int _count;
BYTE *_dest;
int _pitch;
fixed_t _light;
int _color;
uint32_t _srccolor;
public:
FillAddColumnRGBACommand()
@ -353,8 +352,7 @@ public:
_count = dc_count;
_dest = dc_dest;
_pitch = dc_pitch;
_light = dc_light;
_color = dc_color;
_srccolor = dc_srccolor_bgra;
}
void Execute(DrawerThread *thread) override
@ -369,10 +367,18 @@ public:
dest = thread->dest_for_thread(_dest_y, _pitch, (uint32_t*)_dest);
int pitch = _pitch * thread->num_cores;
uint32_t fg = shade_pal_index_simple(_color, calc_light_multiplier(_light));
uint32_t fg_red = (fg >> 24) & 0xff;
uint32_t fg_green = (fg >> 16) & 0xff;
uint32_t fg = _srccolor;
uint32_t fg_red = (fg >> 16) & 0xff;
uint32_t fg_green = (fg >> 8) & 0xff;
uint32_t fg_blue = fg & 0xff;
uint32_t fg_alpha = fg >> 24;
fg_alpha += fg_alpha >> 7;
fg_red *= fg_alpha;
fg_green *= fg_alpha;
fg_blue *= fg_alpha;
uint32_t inv_alpha = 256 - fg_alpha;
do
{
@ -380,9 +386,9 @@ public:
uint32_t bg_green = (*dest >> 8) & 0xff;
uint32_t bg_blue = (*dest) & 0xff;
uint32_t red = (fg_red + bg_red + 1) / 2;
uint32_t green = (fg_green + bg_green + 1) / 2;
uint32_t blue = (fg_blue + bg_blue + 1) / 2;
uint32_t red = (fg_red + bg_red * inv_alpha) / 256;
uint32_t green = (fg_green + bg_green * inv_alpha) / 256;
uint32_t blue = (fg_blue + bg_blue * inv_alpha) / 256;
*dest = 0xff000000 | (red << 16) | (green << 8) | blue;
dest += pitch;
@ -395,8 +401,10 @@ class FillAddClampColumnRGBACommand : public DrawerCommand
int _count;
BYTE *_dest;
int _pitch;
fixed_t _light;
int _color;
uint32_t _srccolor;
fixed_t _srcalpha;
fixed_t _destalpha;
public:
FillAddClampColumnRGBACommand()
@ -404,8 +412,10 @@ public:
_count = dc_count;
_dest = dc_dest;
_pitch = dc_pitch;
_light = dc_light;
_color = dc_color;
_srccolor = dc_srccolor_bgra;
_srcalpha = dc_srcalpha;
_destalpha = dc_destalpha;
}
void Execute(DrawerThread *thread) override
@ -420,20 +430,26 @@ public:
dest = thread->dest_for_thread(_dest_y, _pitch, (uint32_t*)_dest);
int pitch = _pitch * thread->num_cores;
uint32_t fg = shade_pal_index_simple(_color, calc_light_multiplier(_light));
uint32_t fg_red = (fg >> 24) & 0xff;
uint32_t fg_green = (fg >> 16) & 0xff;
uint32_t fg = _srccolor;
uint32_t fg_red = (fg >> 16) & 0xff;
uint32_t fg_green = (fg >> 8) & 0xff;
uint32_t fg_blue = fg & 0xff;
uint32_t fg_alpha = _srcalpha >> (FRACBITS - 8);
uint32_t bg_alpha = _destalpha >> (FRACBITS - 8);
fg_red *= fg_alpha;
fg_green *= fg_alpha;
fg_blue *= fg_alpha;
do {
do
{
uint32_t bg_red = (*dest >> 16) & 0xff;
uint32_t bg_green = (*dest >> 8) & 0xff;
uint32_t bg_blue = (*dest) & 0xff;
uint32_t red = clamp<uint32_t>(fg_red + bg_red, 0, 255);
uint32_t green = clamp<uint32_t>(fg_green + bg_green, 0, 255);
uint32_t blue = clamp<uint32_t>(fg_blue + bg_blue, 0, 255);
uint32_t red = clamp<uint32_t>((fg_red + bg_red * bg_alpha) / 256, 0, 255);
uint32_t green = clamp<uint32_t>((fg_green + bg_green * bg_alpha) / 256, 0, 255);
uint32_t blue = clamp<uint32_t>((fg_blue + bg_blue * bg_alpha) / 256, 0, 255);
*dest = 0xff000000 | (red << 16) | (green << 8) | blue;
dest += pitch;
@ -447,7 +463,9 @@ class FillSubClampColumnRGBACommand : public DrawerCommand
BYTE *_dest;
int _pitch;
int _color;
fixed_t _light;
uint32_t _srccolor;
fixed_t _srcalpha;
fixed_t _destalpha;
public:
FillSubClampColumnRGBACommand()
@ -456,7 +474,9 @@ public:
_dest = dc_dest;
_pitch = dc_pitch;
_color = dc_color;
_light = dc_light;
_srccolor = dc_srccolor_bgra;
_srcalpha = dc_srcalpha;
_destalpha = dc_destalpha;
}
void Execute(DrawerThread *thread) override
@ -471,20 +491,25 @@ public:
dest = thread->dest_for_thread(_dest_y, _pitch, (uint32_t*)_dest);
int pitch = _pitch * thread->num_cores;
uint32_t fg = shade_pal_index_simple(_color, calc_light_multiplier(_light));
uint32_t fg_red = (fg >> 24) & 0xff;
uint32_t fg_green = (fg >> 16) & 0xff;
uint32_t fg = _srccolor;
uint32_t fg_red = (fg >> 16) & 0xff;
uint32_t fg_green = (fg >> 8) & 0xff;
uint32_t fg_blue = fg & 0xff;
uint32_t fg_alpha = _srcalpha >> (FRACBITS - 8);
uint32_t bg_alpha = _destalpha >> (FRACBITS - 8);
do
{
fg_red *= fg_alpha;
fg_green *= fg_alpha;
fg_blue *= fg_alpha;
do {
uint32_t bg_red = (*dest >> 16) & 0xff;
uint32_t bg_green = (*dest >> 8) & 0xff;
uint32_t bg_blue = (*dest) & 0xff;
uint32_t red = clamp<uint32_t>(256 - fg_red + bg_red, 256, 256 + 255) - 255;
uint32_t green = clamp<uint32_t>(256 - fg_green + bg_green, 256, 256 + 255) - 255;
uint32_t blue = clamp<uint32_t>(256 - fg_blue + bg_blue, 256, 256 + 255) - 255;
uint32_t red = clamp<uint32_t>((0x10000 - fg_red + bg_red * bg_alpha) / 256, 256, 256 + 255) - 256;
uint32_t green = clamp<uint32_t>((0x10000 - fg_green + bg_green * bg_alpha) / 256, 256, 256 + 255) - 256;
uint32_t blue = clamp<uint32_t>((0x10000 - fg_blue + bg_blue * bg_alpha) / 256, 256, 256 + 255) - 256;
*dest = 0xff000000 | (red << 16) | (green << 8) | blue;
dest += pitch;
@ -498,7 +523,9 @@ class FillRevSubClampColumnRGBACommand : public DrawerCommand
BYTE *_dest;
int _pitch;
int _color;
fixed_t _light;
uint32_t _srccolor;
fixed_t _srcalpha;
fixed_t _destalpha;
public:
FillRevSubClampColumnRGBACommand()
@ -507,7 +534,9 @@ public:
_dest = dc_dest;
_pitch = dc_pitch;
_color = dc_color;
_light = dc_light;
_srccolor = dc_srccolor_bgra;
_srcalpha = dc_srcalpha;
_destalpha = dc_destalpha;
}
void Execute(DrawerThread *thread) override
@ -522,20 +551,25 @@ public:
dest = thread->dest_for_thread(_dest_y, _pitch, (uint32_t*)_dest);
int pitch = _pitch * thread->num_cores;
uint32_t fg = shade_pal_index_simple(_color, calc_light_multiplier(_light));
uint32_t fg_red = (fg >> 24) & 0xff;
uint32_t fg_green = (fg >> 16) & 0xff;
uint32_t fg = _srccolor;
uint32_t fg_red = (fg >> 16) & 0xff;
uint32_t fg_green = (fg >> 8) & 0xff;
uint32_t fg_blue = fg & 0xff;
uint32_t fg_alpha = _srcalpha >> (FRACBITS - 8);
uint32_t bg_alpha = _destalpha >> (FRACBITS - 8);
do
{
fg_red *= fg_alpha;
fg_green *= fg_alpha;
fg_blue *= fg_alpha;
do {
uint32_t bg_red = (*dest >> 16) & 0xff;
uint32_t bg_green = (*dest >> 8) & 0xff;
uint32_t bg_blue = (*dest) & 0xff;
uint32_t red = clamp<uint32_t>(256 + fg_red - bg_red, 256, 256 + 255) - 255;
uint32_t green = clamp<uint32_t>(256 + fg_green - bg_green, 256, 256 + 255) - 255;
uint32_t blue = clamp<uint32_t>(256 + fg_blue - bg_blue, 256, 256 + 255) - 255;
uint32_t red = clamp<uint32_t>((0x10000 + fg_red - bg_red * bg_alpha) / 256, 256, 256 + 255) - 256;
uint32_t green = clamp<uint32_t>((0x10000 + fg_green - bg_green * bg_alpha) / 256, 256, 256 + 255) - 256;
uint32_t blue = clamp<uint32_t>((0x10000 + fg_blue - bg_blue * bg_alpha) / 256, 256, 256 + 255) - 256;
*dest = 0xff000000 | (red << 16) | (green << 8) | blue;
dest += pitch;