mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-12-03 09:23:19 +00:00
- tell softpoly backend which hwrenderer shader is active and use that to decide which drawer to use
This commit is contained in:
parent
bd591c75fb
commit
555beb58f0
5 changed files with 135 additions and 47 deletions
|
@ -541,6 +541,13 @@ void PolyFrameBuffer::BeginFrame()
|
|||
{
|
||||
SetViewportRects(nullptr);
|
||||
CheckCanvas();
|
||||
|
||||
swrenderer::R_InitFuzzTable(GetCanvas()->GetPitch());
|
||||
static int next_random = 0;
|
||||
swrenderer::fuzzpos = (swrenderer::fuzzpos + swrenderer::fuzz_random_x_offset[next_random] * FUZZTABLE / 100) % FUZZTABLE;
|
||||
next_random++;
|
||||
if (next_random == FUZZ_RANDOM_X_SIZE)
|
||||
next_random = 0;
|
||||
}
|
||||
|
||||
void PolyFrameBuffer::Draw2D()
|
||||
|
|
|
@ -190,6 +190,16 @@ void PolyRenderState::Apply()
|
|||
PolyTriangleDrawer::SetInputAssembly(fb->GetDrawCommands(), static_cast<PolyVertexBuffer*>(mVertexBuffer)->VertexFormat);
|
||||
PolyTriangleDrawer::SetRenderStyle(fb->GetDrawCommands(), mRenderStyle);
|
||||
|
||||
if (mSpecialEffect > EFF_NONE)
|
||||
{
|
||||
PolyTriangleDrawer::SetShader(fb->GetDrawCommands(), mSpecialEffect, 0, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
int effectState = mMaterial.mOverrideShader >= 0 ? mMaterial.mOverrideShader : (mMaterial.mMaterial ? mMaterial.mMaterial->GetShaderIndex() : 0);
|
||||
PolyTriangleDrawer::SetShader(fb->GetDrawCommands(), EFF_NONE, mTextureEnabled ? effectState : SHADER_NoTexture, mAlphaThreshold >= 0.f);
|
||||
}
|
||||
|
||||
PolyPushConstants constants;
|
||||
constants.uFogEnabled = fogset;
|
||||
constants.uTextureMode = mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode;
|
||||
|
|
|
@ -189,6 +189,11 @@ void PolyTriangleDrawer::SetTexture(const DrawerCommandQueuePtr &queue, void *pi
|
|||
queue->Push<PolySetTextureCommand>(pixels, width, height);
|
||||
}
|
||||
|
||||
void PolyTriangleDrawer::SetShader(const DrawerCommandQueuePtr &queue, int specialEffect, int effectState, bool alphaTest)
|
||||
{
|
||||
queue->Push<PolySetShaderCommand>(specialEffect, effectState, alphaTest);
|
||||
}
|
||||
|
||||
void PolyTriangleDrawer::PushStreamData(const DrawerCommandQueuePtr &queue, const StreamData &data, const PolyPushConstants &constants)
|
||||
{
|
||||
queue->Push<PolyPushStreamDataCommand>(data, constants);
|
||||
|
@ -304,11 +309,80 @@ void PolyTriangleThreadData::PushStreamData(const StreamData &data, const PolyPu
|
|||
cm.Clear();
|
||||
drawargs.SetLight(GetColorTable(cm), (int)(constants.uLightLevel * 255.0f), mainVertexShader.Viewpoint->mGlobVis * 32.0f, false);
|
||||
|
||||
drawargs.SetColor(MAKEARGB(
|
||||
static_cast<uint32_t>(mainVertexShader.Data.uVertexColor.W * 255.0f + 0.5f),
|
||||
static_cast<uint32_t>(mainVertexShader.Data.uVertexColor.X * 255.0f + 0.5f),
|
||||
static_cast<uint32_t>(mainVertexShader.Data.uVertexColor.Y * 255.0f + 0.5f),
|
||||
static_cast<uint32_t>(mainVertexShader.Data.uVertexColor.Z * 255.0f + 0.5f)), 0);
|
||||
if (SpecialEffect != EFF_NONE)
|
||||
{
|
||||
// To do: need new drawers for these
|
||||
switch (SpecialEffect)
|
||||
{
|
||||
default: break;
|
||||
case EFF_FOGBOUNDARY: drawargs.SetStyle(TriBlendMode::FogBoundary); break;
|
||||
case EFF_SPHEREMAP: drawargs.SetStyle(TriBlendMode::Fill); break;
|
||||
case EFF_BURN: drawargs.SetStyle(TriBlendMode::Fill); break;
|
||||
case EFF_STENCIL: drawargs.SetStyle(TriBlendMode::Fill); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (EffectState)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case SHADER_Paletted:
|
||||
break;
|
||||
case SHADER_NoTexture:
|
||||
drawargs.SetStyle(TriBlendMode::Fill);
|
||||
drawargs.SetColor(MAKEARGB(
|
||||
static_cast<uint32_t>(mainVertexShader.Data.uVertexColor.W * 255.0f + 0.5f),
|
||||
static_cast<uint32_t>(mainVertexShader.Data.uVertexColor.X * 255.0f + 0.5f),
|
||||
static_cast<uint32_t>(mainVertexShader.Data.uVertexColor.Y * 255.0f + 0.5f),
|
||||
static_cast<uint32_t>(mainVertexShader.Data.uVertexColor.Z * 255.0f + 0.5f)), 0);
|
||||
return;
|
||||
case SHADER_BasicFuzz:
|
||||
case SHADER_SmoothFuzz:
|
||||
case SHADER_SwirlyFuzz:
|
||||
case SHADER_TranslucentFuzz:
|
||||
case SHADER_JaggedFuzz:
|
||||
case SHADER_NoiseFuzz:
|
||||
case SHADER_SmoothNoiseFuzz:
|
||||
case SHADER_SoftwareFuzz:
|
||||
drawargs.SetStyle(TriBlendMode::Fuzzy);
|
||||
drawargs.SetColor(0xff000000, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
auto style = RenderStyle;
|
||||
if (style.BlendOp == STYLEOP_Add && style.SrcAlpha == STYLEALPHA_One && style.DestAlpha == STYLEALPHA_Zero)
|
||||
{
|
||||
drawargs.SetStyle(AlphaTest ? TriBlendMode::Normal : TriBlendMode::Opaque);
|
||||
}
|
||||
else if (style.BlendOp == STYLEOP_Add && style.SrcAlpha == STYLEALPHA_Src && style.DestAlpha == STYLEALPHA_InvSrc)
|
||||
{
|
||||
drawargs.SetStyle(TriBlendMode::Normal);
|
||||
}
|
||||
else if (style.BlendOp == STYLEOP_Add && style.SrcAlpha == STYLEALPHA_SrcCol && style.DestAlpha == STYLEALPHA_One)
|
||||
{
|
||||
drawargs.SetStyle(TriBlendMode::SrcColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (style == LegacyRenderStyles[STYLE_Normal]) drawargs.SetStyle(TriBlendMode::Normal);
|
||||
else if (style == LegacyRenderStyles[STYLE_Stencil]) drawargs.SetStyle(TriBlendMode::Stencil);
|
||||
else if (style == LegacyRenderStyles[STYLE_Translucent]) drawargs.SetStyle(TriBlendMode::Translucent);
|
||||
else if (style == LegacyRenderStyles[STYLE_Add]) drawargs.SetStyle(TriBlendMode::Add);
|
||||
//else if (style == LegacyRenderStyles[STYLE_Shaded]) drawargs.SetStyle(TriBlendMode::Shaded);
|
||||
else if (style == LegacyRenderStyles[STYLE_TranslucentStencil]) drawargs.SetStyle(TriBlendMode::TranslucentStencil);
|
||||
else if (style == LegacyRenderStyles[STYLE_Shadow]) drawargs.SetStyle(TriBlendMode::Shadow);
|
||||
else if (style == LegacyRenderStyles[STYLE_Subtract]) drawargs.SetStyle(TriBlendMode::Subtract);
|
||||
else if (style == LegacyRenderStyles[STYLE_AddStencil]) drawargs.SetStyle(TriBlendMode::AddStencil);
|
||||
else if (style == LegacyRenderStyles[STYLE_AddShaded]) drawargs.SetStyle(TriBlendMode::AddShaded);
|
||||
//else if (style == LegacyRenderStyles[STYLE_Multiply]) drawargs.SetStyle(TriBlendMode::Multiply);
|
||||
//else if (style == LegacyRenderStyles[STYLE_InverseMultiply]) drawargs.SetStyle(TriBlendMode::InverseMultiply);
|
||||
//else if (style == LegacyRenderStyles[STYLE_ColorBlend]) drawargs.SetStyle(TriBlendMode::ColorBlend);
|
||||
else if (style == LegacyRenderStyles[STYLE_Source]) drawargs.SetStyle(TriBlendMode::Opaque);
|
||||
//else if (style == LegacyRenderStyles[STYLE_ColorAdd]) drawargs.SetStyle(TriBlendMode::ColorAdd);
|
||||
else drawargs.SetStyle(TriBlendMode::Opaque);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PolyTriangleThreadData::PushMatrices(const VSMatrix &modelMatrix, const VSMatrix &normalModelMatrix, const VSMatrix &textureMatrix)
|
||||
|
@ -334,6 +408,14 @@ void PolyTriangleThreadData::SetDepthMask(bool on)
|
|||
|
||||
void PolyTriangleThreadData::SetDepthFunc(int func)
|
||||
{
|
||||
if (func == DF_LEqual || func == DF_Less)
|
||||
{
|
||||
drawargs.SetDepthTest(true);
|
||||
}
|
||||
else if (func == DF_Always)
|
||||
{
|
||||
drawargs.SetDepthTest(false);
|
||||
}
|
||||
}
|
||||
|
||||
void PolyTriangleThreadData::SetDepthRange(float min, float max)
|
||||
|
@ -397,44 +479,14 @@ void PolyTriangleThreadData::EnableDepthTest(bool on)
|
|||
|
||||
void PolyTriangleThreadData::SetRenderStyle(FRenderStyle style)
|
||||
{
|
||||
if (style.BlendOp == STYLEOP_Add && style.SrcAlpha == STYLEALPHA_One && style.DestAlpha == STYLEALPHA_Zero && style.Flags == 0)
|
||||
{
|
||||
drawargs.SetStyle(TriBlendMode::Opaque);
|
||||
}
|
||||
else if (style.BlendOp == STYLEOP_Add && style.SrcAlpha == STYLEALPHA_Src && style.DestAlpha == STYLEALPHA_InvSrc)
|
||||
{
|
||||
drawargs.SetStyle(TriBlendMode::Normal);
|
||||
}
|
||||
else if (style.BlendOp == STYLEOP_Add && style.SrcAlpha == STYLEALPHA_One && style.DestAlpha == STYLEALPHA_Zero)
|
||||
{
|
||||
drawargs.SetStyle(TriBlendMode::Normal);
|
||||
}
|
||||
else if (style.BlendOp == STYLEOP_Add && style.SrcAlpha == STYLEALPHA_SrcCol && style.DestAlpha == STYLEALPHA_One)
|
||||
{
|
||||
drawargs.SetStyle(TriBlendMode::SrcColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (style == LegacyRenderStyles[STYLE_Normal]) drawargs.SetStyle(TriBlendMode::Normal);
|
||||
else if (style == LegacyRenderStyles[STYLE_Fuzzy]) drawargs.SetStyle(TriBlendMode::Fuzzy);
|
||||
//else if (style == LegacyRenderStyles[STYLE_SoulTrans]) drawargs.SetStyle(TriBlendMode::SoulTrans);
|
||||
//else if (style == LegacyRenderStyles[STYLE_OptFuzzy]) drawargs.SetStyle(TriBlendMode::OptFuzzy);
|
||||
else if (style == LegacyRenderStyles[STYLE_Stencil]) drawargs.SetStyle(TriBlendMode::Stencil);
|
||||
else if (style == LegacyRenderStyles[STYLE_Translucent]) drawargs.SetStyle(TriBlendMode::Translucent);
|
||||
else if (style == LegacyRenderStyles[STYLE_Add]) drawargs.SetStyle(TriBlendMode::Add);
|
||||
//else if (style == LegacyRenderStyles[STYLE_Shaded]) drawargs.SetStyle(TriBlendMode::Shaded);
|
||||
else if (style == LegacyRenderStyles[STYLE_TranslucentStencil]) drawargs.SetStyle(TriBlendMode::TranslucentStencil);
|
||||
else if (style == LegacyRenderStyles[STYLE_Shadow]) drawargs.SetStyle(TriBlendMode::Shadow);
|
||||
else if (style == LegacyRenderStyles[STYLE_Subtract]) drawargs.SetStyle(TriBlendMode::Subtract);
|
||||
else if (style == LegacyRenderStyles[STYLE_AddStencil]) drawargs.SetStyle(TriBlendMode::AddStencil);
|
||||
else if (style == LegacyRenderStyles[STYLE_AddShaded]) drawargs.SetStyle(TriBlendMode::AddShaded);
|
||||
//else if (style == LegacyRenderStyles[STYLE_Multiply]) drawargs.SetStyle(TriBlendMode::Multiply);
|
||||
//else if (style == LegacyRenderStyles[STYLE_InverseMultiply]) drawargs.SetStyle(TriBlendMode::InverseMultiply);
|
||||
//else if (style == LegacyRenderStyles[STYLE_ColorBlend]) drawargs.SetStyle(TriBlendMode::ColorBlend);
|
||||
//else if (style == LegacyRenderStyles[STYLE_Source]) drawargs.SetStyle(TriBlendMode::Source);
|
||||
//else if (style == LegacyRenderStyles[STYLE_ColorAdd]) drawargs.SetStyle(TriBlendMode::ColorAdd);
|
||||
else drawargs.SetStyle(TriBlendMode::Opaque);
|
||||
}
|
||||
RenderStyle = style;
|
||||
}
|
||||
|
||||
void PolyTriangleThreadData::SetShader(int specialEffect, int effectState, bool alphaTest)
|
||||
{
|
||||
SpecialEffect = specialEffect;
|
||||
EffectState = effectState;
|
||||
AlphaTest = alphaTest;
|
||||
}
|
||||
|
||||
void PolyTriangleThreadData::SetTexture(void *pixels, int width, int height)
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
static void EnableDepthTest(const DrawerCommandQueuePtr &queue, bool on);
|
||||
static void SetRenderStyle(const DrawerCommandQueuePtr &queue, FRenderStyle style);
|
||||
static void SetTexture(const DrawerCommandQueuePtr &queue, void *pixels, int width, int height);
|
||||
static void SetShader(const DrawerCommandQueuePtr &queue, int specialEffect, int effectState, bool alphaTest);
|
||||
static void PushStreamData(const DrawerCommandQueuePtr &queue, const StreamData &data, const PolyPushConstants &constants);
|
||||
static void PushMatrices(const DrawerCommandQueuePtr &queue, const VSMatrix &modelMatrix, const VSMatrix &normalModelMatrix, const VSMatrix &textureMatrix);
|
||||
static void Draw(const DrawerCommandQueuePtr &queue, int index, int vcount, PolyDrawMode mode = PolyDrawMode::Triangles);
|
||||
|
@ -142,6 +143,7 @@ public:
|
|||
void EnableDepthTest(bool on);
|
||||
void SetRenderStyle(FRenderStyle style);
|
||||
void SetTexture(void *pixels, int width, int height);
|
||||
void SetShader(int specialEffect, int effectState, bool alphaTest);
|
||||
|
||||
void UpdateClip();
|
||||
|
||||
|
@ -208,6 +210,11 @@ public:
|
|||
int bottom = 0;
|
||||
} clip, scissor;
|
||||
|
||||
FRenderStyle RenderStyle;
|
||||
int SpecialEffect = EFF_NONE;
|
||||
int EffectState = 0;
|
||||
bool AlphaTest = false;
|
||||
|
||||
PolyDrawArgs drawargs;
|
||||
|
||||
const void *vertices = nullptr;
|
||||
|
@ -396,6 +403,18 @@ private:
|
|||
int height;
|
||||
};
|
||||
|
||||
class PolySetShaderCommand : public PolyDrawerCommand
|
||||
{
|
||||
public:
|
||||
PolySetShaderCommand(int specialEffect, int effectState, bool alphaTest) : specialEffect(specialEffect), effectState(effectState), alphaTest(alphaTest) { }
|
||||
void Execute(DrawerThread *thread) override { PolyTriangleThreadData::Get(thread)->SetShader(specialEffect, effectState, alphaTest); }
|
||||
|
||||
private:
|
||||
int specialEffect;
|
||||
int effectState;
|
||||
bool alphaTest;
|
||||
};
|
||||
|
||||
class PolySetVertexBufferCommand : public PolyDrawerCommand
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -887,7 +887,7 @@ void DrawSpanOpt32(int y, int x0, int x1, const TriDrawTriangleArgs *args, PolyT
|
|||
|
||||
if (ModeT::BlendOp == STYLEOP_Fuzz)
|
||||
{
|
||||
fuzzscale = (200 << FRACBITS) / viewheight;
|
||||
fuzzscale = (200 << FRACBITS) / thread->dest_height;
|
||||
_fuzzpos = swrenderer::fuzzpos;
|
||||
}
|
||||
|
||||
|
@ -1314,7 +1314,7 @@ void DrawSpanOpt8(int y, int x0, int x1, const TriDrawTriangleArgs *args, PolyTr
|
|||
|
||||
if (ModeT::BlendOp == STYLEOP_Fuzz)
|
||||
{
|
||||
fuzzscale = (200 << FRACBITS) / viewheight;
|
||||
fuzzscale = (200 << FRACBITS) / thread->dest_height;
|
||||
_fuzzpos = swrenderer::fuzzpos;
|
||||
}
|
||||
|
||||
|
@ -1626,7 +1626,7 @@ void DrawRect8(const void *destOrg, int destWidth, int destHeight, int destPitch
|
|||
int _fuzzpos;
|
||||
if (ModeT::BlendOp == STYLEOP_Fuzz)
|
||||
{
|
||||
fuzzscale = (200 << FRACBITS) / viewheight;
|
||||
fuzzscale = (200 << FRACBITS) / thread->dest_height;
|
||||
_fuzzpos = swrenderer::fuzzpos;
|
||||
}
|
||||
|
||||
|
@ -1877,7 +1877,7 @@ void DrawRectOpt32(const void *destOrg, int destWidth, int destHeight, int destP
|
|||
int _fuzzpos;
|
||||
if (ModeT::BlendOp == STYLEOP_Fuzz)
|
||||
{
|
||||
fuzzscale = (200 << FRACBITS) / viewheight;
|
||||
fuzzscale = (200 << FRACBITS) / thread->dest_height;
|
||||
_fuzzpos = swrenderer::fuzzpos;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue