Add dynamic colormaps support

This commit is contained in:
Magnus Norddahl 2016-12-17 02:10:52 +01:00
parent 6e8174d9b4
commit ddb18d8e32
2 changed files with 52 additions and 24 deletions

View file

@ -41,11 +41,30 @@ void DrawTriangleCodegen::Generate(TriBlendMode blendmode, bool truecolor, bool
LoadArgs(args, thread_data); LoadArgs(args, thread_data);
CalculateGradients(); CalculateGradients();
DrawFullSpans();
DrawPartialBlocks(); if (truecolor)
{
SSAIfBlock branch;
branch.if_block(is_simple_shade);
{
DrawFullSpans(true);
DrawPartialBlocks(true);
}
branch.else_block();
{
DrawFullSpans(false);
DrawPartialBlocks(false);
}
branch.end_block();
}
else
{
DrawFullSpans(true);
DrawPartialBlocks(true);
}
} }
void DrawTriangleCodegen::DrawFullSpans() void DrawTriangleCodegen::DrawFullSpans(bool isSimpleShade)
{ {
stack_i.store(SSAInt(0)); stack_i.store(SSAInt(0));
SSAForBlock loop; SSAForBlock loop;
@ -130,7 +149,7 @@ void DrawTriangleCodegen::DrawFullSpans()
for (int sse = 0; sse < 4; sse++) for (int sse = 0; sse < 4; sse++)
{ {
currentlight = is_fixed_light.select(light, lightpos >> 8); currentlight = is_fixed_light.select(light, lightpos >> 8);
pixels[sse] = ProcessPixel32(pixels[sse], varyingPos); pixels[sse] = ProcessPixel32(pixels[sse], varyingPos, isSimpleShade);
for (int j = 0; j < TriVertex::NumVarying; j++) for (int j = 0; j < TriVertex::NumVarying; j++)
varyingPos[j] = varyingPos[j] + varyingStep[j]; varyingPos[j] = varyingPos[j] + varyingStep[j];
@ -180,7 +199,7 @@ void DrawTriangleCodegen::DrawFullSpans()
loop.end_block(); loop.end_block();
} }
void DrawTriangleCodegen::DrawPartialBlocks() void DrawTriangleCodegen::DrawPartialBlocks(bool isSimpleShade)
{ {
stack_i.store(SSAInt(0)); stack_i.store(SSAInt(0));
SSAForBlock loop; SSAForBlock loop;
@ -240,7 +259,7 @@ void DrawTriangleCodegen::DrawPartialBlocks()
currentlight = is_fixed_light.select(light, lightpos >> 8); currentlight = is_fixed_light.select(light, lightpos >> 8);
SSAUBytePtr destptr = dest[x * 4]; SSAUBytePtr destptr = dest[x * 4];
destptr.store_vec4ub(ProcessPixel32(destptr.load_vec4ub(false), varyingPos)); destptr.store_vec4ub(ProcessPixel32(destptr.load_vec4ub(false), varyingPos, isSimpleShade));
} }
else else
{ {
@ -381,7 +400,15 @@ SSAInt DrawTriangleCodegen::Shade8(SSAInt c)
return currentcolormap[c].load(true).zext_int(); return currentcolormap[c].load(true).zext_int();
} }
SSAVec4i DrawTriangleCodegen::ProcessPixel32(SSAVec4i bg, SSAInt *varying) SSAVec4i DrawTriangleCodegen::Shade32(SSAVec4i fg, SSAInt light, bool isSimpleShade)
{
if (isSimpleShade)
return shade_bgra_simple(fg, currentlight);
else
return shade_bgra_advanced(fg, currentlight, shade_constants);
}
SSAVec4i DrawTriangleCodegen::ProcessPixel32(SSAVec4i bg, SSAInt *varying, bool isSimpleShade)
{ {
SSAVec4i fg; SSAVec4i fg;
SSAVec4i output; SSAVec4i output;
@ -391,58 +418,58 @@ SSAVec4i DrawTriangleCodegen::ProcessPixel32(SSAVec4i bg, SSAInt *varying)
default: default:
case TriBlendMode::Copy: case TriBlendMode::Copy:
fg = Sample32(varying); fg = Sample32(varying);
output = blend_copy(shade_bgra_simple(fg, currentlight)); output = blend_copy(Shade32(fg, currentlight, isSimpleShade));
break; break;
case TriBlendMode::AlphaBlend: case TriBlendMode::AlphaBlend:
fg = Sample32(varying); fg = Sample32(varying);
output = blend_alpha_blend(shade_bgra_simple(fg, currentlight), bg); output = blend_alpha_blend(Shade32(fg, currentlight, isSimpleShade), bg);
break; break;
case TriBlendMode::AddSolid: case TriBlendMode::AddSolid:
fg = Sample32(varying); fg = Sample32(varying);
output = blend_add(shade_bgra_simple(fg, currentlight), bg, srcalpha, destalpha); output = blend_add(Shade32(fg, currentlight, isSimpleShade), bg, srcalpha, destalpha);
break; break;
case TriBlendMode::Add: case TriBlendMode::Add:
fg = Sample32(varying); fg = Sample32(varying);
output = blend_add(shade_bgra_simple(fg, currentlight), bg, srcalpha, calc_blend_bgalpha(fg, destalpha)); output = blend_add(Shade32(fg, currentlight, isSimpleShade), bg, srcalpha, calc_blend_bgalpha(fg, destalpha));
break; break;
case TriBlendMode::Sub: case TriBlendMode::Sub:
fg = Sample32(varying); fg = Sample32(varying);
output = blend_sub(shade_bgra_simple(fg, currentlight), bg, srcalpha, calc_blend_bgalpha(fg, destalpha)); output = blend_sub(Shade32(fg, currentlight, isSimpleShade), bg, srcalpha, calc_blend_bgalpha(fg, destalpha));
break; break;
case TriBlendMode::RevSub: case TriBlendMode::RevSub:
fg = Sample32(varying); fg = Sample32(varying);
output = blend_revsub(shade_bgra_simple(fg, currentlight), bg, srcalpha, calc_blend_bgalpha(fg, destalpha)); output = blend_revsub(Shade32(fg, currentlight, isSimpleShade), bg, srcalpha, calc_blend_bgalpha(fg, destalpha));
break; break;
case TriBlendMode::Stencil: case TriBlendMode::Stencil:
fg = Sample32(varying); fg = Sample32(varying);
output = blend_stencil(shade_bgra_simple(SSAVec4i::unpack(color), currentlight), fg[3], bg, srcalpha, destalpha); output = blend_stencil(Shade32(SSAVec4i::unpack(color), currentlight, isSimpleShade), fg[3], bg, srcalpha, destalpha);
break; break;
case TriBlendMode::Shaded: case TriBlendMode::Shaded:
output = blend_stencil(shade_bgra_simple(SSAVec4i::unpack(color), currentlight), Sample8(varying), bg, srcalpha, destalpha); output = blend_stencil(Shade32(SSAVec4i::unpack(color), currentlight, isSimpleShade), Sample8(varying), bg, srcalpha, destalpha);
break; break;
case TriBlendMode::TranslateCopy: case TriBlendMode::TranslateCopy:
fg = TranslateSample32(varying); fg = TranslateSample32(varying);
output = blend_copy(shade_bgra_simple(fg, currentlight)); output = blend_copy(Shade32(fg, currentlight, isSimpleShade));
break; break;
case TriBlendMode::TranslateAlphaBlend: case TriBlendMode::TranslateAlphaBlend:
fg = TranslateSample32(varying); fg = TranslateSample32(varying);
output = blend_alpha_blend(shade_bgra_simple(fg, currentlight), bg); output = blend_alpha_blend(Shade32(fg, currentlight, isSimpleShade), bg);
break; break;
case TriBlendMode::TranslateAdd: case TriBlendMode::TranslateAdd:
fg = TranslateSample32(varying); fg = TranslateSample32(varying);
output = blend_add(shade_bgra_simple(fg, currentlight), bg, srcalpha, calc_blend_bgalpha(fg, destalpha)); output = blend_add(Shade32(fg, currentlight, isSimpleShade), bg, srcalpha, calc_blend_bgalpha(fg, destalpha));
break; break;
case TriBlendMode::TranslateSub: case TriBlendMode::TranslateSub:
fg = TranslateSample32(varying); fg = TranslateSample32(varying);
output = blend_sub(shade_bgra_simple(fg, currentlight), bg, srcalpha, calc_blend_bgalpha(fg, destalpha)); output = blend_sub(Shade32(fg, currentlight, isSimpleShade), bg, srcalpha, calc_blend_bgalpha(fg, destalpha));
break; break;
case TriBlendMode::TranslateRevSub: case TriBlendMode::TranslateRevSub:
fg = TranslateSample32(varying); fg = TranslateSample32(varying);
output = blend_revsub(shade_bgra_simple(fg, currentlight), bg, srcalpha, calc_blend_bgalpha(fg, destalpha)); output = blend_revsub(Shade32(fg, currentlight, isSimpleShade), bg, srcalpha, calc_blend_bgalpha(fg, destalpha));
break; break;
case TriBlendMode::AddSrcColorOneMinusSrcColor: case TriBlendMode::AddSrcColorOneMinusSrcColor:
fg = Sample32(varying); fg = Sample32(varying);
output = blend_add_srccolor_oneminussrccolor(shade_bgra_simple(fg, currentlight), bg); output = blend_add_srccolor_oneminussrccolor(Shade32(fg, currentlight, isSimpleShade), bg);
break; break;
case TriBlendMode::Skycap: case TriBlendMode::Skycap:
fg = Sample32(varying); fg = Sample32(varying);

View file

@ -48,15 +48,16 @@ private:
void CalculateGradients(); void CalculateGradients();
SSAFloat FindGradientX(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2); SSAFloat FindGradientX(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2);
SSAFloat FindGradientY(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2); SSAFloat FindGradientY(SSAFloat x0, SSAFloat y0, SSAFloat x1, SSAFloat y1, SSAFloat x2, SSAFloat y2, SSAFloat c0, SSAFloat c1, SSAFloat c2);
void DrawFullSpans(); void DrawFullSpans(bool isSimpleShade);
void DrawPartialBlocks(); void DrawPartialBlocks(bool isSimpleShade);
SSAVec4i ProcessPixel32(SSAVec4i bg, SSAInt *varying); SSAVec4i ProcessPixel32(SSAVec4i bg, SSAInt *varying, bool isSimpleShade);
SSAInt ProcessPixel8(SSAInt bg, SSAInt *varying); SSAInt ProcessPixel8(SSAInt bg, SSAInt *varying);
SSAVec4i TranslateSample32(SSAInt *varying); SSAVec4i TranslateSample32(SSAInt *varying);
SSAInt TranslateSample8(SSAInt *varying); SSAInt TranslateSample8(SSAInt *varying);
SSAVec4i Sample32(SSAInt *varying); SSAVec4i Sample32(SSAInt *varying);
SSAInt Sample8(SSAInt *varying); SSAInt Sample8(SSAInt *varying);
SSAVec4i Shade32(SSAVec4i fg, SSAInt light, bool isSimpleShade);
SSAInt Shade8(SSAInt c); SSAInt Shade8(SSAInt c);
SSAVec4i ToBgra(SSAInt index); SSAVec4i ToBgra(SSAInt index);
SSAInt ToPal8(SSAVec4i c); SSAInt ToPal8(SSAVec4i c);