Skip to content

Commit

Permalink
Select fragment shader once per triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Dec 8, 2019
1 parent f7ae955 commit 42720f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/rendering/polyrenderer/drawers/poly_triangle.h
Expand Up @@ -272,6 +272,7 @@ class PolyTriangleThreadData
uint8_t StencilTestValue = 0;
uint8_t StencilWriteValue = 0;

void (*FragmentShader)(int x0, int x1, PolyTriangleThreadData* thread) = nullptr;
void (*WriteColorFunc)(int y, int x0, int x1, PolyTriangleThreadData* thread) = nullptr;

private:
Expand Down
54 changes: 32 additions & 22 deletions src/rendering/polyrenderer/drawers/screen_triangle.cpp
Expand Up @@ -88,7 +88,7 @@ static void WriteW(int y, int x0, int x1, const TriDrawTriangleArgs* args, PolyT
}
#endif

static void WriteDynLightArray(int y, int x0, int x1, const TriDrawTriangleArgs* args, PolyTriangleThreadData* thread)
static void WriteDynLightArray(int x0, int x1, PolyTriangleThreadData* thread)
{
int num_lights = thread->numPolyLights;
PolyLight* lights = thread->polyLights;
Expand Down Expand Up @@ -1088,24 +1088,12 @@ static void ApplyVertexColor(int x0, int x1, PolyTriangleThreadData* thread)
}
}

static void RunShader(int x0, int x1, PolyTriangleThreadData* thread)
static void MainFP(int x0, int x1, PolyTriangleThreadData* thread)
{
if (thread->SpecialEffect == EFF_FOGBOUNDARY) // fogboundary.fp
{
EffectFogBoundary(x0, x1, thread);
return;
}
else if (thread->SpecialEffect == EFF_BURN) // burn.fp
{
EffectBurn(x0, x1, thread);
return;
}
else if (thread->SpecialEffect == EFF_STENCIL) // stencil.fp
{
EffectStencil(x0, x1, thread);
return;
}
else if (thread->EffectState == SHADER_Paletted) // func_paletted
if (thread->numPolyLights > 0)
WriteDynLightArray(x0, x1, thread);

if (thread->EffectState == SHADER_Paletted) // func_paletted
{
FuncPaletted(x0, x1, thread);
}
Expand Down Expand Up @@ -1219,17 +1207,38 @@ static void RunShader(int x0, int x1, PolyTriangleThreadData* thread)
}
}

static void SelectFragmentShader(PolyTriangleThreadData* thread)
{
void (*fragshader)(int x0, int x1, PolyTriangleThreadData * thread);

if (thread->SpecialEffect == EFF_FOGBOUNDARY) // fogboundary.fp
{
fragshader = &EffectFogBoundary;
}
else if (thread->SpecialEffect == EFF_BURN) // burn.fp
{
fragshader = &EffectBurn;
}
else if (thread->SpecialEffect == EFF_STENCIL) // stencil.fp
{
fragshader = &EffectStencil;
}
else
{
fragshader = &MainFP;
}

thread->FragmentShader = fragshader;
}

static void DrawSpan(int y, int x0, int x1, const TriDrawTriangleArgs* args, PolyTriangleThreadData* thread)
{
WriteVaryings(y, x0, x1, args, thread);

if (thread->PushConstants->uLightLevel >= 0.0f)
WriteLightArray(y, x0, x1, args, thread);

if (thread->numPolyLights > 0)
WriteDynLightArray(y, x0, x1, args, thread);

RunShader(x0, x1, thread);
thread->FragmentShader(x0, x1, thread);

if (thread->WriteColor)
thread->WriteColorFunc(y, x0, x1, thread);
Expand Down Expand Up @@ -1362,6 +1371,7 @@ void ScreenTriangle::Draw(const TriDrawTriangleArgs* args, PolyTriangleThreadDat
if (topY >= bottomY)
return;

SelectFragmentShader(thread);
SelectWriteColorFunc(thread);

void(*testfunc)(int y, int x0, int x1, const TriDrawTriangleArgs * args, PolyTriangleThreadData * thread);
Expand Down

0 comments on commit 42720f8

Please sign in to comment.