From 101108877acc4bba39668c066fba40793863b326 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 24 Dec 2016 11:40:15 -0500 Subject: [PATCH] - Reimplemented rgb555 into all drawers in r_draw_pal.cpp including span drawers. All that remains now are the 4col drawers in r_drawt_pal.cpp. --- src/r_draw.cpp | 6 + src/r_draw_pal.cpp | 1051 ++++++++++++++++++++++++++++++++------------ src/r_plane.cpp | 8 + src/r_things.cpp | 73 ++- 4 files changed, 847 insertions(+), 291 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index a08a204ca3..b44bc5f951 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -236,16 +236,22 @@ namespace swrenderer } if (flags & STYLEF_InvertSource) { + dc_srcblend = Col2RGB8_Inverse[fglevel >> 10]; + dc_destblend = Col2RGB8_LessPrecision[bglevel >> 10]; dc_srcalpha = fglevel; dc_destalpha = bglevel; } else if (op == STYLEOP_Add && fglevel + bglevel <= FRACUNIT) { + dc_srcblend = Col2RGB8[fglevel >> 10]; + dc_destblend = Col2RGB8[bglevel >> 10]; dc_srcalpha = fglevel; dc_destalpha = bglevel; } else { + dc_srcblend = Col2RGB8_LessPrecision[fglevel >> 10]; + dc_destblend = Col2RGB8_LessPrecision[bglevel >> 10]; dc_srcalpha = fglevel; dc_destalpha = bglevel; } diff --git a/src/r_draw_pal.cpp b/src/r_draw_pal.cpp index 0da9e38bee..88fe93f85a 100644 --- a/src/r_draw_pal.cpp +++ b/src/r_draw_pal.cpp @@ -658,6 +658,9 @@ namespace swrenderer int bits = _fracbits; int pitch = _pitch; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + count = thread->count_for_thread(_dest_y, count); if (count <= 0) return; @@ -711,6 +714,9 @@ namespace swrenderer int count = _count; int bits = _fracbits; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; + uint32_t dc_wall_texturefrac[4] = { _texturefrac[0], _texturefrac[1], _texturefrac[2], _texturefrac[3] }; uint32_t dc_wall_iscale[4] = { _iscale[0], _iscale[1], _iscale[2], _iscale[3] }; @@ -728,22 +734,48 @@ namespace swrenderer } pitch *= thread->num_cores; - do + if (!r_blendmethod) { - for (int i = 0; i < 4; ++i) + do { - uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; - if (pix != 0) + for (int i = 0; i < 4; ++i) { - uint32_t r = clamp(GPalette.BaseColors[_colormap[i][pix]].r - GPalette.BaseColors[dest[i]].r, 0, 255); - uint32_t g = clamp(GPalette.BaseColors[_colormap[i][pix]].g - GPalette.BaseColors[dest[i]].g, 0, 255); - uint32_t b = clamp(GPalette.BaseColors[_colormap[i][pix]].b - GPalette.BaseColors[dest[i]].b, 0, 255); - dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; + uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; + if (pix != 0) + { + uint32_t a = (bg2rgb[dest[i]] | 0x40100400) - fg2rgb[_colormap[i][pix]]; + uint32_t b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + dest[i] = RGB32k.All[a & (a >> 15)]; + } + dc_wall_texturefrac[i] += dc_wall_iscale[i]; } - dc_wall_texturefrac[i] += dc_wall_iscale[i]; - } - dest += _pitch; - } while (--count); + dest += _pitch; + } while (--count); + } + else + { + do + { + for (int i = 0; i < 4; ++i) + { + uint8_t pix = _source[i][dc_wall_texturefrac[i] >> bits]; + if (pix != 0) + { + uint32_t r = clamp(GPalette.BaseColors[_colormap[i][pix]].r - GPalette.BaseColors[dest[i]].r, 0, 255); + uint32_t g = clamp(GPalette.BaseColors[_colormap[i][pix]].g - GPalette.BaseColors[dest[i]].g, 0, 255); + uint32_t b = clamp(GPalette.BaseColors[_colormap[i][pix]].b - GPalette.BaseColors[dest[i]].b, 0, 255); + dest[i] = RGB256k.RGB[r>>2][g>>2][b>>2]; + } + dc_wall_texturefrac[i] += dc_wall_iscale[i]; + } + dest += _pitch; + } while (--count); + } } ///////////////////////////////////////////////////////////////////////// @@ -1319,18 +1351,30 @@ namespace swrenderer const PalEntry* pal = GPalette.BaseColors; - do + if (!r_blendmethod) { - int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; - int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; - int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; - int r = clamp((src_r + pal[*dest].r * _destalpha)>>18, 0, 255); - int g = clamp((src_g + pal[*dest].g * _destalpha)>>18, 0, 255); - int b = clamp((src_b + pal[*dest].b * _destalpha)>>18, 0, 255); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - } while (--count); - + do + { + uint32_t bg; + bg = (fg + bg2rgb[*dest]) | 0x1f07c1f; + *dest = RGB32k.All[bg & (bg >> 15)]; + dest += pitch; + } while (--count); + } + else + { + do + { + int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; + int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; + int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; + int r = clamp((src_r + pal[*dest].r * _destalpha)>>18, 0, 255); + int g = clamp((src_g + pal[*dest].g * _destalpha)>>18, 0, 255); + int b = clamp((src_b + pal[*dest].b * _destalpha)>>18, 0, 255); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + } while (--count); + } } void FillColumnAddClampPalCommand::Execute(DrawerThread *thread) @@ -1357,17 +1401,36 @@ namespace swrenderer const PalEntry* pal = GPalette.BaseColors; - do + if (!r_blendmethod) { - int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; - int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; - int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; - int r = clamp((src_r + pal[*dest].r * _destalpha)>>18, 0, 255); - int g = clamp((src_g + pal[*dest].g * _destalpha)>>18, 0, 255); - int b = clamp((src_b + pal[*dest].b * _destalpha)>>18, 0, 255); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - } while (--count); + do + { + uint32_t a = fg + bg2rgb[*dest]; + uint32_t b = a; + + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest = RGB32k.All[a & (a >> 15)]; + dest += pitch; + } while (--count); + } + else + { + do + { + int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; + int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; + int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; + int r = clamp((src_r + pal[*dest].r * _destalpha)>>18, 0, 255); + int g = clamp((src_g + pal[*dest].g * _destalpha)>>18, 0, 255); + int b = clamp((src_b + pal[*dest].b * _destalpha)>>18, 0, 255); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + } while (--count); + } } void FillColumnSubClampPalCommand::Execute(DrawerThread *thread) @@ -1378,6 +1441,8 @@ namespace swrenderer count = _count; dest = _dest; + uint32_t *bg2rgb = _destblend; + uint32_t fg = _srccolor; int pitch = _pitch; @@ -1390,19 +1455,37 @@ namespace swrenderer const PalEntry* palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; - int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; - int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; - int bg = *dest; - int r = MAX((src_r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((src_g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((src_b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + do + { + uint32_t a = fg - bg2rgb[*dest]; + uint32_t b = a; - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - } while (--count); + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k.All[a & (a >> 15)]; + dest += pitch; + } while (--count); + } + else + { + do + { + int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; + int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; + int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; + int bg = *dest; + int r = MAX((src_r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((src_g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((src_b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + } while (--count); + } } void FillColumnRevSubClampPalCommand::Execute(DrawerThread *thread) @@ -1415,6 +1498,8 @@ namespace swrenderer return; dest = _dest; + uint32_t *bg2rgb = _destblend; + uint32_t fg = _srccolor; int pitch = _pitch; @@ -1427,19 +1512,37 @@ namespace swrenderer const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; - int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; - int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; - int bg = *dest; - int r = MAX((src_r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((src_g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((src_b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + do + { + uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg; + uint32_t b = a; - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - } while (--count); + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k.All[a & (a >> 15)]; + dest += pitch; + } while (--count); + } + else + { + do + { + int src_r = ((_srccolor >> 16) & 0xff) * _srcalpha; + int src_g = ((_srccolor >> 0) & 0xff) * _srcalpha; + int src_b = ((_srccolor >> 8) & 0xff) * _srcalpha; + int bg = *dest; + int r = MAX((src_r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((src_g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((src_b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + } while (--count); + } } void DrawColumnAddPalCommand::Execute(DrawerThread *thread) @@ -1465,21 +1568,41 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const uint8_t *colormap = _colormap; const uint8_t *source = _source; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - uint32_t fg = colormap[source[frac >> FRACBITS]]; - uint32_t bg = *dest; - uint32_t r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); - uint32_t g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); - uint32_t b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - frac += fracstep; - } while (--count); + do + { + uint32_t fg = colormap[source[frac >> FRACBITS]]; + uint32_t bg = *dest; + + fg = fg2rgb[fg]; + bg = bg2rgb[bg]; + fg = (fg + bg) | 0x1f07c1f; + *dest = RGB32k.All[fg & (fg >> 15)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + uint32_t fg = colormap[source[frac >> FRACBITS]]; + uint32_t bg = *dest; + uint32_t r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + uint32_t g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + uint32_t b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + frac += fracstep; + } while (--count); + } } void DrawColumnTranslatedPalCommand::Execute(DrawerThread *thread) @@ -1543,23 +1666,43 @@ namespace swrenderer fracstep *= thread->num_cores; pitch *= thread->num_cores; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const uint8_t *translation = _translation; const uint8_t *colormap = _colormap; const uint8_t *source = _source; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - uint32_t fg = colormap[translation[source[frac >> FRACBITS]]]; - uint32_t bg = *dest; - uint32_t r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); - uint32_t g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); - uint32_t b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - frac += fracstep; - } while (--count); + do + { + uint32_t fg = colormap[translation[source[frac >> FRACBITS]]]; + uint32_t bg = *dest; + + fg = fg2rgb[fg]; + bg = bg2rgb[bg]; + fg = (fg + bg) | 0x1f07c1f; + *dest = RGB32k.All[fg & (fg >> 15)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + uint32_t fg = colormap[translation[source[frac >> FRACBITS]]]; + uint32_t bg = *dest; + uint32_t r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + uint32_t g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + uint32_t b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + frac += fracstep; + } while (--count); + } } void DrawColumnShadedPalCommand::Execute(DrawerThread *thread) @@ -1586,21 +1729,37 @@ namespace swrenderer const uint8_t *source = _source; const uint8_t *colormap = _colormap; - + uint32_t *fgstart = &Col2RGB8[0][_color]; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - uint32_t val = source[frac >> FRACBITS]; + do + { + uint32_t val = colormap[source[frac >> FRACBITS]]; + uint32_t fg = fgstart[val << 8]; + val = (Col2RGB8[64 - val][*dest] + fg) | 0x1f07c1f; + *dest = RGB32k.All[val & (val >> 15)]; - int r = (palette[*dest].r * (255-val) + palette[_color].r * val) >> 10; - int g = (palette[*dest].g * (255-val) + palette[_color].g * val) >> 10; - int b = (palette[*dest].b * (255-val) + palette[_color].b * val) >> 10; - *dest = RGB256k.RGB[clamp(r,0,63)][clamp(g,0,63)][clamp(b,0,63)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + uint32_t val = source[frac >> FRACBITS]; - dest += pitch; - frac += fracstep; - } while (--count); + int r = (palette[*dest].r * (255-val) + palette[_color].r * val) >> 10; + int g = (palette[*dest].g * (255-val) + palette[_color].g * val) >> 10; + int b = (palette[*dest].b * (255-val) + palette[_color].b * val) >> 10; + *dest = RGB256k.RGB[clamp(r,0,63)][clamp(g,0,63)][clamp(b,0,63)]; + + dest += pitch; + frac += fracstep; + } while (--count); + } } void DrawColumnAddClampPalCommand::Execute(DrawerThread *thread) @@ -1628,19 +1787,41 @@ namespace swrenderer const uint8_t *colormap = _colormap; const uint8_t *source = _source; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - int fg = colormap[source[frac >> FRACBITS]]; - int bg = *dest; - int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); - int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); - int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - frac += fracstep; - } while (--count); + do + { + uint32_t a = fg2rgb[colormap[source[frac >> FRACBITS]]] + bg2rgb[*dest]; + uint32_t b = a; + + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest = RGB32k.All[a & (a >> 15)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + int fg = colormap[source[frac >> FRACBITS]]; + int bg = *dest; + int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + frac += fracstep; + } while (--count); + } } void DrawColumnAddClampTranslatedPalCommand::Execute(DrawerThread *thread) @@ -1669,19 +1850,41 @@ namespace swrenderer const uint8_t *translation = _translation; const uint8_t *colormap = _colormap; const uint8_t *source = _source; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - int fg = colormap[translation[source[frac >> FRACBITS]]]; - int bg = *dest; - int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); - int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); - int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - frac += fracstep; - } while (--count); + do + { + uint32_t a = fg2rgb[colormap[translation[source[frac >> FRACBITS]]]] + bg2rgb[*dest]; + uint32_t b = a; + + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest = RGB32k.All[(a >> 15) & a]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + int fg = colormap[translation[source[frac >> FRACBITS]]]; + int bg = *dest; + int r = MIN((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 63); + int g = MIN((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 63); + int b = MIN((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 63); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + frac += fracstep; + } while (--count); + } } void DrawColumnSubClampPalCommand::Execute(DrawerThread *thread) @@ -1709,19 +1912,40 @@ namespace swrenderer const uint8_t *colormap = _colormap; const uint8_t *source = _source; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - int fg = colormap[source[frac >> FRACBITS]]; - int bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - frac += fracstep; - } while (--count); + do + { + uint32_t a = (fg2rgb[colormap[source[frac >> FRACBITS]]] | 0x40100400) - bg2rgb[*dest]; + uint32_t b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k.All[a & (a >> 15)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + int fg = colormap[source[frac >> FRACBITS]]; + int bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + frac += fracstep; + } while (--count); + } } void DrawColumnSubClampTranslatedPalCommand::Execute(DrawerThread *thread) @@ -1750,19 +1974,40 @@ namespace swrenderer const uint8_t *translation = _translation; const uint8_t *colormap = _colormap; const uint8_t *source = _source; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - int fg = colormap[translation[source[frac >> FRACBITS]]]; - int bg = *dest; - int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - frac += fracstep; - } while (--count); + do + { + uint32_t a = (fg2rgb[colormap[translation[source[frac >> FRACBITS]]]] | 0x40100400) - bg2rgb[*dest]; + uint32_t b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k.All[(a >> 15) & a]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + int fg = colormap[translation[source[frac >> FRACBITS]]]; + int bg = *dest; + int r = MAX((palette[fg].r * _srcalpha - palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha - palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha - palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + frac += fracstep; + } while (--count); + } } void DrawColumnRevSubClampPalCommand::Execute(DrawerThread *thread) @@ -1790,19 +2035,40 @@ namespace swrenderer const uint8_t *colormap = _colormap; const uint8_t *source = _source; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - int fg = colormap[source[frac >> FRACBITS]]; - int bg = *dest; - int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - frac += fracstep; - } while (--count); + do + { + uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[source[frac >> FRACBITS]]]; + uint32_t b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k.All[a & (a >> 15)]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + int fg = colormap[source[frac >> FRACBITS]]; + int bg = *dest; + int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + frac += fracstep; + } while (--count); + } } void DrawColumnRevSubClampTranslatedPalCommand::Execute(DrawerThread *thread) @@ -1831,19 +2097,40 @@ namespace swrenderer const uint8_t *translation = _translation; const uint8_t *colormap = _colormap; const uint8_t *source = _source; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; - do + if (!r_blendmethod) { - int fg = colormap[translation[source[frac >> FRACBITS]]]; - int bg = *dest; - int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest = RGB256k.RGB[r][g][b]; - dest += pitch; - frac += fracstep; - } while (--count); + do + { + uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[translation[source[frac >> FRACBITS]]]]; + uint32_t b = a; + + b &= 0x40100400; + b = b - (b >> 5); + a &= b; + a |= 0x01f07c1f; + *dest = RGB32k.All[(a >> 15) & a]; + dest += pitch; + frac += fracstep; + } while (--count); + } + else + { + do + { + int fg = colormap[translation[source[frac >> FRACBITS]]]; + int bg = *dest; + int r = MAX((-palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((-palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((-palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; + dest += pitch; + frac += fracstep; + } while (--count); + } } ///////////////////////////////////////////////////////////////////////// @@ -2103,6 +2390,8 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; xfrac = _xfrac; yfrac = _yfrac; @@ -2116,41 +2405,81 @@ namespace swrenderer const PalEntry *palette = GPalette.BaseColors; - if (_xbits == 6 && _ybits == 6) + if (!r_blendmethod) { - // 64x64 is the most common case by far, so special case it. - do + if (_xbits == 6 && _ybits == 6) { - spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); - uint32_t fg = colormap[source[spot]]; - uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest++ = RGB256k.RGB[r][g][b]; - - xfrac += xstep; - yfrac += ystep; - } while (--count); + // 64x64 is the most common case by far, so special case it. + do + { + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + uint32_t fg = colormap[source[spot]]; + uint32_t bg = *dest; + fg = fg2rgb[fg]; + bg = bg2rgb[bg]; + fg = (fg + bg) | 0x1f07c1f; + *dest++ = RGB32k.All[fg & (fg >> 15)]; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + uint32_t fg = colormap[source[spot]]; + uint32_t bg = *dest; + fg = fg2rgb[fg]; + bg = bg2rgb[bg]; + fg = (fg + bg) | 0x1f07c1f; + *dest++ = RGB32k.All[fg & (fg >> 15)]; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } else { - uint8_t yshift = 32 - _ybits; - uint8_t xshift = yshift - _xbits; - int xmask = ((1 << _xbits) - 1) << _ybits; - do + if (_xbits == 6 && _ybits == 6) { - spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); - uint32_t fg = colormap[source[spot]]; - uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest++ = RGB256k.RGB[r][g][b]; + // 64x64 is the most common case by far, so special case it. + do + { + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + uint32_t fg = colormap[source[spot]]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest++ = RGB256k.RGB[r][g][b]; - xfrac += xstep; - yfrac += ystep; - } while (--count); + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + uint32_t fg = colormap[source[spot]]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest++ = RGB256k.RGB[r][g][b]; + + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } } @@ -2168,6 +2497,8 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; @@ -2181,53 +2512,107 @@ namespace swrenderer xstep = _xstep; ystep = _ystep; - if (_xbits == 6 && _ybits == 6) + if (!r_blendmethod) { - // 64x64 is the most common case by far, so special case it. - do + if (_xbits == 6 && _ybits == 6) { - uint8_t texdata; - - spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); - texdata = source[spot]; - if (texdata != 0) + // 64x64 is the most common case by far, so special case it. + do { - uint32_t fg = colormap[texdata]; - uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest = RGB256k.RGB[r][g][b]; - } - dest++; - xfrac += xstep; - yfrac += ystep; - } while (--count); + uint8_t texdata; + + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + texdata = source[spot]; + if (texdata != 0) + { + uint32_t fg = colormap[texdata]; + uint32_t bg = *dest; + fg = fg2rgb[fg]; + bg = bg2rgb[bg]; + fg = (fg + bg) | 0x1f07c1f; + *dest = RGB32k.All[fg & (fg >> 15)]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + uint8_t texdata; + + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + texdata = source[spot]; + if (texdata != 0) + { + uint32_t fg = colormap[texdata]; + uint32_t bg = *dest; + fg = fg2rgb[fg]; + bg = bg2rgb[bg]; + fg = (fg + bg) | 0x1f07c1f; + *dest = RGB32k.All[fg & (fg >> 15)]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } else { - uint8_t yshift = 32 - _ybits; - uint8_t xshift = yshift - _xbits; - int xmask = ((1 << _xbits) - 1) << _ybits; - do + if (_xbits == 6 && _ybits == 6) { - uint8_t texdata; - - spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); - texdata = source[spot]; - if (texdata != 0) + // 64x64 is the most common case by far, so special case it. + do { - uint32_t fg = colormap[texdata]; - uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest = RGB256k.RGB[r][g][b]; - } - dest++; - xfrac += xstep; - yfrac += ystep; - } while (--count); + uint8_t texdata; + + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + texdata = source[spot]; + if (texdata != 0) + { + uint32_t fg = colormap[texdata]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + uint8_t texdata; + + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + texdata = source[spot]; + if (texdata != 0) + { + uint32_t fg = colormap[texdata]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } } @@ -2245,6 +2630,8 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; xfrac = _xfrac; @@ -2257,41 +2644,87 @@ namespace swrenderer xstep = _xstep; ystep = _ystep; - if (_xbits == 6 && _ybits == 6) + if (!r_blendmethod) { - // 64x64 is the most common case by far, so special case it. - do + if (_xbits == 6 && _ybits == 6) { - spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); - uint32_t fg = colormap[source[spot]]; - uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest++ = RGB256k.RGB[r][g][b]; + // 64x64 is the most common case by far, so special case it. + do + { + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + uint32_t a = fg2rgb[colormap[source[spot]]] + bg2rgb[*dest]; + uint32_t b = a; - xfrac += xstep; - yfrac += ystep; - } while (--count); + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest++ = RGB32k.All[a & (a >> 15)]; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + uint32_t a = fg2rgb[colormap[source[spot]]] + bg2rgb[*dest]; + uint32_t b = a; + + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest++ = RGB32k.All[a & (a >> 15)]; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } else { - uint8_t yshift = 32 - _ybits; - uint8_t xshift = yshift - _xbits; - int xmask = ((1 << _xbits) - 1) << _ybits; - do + if (_xbits == 6 && _ybits == 6) { - spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); - uint32_t fg = colormap[source[spot]]; - uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest++ = RGB256k.RGB[r][g][b]; + // 64x64 is the most common case by far, so special case it. + do + { + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + uint32_t fg = colormap[source[spot]]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest++ = RGB256k.RGB[r][g][b]; - xfrac += xstep; - yfrac += ystep; - } while (--count); + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + uint32_t fg = colormap[source[spot]]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest++ = RGB256k.RGB[r][g][b]; + + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } } @@ -2309,6 +2742,8 @@ namespace swrenderer const uint8_t *colormap = _colormap; int count; int spot; + uint32_t *fg2rgb = _srcblend; + uint32_t *bg2rgb = _destblend; const PalEntry *palette = GPalette.BaseColors; xfrac = _xfrac; @@ -2321,53 +2756,113 @@ namespace swrenderer xstep = _xstep; ystep = _ystep; - if (_xbits == 6 && _ybits == 6) + if (!r_columnmethod) { - // 64x64 is the most common case by far, so special case it. - do + if (_xbits == 6 && _ybits == 6) { - uint8_t texdata; - - spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); - texdata = source[spot]; - if (texdata != 0) + // 64x64 is the most common case by far, so special case it. + do { - uint32_t fg = colormap[texdata]; - uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest = RGB256k.RGB[r][g][b]; - } - dest++; - xfrac += xstep; - yfrac += ystep; - } while (--count); + uint8_t texdata; + + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + texdata = source[spot]; + if (texdata != 0) + { + uint32_t a = fg2rgb[colormap[texdata]] + bg2rgb[*dest]; + uint32_t b = a; + + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest = RGB32k.All[a & (a >> 15)]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + uint8_t texdata; + + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + texdata = source[spot]; + if (texdata != 0) + { + uint32_t a = fg2rgb[colormap[texdata]] + bg2rgb[*dest]; + uint32_t b = a; + + a |= 0x01f07c1f; + b &= 0x40100400; + a &= 0x3fffffff; + b = b - (b >> 5); + a |= b; + *dest = RGB32k.All[a & (a >> 15)]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } else { - uint8_t yshift = 32 - _ybits; - uint8_t xshift = yshift - _xbits; - int xmask = ((1 << _xbits) - 1) << _ybits; - do + if (_xbits == 6 && _ybits == 6) { - uint8_t texdata; - - spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); - texdata = source[spot]; - if (texdata != 0) + // 64x64 is the most common case by far, so special case it. + do { - uint32_t fg = colormap[texdata]; - uint32_t bg = *dest; - int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); - int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); - int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); - *dest = RGB256k.RGB[r][g][b]; - } - dest++; - xfrac += xstep; - yfrac += ystep; - } while (--count); + uint8_t texdata; + + spot = ((xfrac >> (32 - 6 - 6))&(63 * 64)) + (yfrac >> (32 - 6)); + texdata = source[spot]; + if (texdata != 0) + { + uint32_t fg = colormap[texdata]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } + else + { + uint8_t yshift = 32 - _ybits; + uint8_t xshift = yshift - _xbits; + int xmask = ((1 << _xbits) - 1) << _ybits; + do + { + uint8_t texdata; + + spot = ((xfrac >> xshift) & xmask) + (yfrac >> yshift); + texdata = source[spot]; + if (texdata != 0) + { + uint32_t fg = colormap[texdata]; + uint32_t bg = *dest; + int r = MAX((palette[fg].r * _srcalpha + palette[bg].r * _destalpha)>>18, 0); + int g = MAX((palette[fg].g * _srcalpha + palette[bg].g * _destalpha)>>18, 0); + int b = MAX((palette[fg].b * _srcalpha + palette[bg].b * _destalpha)>>18, 0); + *dest = RGB256k.RGB[r][g][b]; + } + dest++; + xfrac += xstep; + yfrac += ystep; + } while (--count); + } } } diff --git a/src/r_plane.cpp b/src/r_plane.cpp index dbecb5247d..b8368e73a7 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -1509,12 +1509,16 @@ void R_DrawNormalPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t if (!additive) { spanfunc = R_DrawSpanMaskedTranslucent; + dc_srcblend = Col2RGB8[alpha>>10]; + dc_destblend = Col2RGB8[(OPAQUE-alpha)>>10]; dc_srcalpha = alpha; dc_destalpha = OPAQUE-alpha; } else { spanfunc = R_DrawSpanMaskedAddClamp; + dc_srcblend = Col2RGB8_LessPrecision[alpha>>10]; + dc_destblend = Col2RGB8_LessPrecision[FRACUNIT>>10]; dc_srcalpha = alpha; dc_destalpha = FRACUNIT; } @@ -1531,12 +1535,16 @@ void R_DrawNormalPlane (visplane_t *pl, double _xscale, double _yscale, fixed_t if (!additive) { spanfunc = R_DrawSpanTranslucent; + dc_srcblend = Col2RGB8[alpha>>10]; + dc_destblend = Col2RGB8[(OPAQUE-alpha)>>10]; dc_srcalpha = alpha; dc_destalpha = OPAQUE-alpha; } else { spanfunc = R_DrawSpanAddClamp; + dc_srcblend = Col2RGB8_LessPrecision[alpha>>10]; + dc_destblend = Col2RGB8_LessPrecision[FRACUNIT>>10]; dc_srcalpha = alpha; dc_destalpha = FRACUNIT; } diff --git a/src/r_things.cpp b/src/r_things.cpp index 61da979da8..95b563c0d6 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -72,6 +72,7 @@ EXTERN_CVAR(Int, r_drawfuzz) EXTERN_CVAR(Bool, r_deathcamera); EXTERN_CVAR(Bool, r_drawplayersprites) EXTERN_CVAR(Bool, r_drawvoxels) +EXTERN_CVAR(Bool, r_blendmethod) CVAR(Bool, r_fullbrightignoresectorcolor, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); //CVAR(Bool, r_splitsprites, true, CVAR_ARCHIVE) @@ -2640,8 +2641,10 @@ static void R_DrawMaskedSegsBehindParticle (const vissprite_t *vis) void R_DrawParticle (vissprite_t *vis) { + DWORD *bg2rgb; int spacing; BYTE *dest; + DWORD fg; BYTE color = vis->Style.colormap[vis->startfrac]; int yl = vis->y1; int ycount = vis->y2 - yl + 1; @@ -2655,8 +2658,32 @@ void R_DrawParticle (vissprite_t *vis) // vis->renderflags holds translucency level (0-255) fixed_t fglevel, bglevel; - fglevel = ((vis->renderflags + 1) << 8) & ~0x3ff; - bglevel = FRACUNIT-fglevel; + { + DWORD *fg2rgb; + + fglevel = ((vis->renderflags + 1) << 8) & ~0x3ff; + bglevel = FRACUNIT-fglevel; + fg2rgb = Col2RGB8[fglevel>>10]; + bg2rgb = Col2RGB8[bglevel>>10]; + fg = fg2rgb[color]; + } + + /* + + spacing = RenderTarget->GetPitch() - countbase; + dest = ylookup[yl] + x1 + dc_destorg; + + do + { + int count = countbase; + do + { + DWORD bg = bg2rgb[*dest]; + bg = (fg+bg) | 0x1f07c1f; + *dest++ = RGB32k.All[bg & (bg>>15)]; + } while (--count); + dest += spacing; + } while (--ycount);*/ // original was row-wise // width = countbase @@ -2664,20 +2691,40 @@ void R_DrawParticle (vissprite_t *vis) spacing = RenderTarget->GetPitch(); - for (int x = x1; x < (x1+countbase); x++) + if (!r_blendmethod) { - dc_x = x; - if (R_ClipSpriteColumnWithPortals(vis)) - continue; - dest = ylookup[yl] + x + dc_destorg; - for (int y = 0; y < ycount; y++) + for (int x = x1; x < (x1+countbase); x++) { - uint32_t dest_r = MIN((GPalette.BaseColors[*dest].r * bglevel + GPalette.BaseColors[color].r * fglevel) >> 18, 63); - uint32_t dest_g = MIN((GPalette.BaseColors[*dest].g * bglevel + GPalette.BaseColors[color].g * fglevel) >> 18, 63); - uint32_t dest_b = MIN((GPalette.BaseColors[*dest].b * bglevel + GPalette.BaseColors[color].b * fglevel) >> 18, 63); + dc_x = x; + if (R_ClipSpriteColumnWithPortals(vis)) + continue; + dest = ylookup[yl] + x + dc_destorg; + for (int y = 0; y < ycount; y++) + { + DWORD bg = bg2rgb[*dest]; + bg = (fg+bg) | 0x1f07c1f; + *dest = RGB32k.All[bg & (bg>>15)]; + dest += spacing; + } + } + } + else + { + for (int x = x1; x < (x1+countbase); x++) + { + dc_x = x; + if (R_ClipSpriteColumnWithPortals(vis)) + continue; + dest = ylookup[yl] + x + dc_destorg; + for (int y = 0; y < ycount; y++) + { + uint32_t dest_r = MIN((GPalette.BaseColors[*dest].r * bglevel + GPalette.BaseColors[color].r * fglevel) >> 18, 63); + uint32_t dest_g = MIN((GPalette.BaseColors[*dest].g * bglevel + GPalette.BaseColors[color].g * fglevel) >> 18, 63); + uint32_t dest_b = MIN((GPalette.BaseColors[*dest].b * bglevel + GPalette.BaseColors[color].b * fglevel) >> 18, 63); - *dest = RGB256k.RGB[dest_r][dest_g][dest_b]; - dest += spacing; + *dest = RGB256k.RGB[dest_r][dest_g][dest_b]; + dest += spacing; + } } } }