- Reimplemented rgb555 for drawers in r_drawt_pal.cpp

This commit is contained in:
Rachael Alexanderson 2016-12-24 12:30:45 -05:00
parent 101108877a
commit 785b58f57a
1 changed files with 415 additions and 114 deletions

View File

@ -50,6 +50,8 @@
#include "v_video.h" #include "v_video.h"
#include "r_draw_pal.h" #include "r_draw_pal.h"
EXTERN_CVAR(Bool, r_blendmethod)
// I should have commented this stuff better. // I should have commented this stuff better.
// //
// dc_temp is the buffer R_DrawColumnHoriz writes into. // dc_temp is the buffer R_DrawColumnHoriz writes into.
@ -444,12 +446,30 @@ namespace swrenderer
if (count <= 0) if (count <= 0)
return; return;
const uint32_t *fg2rgb = _srcblend;
const uint32_t *bg2rgb = _destblend;
dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg;
source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx];
pitch = _pitch * thread->num_cores; pitch = _pitch * thread->num_cores;
colormap = _colormap; colormap = _colormap;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t fg = colormap[*source];
uint32_t bg = *dest;
fg = fg2rgb[fg];
bg = bg2rgb[bg];
fg = (fg+bg) | 0x1f07c1f;
*dest = RGB32k.All[fg & (fg>>15)];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
uint32_t fg = colormap[*source]; uint32_t fg = colormap[*source];
uint32_t bg = *dest; uint32_t bg = *dest;
@ -462,6 +482,7 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt4AddPalCommand::Execute(DrawerThread *thread) void DrawColumnRt4AddPalCommand::Execute(DrawerThread *thread)
{ {
@ -475,12 +496,52 @@ namespace swrenderer
if (count <= 0) if (count <= 0)
return; return;
const uint32_t *fg2rgb = _srcblend;
const uint32_t *bg2rgb = _destblend;
dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg;
source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4];
pitch = _pitch * thread->num_cores; pitch = _pitch * thread->num_cores;
colormap = _colormap; colormap = _colormap;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t fg = colormap[source[0]];
uint32_t bg = dest[0];
fg = fg2rgb[fg];
bg = bg2rgb[bg];
fg = (fg+bg) | 0x1f07c1f;
dest[0] = RGB32k.All[fg & (fg>>15)];
fg = colormap[source[1]];
bg = dest[1];
fg = fg2rgb[fg];
bg = bg2rgb[bg];
fg = (fg+bg) | 0x1f07c1f;
dest[1] = RGB32k.All[fg & (fg>>15)];
fg = colormap[source[2]];
bg = dest[2];
fg = fg2rgb[fg];
bg = bg2rgb[bg];
fg = (fg+bg) | 0x1f07c1f;
dest[2] = RGB32k.All[fg & (fg>>15)];
fg = colormap[source[3]];
bg = dest[3];
fg = fg2rgb[fg];
bg = bg2rgb[bg];
fg = (fg+bg) | 0x1f07c1f;
dest[3] = RGB32k.All[fg & (fg>>15)];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
for (int ks = 0; ks < 4; ks++) for (int ks = 0; ks < 4; ks++)
{ // [SP] this 4col function was a block of copy-pasted code. 4 times. I regret nothing. { // [SP] this 4col function was a block of copy-pasted code. 4 times. I regret nothing.
@ -496,9 +557,11 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt1ShadedPalCommand::Execute(DrawerThread *thread) void DrawColumnRt1ShadedPalCommand::Execute(DrawerThread *thread)
{ {
uint32_t *fgstart;
const uint8_t *colormap; const uint8_t *colormap;
uint8_t *source; uint8_t *source;
uint8_t *dest; uint8_t *dest;
@ -509,12 +572,26 @@ namespace swrenderer
if (count <= 0) if (count <= 0)
return; return;
fgstart = &Col2RGB8[0][_color];
colormap = _colormap; colormap = _colormap;
dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg;
source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx];
pitch = _pitch * thread->num_cores; pitch = _pitch * thread->num_cores;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t val = colormap[*source];
uint32_t fg = fgstart[val<<8];
val = (Col2RGB8[64-val][*dest] + fg) | 0x1f07c1f;
*dest = RGB32k.All[val & (val>>15)];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
uint32_t val = *source; uint32_t val = *source;
int r = (palette[*dest].r * (255-val) + palette[_color].r * val) >> 10; int r = (palette[*dest].r * (255-val) + palette[_color].r * val) >> 10;
@ -525,9 +602,11 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt4ShadedPalCommand::Execute(DrawerThread *thread) void DrawColumnRt4ShadedPalCommand::Execute(DrawerThread *thread)
{ {
uint32_t *fgstart;
const uint8_t *colormap; const uint8_t *colormap;
uint8_t *source; uint8_t *source;
uint8_t *dest; uint8_t *dest;
@ -538,12 +617,40 @@ namespace swrenderer
if (count <= 0) if (count <= 0)
return; return;
fgstart = &Col2RGB8[0][_color];
colormap = _colormap; colormap = _colormap;
dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg;
source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4]; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4];
pitch = _pitch * thread->num_cores; pitch = _pitch * thread->num_cores;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t val;
val = colormap[source[0]];
val = (Col2RGB8[64-val][dest[0]] + fgstart[val<<8]) | 0x1f07c1f;
dest[0] = RGB32k.All[val & (val>>15)];
val = colormap[source[1]];
val = (Col2RGB8[64-val][dest[1]] + fgstart[val<<8]) | 0x1f07c1f;
dest[1] = RGB32k.All[val & (val>>15)];
val = colormap[source[2]];
val = (Col2RGB8[64-val][dest[2]] + fgstart[val<<8]) | 0x1f07c1f;
dest[2] = RGB32k.All[val & (val>>15)];
val = colormap[source[3]];
val = (Col2RGB8[64-val][dest[3]] + fgstart[val<<8]) | 0x1f07c1f;
dest[3] = RGB32k.All[val & (val>>15)];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
uint32_t val; uint32_t val;
@ -560,6 +667,7 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt1AddClampPalCommand::Execute(DrawerThread *thread) void DrawColumnRt1AddClampPalCommand::Execute(DrawerThread *thread)
{ {
@ -573,12 +681,32 @@ namespace swrenderer
if (count <= 0) if (count <= 0)
return; return;
const uint32_t *fg2rgb = _srcblend;
const uint32_t *bg2rgb = _destblend;
dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg; dest = ylookup[yl + thread->skipped_by_thread(yl)] + sx + _destorg;
source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx]; source = &thread->dc_temp[thread->temp_line_for_thread(yl)*4 + hx];
pitch = _pitch * thread->num_cores; pitch = _pitch * thread->num_cores;
colormap = _colormap; colormap = _colormap;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t a = fg2rgb[colormap[*source]] + bg2rgb[*dest];
uint32_t b = a;
a |= 0x01f07c1f;
b &= 0x40100400;
a &= 0x3fffffff;
b = b - (b >> 5);
a |= b;
*dest = RGB32k.All[(a>>15) & a];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
int fg = colormap[*source]; int fg = colormap[*source];
int bg = *dest; int bg = *dest;
@ -590,6 +718,7 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt4AddClampPalCommand::Execute(DrawerThread *thread) void DrawColumnRt4AddClampPalCommand::Execute(DrawerThread *thread)
{ {
@ -609,6 +738,55 @@ namespace swrenderer
colormap = _colormap; colormap = _colormap;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
const uint32_t *fg2rgb = _srcblend;
const uint32_t *bg2rgb = _destblend;
if (!r_blendmethod)
{
do {
uint32_t a = fg2rgb[colormap[source[0]]] + bg2rgb[dest[0]];
uint32_t b = a;
a |= 0x01f07c1f;
b &= 0x40100400;
a &= 0x3fffffff;
b = b - (b >> 5);
a |= b;
dest[0] = RGB32k.All[(a>>15) & a];
a = fg2rgb[colormap[source[1]]] + bg2rgb[dest[1]];
b = a;
a |= 0x01f07c1f;
b &= 0x40100400;
a &= 0x3fffffff;
b = b - (b >> 5);
a |= b;
dest[1] = RGB32k.All[(a>>15) & a];
a = fg2rgb[colormap[source[2]]] + bg2rgb[dest[2]];
b = a;
a |= 0x01f07c1f;
b &= 0x40100400;
a &= 0x3fffffff;
b = b - (b >> 5);
a |= b;
dest[2] = RGB32k.All[(a>>15) & a];
a = fg2rgb[colormap[source[3]]] + bg2rgb[dest[3]];
b = a;
a |= 0x01f07c1f;
b &= 0x40100400;
a &= 0x3fffffff;
b = b - (b >> 5);
a |= b;
dest[3] = RGB32k.All[(a>>15) & a];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
for (int ks = 0; ks < 4; ks++) for (int ks = 0; ks < 4; ks++)
{ {
@ -624,6 +802,7 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt1SubClampPalCommand::Execute(DrawerThread *thread) void DrawColumnRt1SubClampPalCommand::Execute(DrawerThread *thread)
{ {
@ -645,6 +824,23 @@ namespace swrenderer
colormap = _colormap; colormap = _colormap;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t a = (fg2rgb[colormap[*source]] | 0x40100400) - bg2rgb[*dest];
uint32_t b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
*dest = RGB32k.All[(a>>15) & a];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
int fg = colormap[*source]; int fg = colormap[*source];
int bg = *dest; int bg = *dest;
@ -656,6 +852,7 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt4SubClampPalCommand::Execute(DrawerThread *thread) void DrawColumnRt4SubClampPalCommand::Execute(DrawerThread *thread)
{ {
@ -677,6 +874,48 @@ namespace swrenderer
colormap = _colormap; colormap = _colormap;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t a = (fg2rgb[colormap[source[0]]] | 0x40100400) - bg2rgb[dest[0]];
uint32_t b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
dest[0] = RGB32k.All[(a>>15) & a];
a = (fg2rgb[colormap[source[1]]] | 0x40100400) - bg2rgb[dest[1]];
b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
dest[1] = RGB32k.All[(a>>15) & a];
a = (fg2rgb[colormap[source[2]]] | 0x40100400) - bg2rgb[dest[2]];
b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
dest[2] = RGB32k.All[(a>>15) & a];
a = (fg2rgb[colormap[source[3]]] | 0x40100400) - bg2rgb[dest[3]];
b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
dest[3] = RGB32k.All[(a>>15) & a];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
for (int ks = 0; ks < 4; ks++) for (int ks = 0; ks < 4; ks++)
{ {
@ -692,6 +931,7 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt1RevSubClampPalCommand::Execute(DrawerThread *thread) void DrawColumnRt1RevSubClampPalCommand::Execute(DrawerThread *thread)
{ {
@ -713,6 +953,23 @@ namespace swrenderer
colormap = _colormap; colormap = _colormap;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t a = (bg2rgb[*dest] | 0x40100400) - fg2rgb[colormap[*source]];
uint32_t b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
*dest = RGB32k.All[(a>>15) & a];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
int fg = colormap[*source]; int fg = colormap[*source];
int bg = *dest; int bg = *dest;
@ -724,6 +981,7 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
void DrawColumnRt4RevSubClampPalCommand::Execute(DrawerThread *thread) void DrawColumnRt4RevSubClampPalCommand::Execute(DrawerThread *thread)
{ {
@ -745,6 +1003,48 @@ namespace swrenderer
colormap = _colormap; colormap = _colormap;
const PalEntry *palette = GPalette.BaseColors; const PalEntry *palette = GPalette.BaseColors;
if (!r_blendmethod)
{
do {
uint32_t a = (bg2rgb[dest[0]] | 0x40100400) - fg2rgb[colormap[source[0]]];
uint32_t b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
dest[0] = RGB32k.All[(a>>15) & a];
a = (bg2rgb[dest[1]] | 0x40100400) - fg2rgb[colormap[source[1]]];
b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
dest[1] = RGB32k.All[(a>>15) & a];
a = (bg2rgb[dest[2]] | 0x40100400) - fg2rgb[colormap[source[2]]];
b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
dest[2] = RGB32k.All[(a>>15) & a];
a = (bg2rgb[dest[3]] | 0x40100400) - fg2rgb[colormap[source[3]]];
b = a;
b &= 0x40100400;
b = b - (b >> 5);
a &= b;
a |= 0x01f07c1f;
dest[3] = RGB32k.All[(a>>15) & a];
source += 4;
dest += pitch;
} while (--count);
}
else
{
do { do {
for (int ks = 0; ks < 4; ks++) for (int ks = 0; ks < 4; ks++)
{ {
@ -760,4 +1060,5 @@ namespace swrenderer
dest += pitch; dest += pitch;
} while (--count); } while (--count);
} }
}
} }