- Add new drawer: AddClampShadedSprite

- fixed: AddShaded did not have a drawer associated with it in the software renderer - used new drawer for this purpose.
This commit is contained in:
Rachael Alexanderson 2017-03-15 14:28:16 -04:00
parent d0c77d7264
commit a2fc2fb707
7 changed files with 69 additions and 3 deletions

View file

@ -71,6 +71,7 @@ namespace swrenderer
virtual void DrawTranslatedColumn(const SpriteDrawerArgs &args) = 0;
virtual void DrawTranslatedAddColumn(const SpriteDrawerArgs &args) = 0;
virtual void DrawShadedColumn(const SpriteDrawerArgs &args) = 0;
virtual void DrawAddClampShadedColumn(const SpriteDrawerArgs &args) = 0;
virtual void DrawAddClampColumn(const SpriteDrawerArgs &args) = 0;
virtual void DrawAddClampTranslatedColumn(const SpriteDrawerArgs &args) = 0;
virtual void DrawSubClampColumn(const SpriteDrawerArgs &args) = 0;

View file

@ -1412,6 +1412,48 @@ namespace swrenderer
}
}
void DrawColumnAddClampShadedPalCommand::Execute(DrawerThread *thread)
{
int count;
uint8_t *dest;
fixed_t frac, fracstep;
count = args.Count();
dest = args.Dest();
fracstep = args.TextureVStep();
frac = args.TextureVPos();
count = thread->count_for_thread(args.DestY(), count);
if (count <= 0)
return;
int pitch = args.Viewport()->RenderTarget->GetPitch();
dest = thread->dest_for_thread(args.DestY(), pitch, dest);
frac += fracstep * thread->skipped_by_thread(args.DestY());
fracstep *= thread->num_cores;
pitch *= thread->num_cores;
const uint8_t *source = args.TexturePixels();
const uint8_t *colormap = args.Colormap(args.Viewport());
//uint32_t *fgstart = &Col2RGB8[0][args.SolidColor()]; // if someone wants to write the 555's, be my guest.
const PalEntry *palette = GPalette.BaseColors;
int color = args.SolidColor();
do
{
uint32_t val = source[frac >> FRACBITS];
int r = (palette[*dest].r * (255) + palette[color].r * val) >> 10;
int g = (palette[*dest].g * (255) + palette[color].g * val) >> 10;
int b = (palette[*dest].b * (255) + 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)
{
int count;

View file

@ -65,6 +65,7 @@ namespace swrenderer
class DrawColumnTranslatedPalCommand : public PalColumnCommand { public: using PalColumnCommand::PalColumnCommand; void Execute(DrawerThread *thread) override; };
class DrawColumnTlatedAddPalCommand : public PalColumnCommand { public: using PalColumnCommand::PalColumnCommand; void Execute(DrawerThread *thread) override; };
class DrawColumnShadedPalCommand : public PalColumnCommand { public: using PalColumnCommand::PalColumnCommand; void Execute(DrawerThread *thread) override; };
class DrawColumnAddClampShadedPalCommand : public PalColumnCommand { public: using PalColumnCommand::PalColumnCommand; void Execute(DrawerThread *thread) override; };
class DrawColumnAddClampPalCommand : public PalColumnCommand { public: using PalColumnCommand::PalColumnCommand; void Execute(DrawerThread *thread) override; };
class DrawColumnAddClampTranslatedPalCommand : public PalColumnCommand { public: using PalColumnCommand::PalColumnCommand; void Execute(DrawerThread *thread) override; };
class DrawColumnSubClampPalCommand : public PalColumnCommand { public: using PalColumnCommand::PalColumnCommand; void Execute(DrawerThread *thread) override; };
@ -236,6 +237,7 @@ namespace swrenderer
void DrawTranslatedColumn(const SpriteDrawerArgs &args) override { Queue->Push<DrawColumnTranslatedPalCommand>(args); }
void DrawTranslatedAddColumn(const SpriteDrawerArgs &args) override { Queue->Push<DrawColumnTlatedAddPalCommand>(args); }
void DrawShadedColumn(const SpriteDrawerArgs &args) override { Queue->Push<DrawColumnShadedPalCommand>(args); }
void DrawAddClampShadedColumn(const SpriteDrawerArgs &args) override { Queue->Push<DrawColumnAddClampShadedPalCommand>(args); }
void DrawAddClampColumn(const SpriteDrawerArgs &args) override { Queue->Push<DrawColumnAddClampPalCommand>(args); }
void DrawAddClampTranslatedColumn(const SpriteDrawerArgs &args) override { Queue->Push<DrawColumnAddClampTranslatedPalCommand>(args); }
void DrawSubClampColumn(const SpriteDrawerArgs &args) override { Queue->Push<DrawColumnSubClampPalCommand>(args); }

View file

@ -156,6 +156,11 @@ namespace swrenderer
Queue->Push<DrawSpriteShaded32Command>(args);
}
void SWTruecolorDrawers::DrawAddClampShadedColumn(const SpriteDrawerArgs &args)
{
Queue->Push<DrawSpriteAddClampShaded32Command>(args);
}
void SWTruecolorDrawers::DrawAddClampColumn(const SpriteDrawerArgs &args)
{
Queue->Push<DrawSpriteAddClamp32Command>(args);

View file

@ -243,6 +243,7 @@ namespace swrenderer
void DrawTranslatedColumn(const SpriteDrawerArgs &args) override;
void DrawTranslatedAddColumn(const SpriteDrawerArgs &args) override;
void DrawShadedColumn(const SpriteDrawerArgs &args) override;
void DrawAddClampShadedColumn(const SpriteDrawerArgs &args) override;
void DrawAddClampColumn(const SpriteDrawerArgs &args) override;
void DrawAddClampTranslatedColumn(const SpriteDrawerArgs &args) override;
void DrawSubClampColumn(const SpriteDrawerArgs &args) override;

View file

@ -29,10 +29,11 @@ namespace swrenderer
{
namespace DrawSprite32TModes
{
enum class SpriteBlendModes { Copy, Opaque, Shaded, AddClamp, SubClamp, RevSubClamp };
enum class SpriteBlendModes { Copy, Opaque, Shaded, AddClampShaded, AddClamp, SubClamp, RevSubClamp };
struct CopySprite { static const int Mode = (int)SpriteBlendModes::Copy; };
struct OpaqueSprite { static const int Mode = (int)SpriteBlendModes::Opaque; };
struct ShadedSprite { static const int Mode = (int)SpriteBlendModes::Shaded; };
struct AddClampShadedSprite { static const int Mode = (int)SpriteBlendModes::AddClampShaded; };
struct AddClampSprite { static const int Mode = (int)SpriteBlendModes::AddClamp; };
struct SubClampSprite { static const int Mode = (int)SpriteBlendModes::SubClamp; };
struct RevSubClampSprite { static const int Mode = (int)SpriteBlendModes::RevSubClamp; };
@ -381,6 +382,16 @@ namespace swrenderer
outcolor = _mm_or_si128(outcolor, _mm_set1_epi32(0xff000000));
return outcolor;
}
else if (BlendT::Mode == (int)SpriteBlendModes::AddClampShaded)
{
__m128i alpha = _mm_set_epi16(ifgshade1, ifgshade1, ifgshade1, ifgshade1, ifgshade0, ifgshade0, ifgshade0, ifgshade0);
fgcolor = _mm_srli_epi16(_mm_mullo_epi16(fgcolor, alpha), 8);
__m128i outcolor = _mm_add_epi16(fgcolor, bgcolor);
outcolor = _mm_packus_epi16(outcolor, _mm_setzero_si128());
outcolor = _mm_or_si128(outcolor, _mm_set1_epi32(0xff000000));
return outcolor;
}
else
{
uint32_t alpha0 = APART(ifgcolor0);
@ -448,6 +459,7 @@ namespace swrenderer
typedef DrawSprite32T<DrawSprite32TModes::RevSubClampSprite, DrawSprite32TModes::FillSampler> FillSpriteRevSubClamp32Command;
typedef DrawSprite32T<DrawSprite32TModes::ShadedSprite, DrawSprite32TModes::ShadedSampler> DrawSpriteShaded32Command;
typedef DrawSprite32T<DrawSprite32TModes::AddClampShadedSprite, DrawSprite32TModes::ShadedSampler> DrawSpriteAddClampShaded32Command;
typedef DrawSprite32T<DrawSprite32TModes::OpaqueSprite, DrawSprite32TModes::TranslatedSampler> DrawSpriteTranslated32Command;
typedef DrawSprite32T<DrawSprite32TModes::AddClampSprite, DrawSprite32TModes::TranslatedSampler> DrawSpriteTranslatedAddClamp32Command;

View file

@ -432,12 +432,15 @@ namespace swrenderer
colfunc = &SWPixelFormatDrawers::DrawFuzzColumn;
return true;
}
else if (style == LegacyRenderStyles[STYLE_Shaded])
else if (style == LegacyRenderStyles[STYLE_Shaded] || style == LegacyRenderStyles[STYLE_AddShaded])
{
// Shaded drawer only gets 16 levels of alpha because it saves memory.
if ((alpha >>= 12) == 0 || basecolormap == nullptr)
return false;
colfunc = &SWPixelFormatDrawers::DrawShadedColumn;
if (style == LegacyRenderStyles[STYLE_Shaded])
colfunc = &SWPixelFormatDrawers::DrawShadedColumn;
else
colfunc = &SWPixelFormatDrawers::DrawAddClampShadedColumn;
drawer_needs_pal_input = true;
CameraLight *cameraLight = CameraLight::Instance();
dc_color = cameraLight->FixedColormap() ? cameraLight->FixedColormap()->Maps[APART(color)] : basecolormap->Maps[APART(color)];