From adb65ce72a735997bf98f298332717a14e7619cc Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 16 Dec 2016 00:35:45 +0100 Subject: [PATCH] Remove TriDrawVariant --- src/r_drawers.h | 11 ------ src/r_poly_decal.cpp | 6 +++- src/r_poly_particle.cpp | 6 +++- src/r_poly_plane.cpp | 18 ++++++---- src/r_poly_scene.cpp | 11 +++--- src/r_poly_sky.cpp | 11 +++--- src/r_poly_sprite.cpp | 6 +++- src/r_poly_triangle.cpp | 76 ++++++++++----------------------------- src/r_poly_triangle.h | 14 +++++--- src/r_poly_wall.cpp | 16 ++++++--- src/r_poly_wallsprite.cpp | 6 +++- 11 files changed, 83 insertions(+), 98 deletions(-) diff --git a/src/r_drawers.h b/src/r_drawers.h index 543796609..102d3159f 100644 --- a/src/r_drawers.h +++ b/src/r_drawers.h @@ -251,17 +251,6 @@ struct TriDrawTriangleArgs const uint8_t *BaseColors; }; -enum class TriDrawVariant -{ - DrawNormal, - FillNormal, - DrawSubsector, - FillSubsector, - FuzzSubsector, - Stencil, - StencilClose -}; - enum class TriBlendMode { Copy, // blend_copy(shade(fg)) diff --git a/src/r_poly_decal.cpp b/src/r_poly_decal.cpp index e91e25b58..7718d422e 100644 --- a/src/r_poly_decal.cpp +++ b/src/r_poly_decal.cpp @@ -167,5 +167,9 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan args.stencilwritevalue = stencilValue; //mode = R_SetPatchStyle (decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, TriBlendMode::Shaded); + args.blendmode = TriBlendMode::Shaded; + args.subsectorTest = true; + args.writeStencil = false; + args.writeSubsector = false; + PolyTriangleDrawer::draw(args); } diff --git a/src/r_poly_particle.cpp b/src/r_poly_particle.cpp index 0d31614d2..27888e77b 100644 --- a/src/r_poly_particle.cpp +++ b/src/r_poly_particle.cpp @@ -105,5 +105,9 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const Vec4f &clipP args.stencilwritevalue = stencilValue; args.SetColormap(sub->sector->ColorMap); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); - PolyTriangleDrawer::draw(args, TriDrawVariant::FillSubsector, TriBlendMode::AlphaBlend); + args.subsectorTest = true; + args.writeStencil = false; + args.writeSubsector = false; + args.blendmode = TriBlendMode::AlphaBlend; + PolyTriangleDrawer::draw(args); } diff --git a/src/r_poly_plane.cpp b/src/r_poly_plane.cpp index c7f011a76..e21868dc2 100644 --- a/src/r_poly_plane.cpp +++ b/src/r_poly_plane.cpp @@ -143,8 +143,8 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const Vec4f &c args.SetTexture(tex); args.SetColormap(sub->sector->ColorMap); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawNormal, TriBlendMode::Copy); - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); + args.blendmode = TriBlendMode::Copy; + PolyTriangleDrawer::draw(args); } void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector> §orPortals) @@ -341,13 +341,15 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan if (!portal) { args.SetTexture(tex); - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawNormal, TriBlendMode::Copy); - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); + args.blendmode = TriBlendMode::Copy; + PolyTriangleDrawer::draw(args); } else { args.stencilwritevalue = polyportal->StencilValue; - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); + args.writeColor = false; + args.writeSubsector = false; + PolyTriangleDrawer::draw(args); polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth }); polyportal->Segments.insert(polyportal->Segments.end(), portalSegments.begin(), portalSegments.end()); } @@ -365,7 +367,9 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan args.stencilwritevalue = 255; } - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); + args.writeColor = false; + args.writeSubsector = false; + PolyTriangleDrawer::draw(args); for (uint32_t i = 0; i < sub->numlines; i++) { @@ -433,7 +437,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const Vec4f &clipPlan args.vinput = wallvert; args.vcount = 4; - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); + PolyTriangleDrawer::draw(args); if (portal) { diff --git a/src/r_poly_scene.cpp b/src/r_poly_scene.cpp index c0697f55e..cfb858e0b 100644 --- a/src/r_poly_scene.cpp +++ b/src/r_poly_scene.cpp @@ -255,7 +255,8 @@ void RenderPolyScene::RenderPortals(int portalDepth) args.vcount = verts.Count; args.ccw = verts.Ccw; args.uniforms.subsectorDepth = verts.SubsectorDepth; - PolyTriangleDrawer::draw(args, TriDrawVariant::FillNormal, TriBlendMode::Copy); + args.blendmode = TriBlendMode::Copy; + PolyTriangleDrawer::draw(args); } } @@ -269,7 +270,7 @@ void RenderPolyScene::RenderPortals(int portalDepth) args.vcount = verts.Count; args.ccw = verts.Ccw; args.uniforms.subsectorDepth = verts.SubsectorDepth; - PolyTriangleDrawer::draw(args, TriDrawVariant::FillNormal, TriBlendMode::Copy); + PolyTriangleDrawer::draw(args); } } } @@ -296,7 +297,8 @@ void RenderPolyScene::RenderTranslucent(int portalDepth) args.vcount = verts.Count; args.ccw = verts.Ccw; args.uniforms.subsectorDepth = verts.SubsectorDepth; - PolyTriangleDrawer::draw(args, TriDrawVariant::StencilClose, TriBlendMode::Copy); + args.writeColor = false; + PolyTriangleDrawer::draw(args); } } @@ -317,7 +319,8 @@ void RenderPolyScene::RenderTranslucent(int portalDepth) args.vcount = verts.Count; args.ccw = verts.Ccw; args.uniforms.subsectorDepth = verts.SubsectorDepth; - PolyTriangleDrawer::draw(args, TriDrawVariant::StencilClose, TriBlendMode::Copy); + args.writeColor = false; + PolyTriangleDrawer::draw(args); } } } diff --git a/src/r_poly_sky.cpp b/src/r_poly_sky.cpp index 823a510f2..d2ea632b8 100644 --- a/src/r_poly_sky.cpp +++ b/src/r_poly_sky.cpp @@ -59,13 +59,14 @@ void PolySkyDome::Render(const TriMatrix &worldToClip) args.objectToClip = &objectToClip; args.stenciltestvalue = 255; args.stencilwritevalue = 1; - args.SetTexture(frontskytex); args.SetColormap(&NormalLight); args.SetClipPlane(0.0f, 0.0f, 0.0f, 0.0f); RenderCapColorRow(args, frontskytex, 0, false); RenderCapColorRow(args, frontskytex, rc, true); + args.SetTexture(frontskytex); + uint32_t topcapcolor = frontskytex->GetSkyCapColor(false); uint32_t bottomcapcolor = frontskytex->GetSkyCapColor(true); @@ -83,8 +84,8 @@ void PolySkyDome::RenderRow(PolyDrawArgs &args, int row, uint32_t capcolor) args.mode = TriangleDrawMode::Strip; args.ccw = false; args.uniforms.color = capcolor; - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawNormal, TriBlendMode::Skycap); - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Skycap); + args.blendmode = TriBlendMode::Skycap; + PolyTriangleDrawer::draw(args); } void PolySkyDome::RenderCapColorRow(PolyDrawArgs &args, FTexture *skytex, int row, bool bottomCap) @@ -98,8 +99,8 @@ void PolySkyDome::RenderCapColorRow(PolyDrawArgs &args, FTexture *skytex, int ro args.mode = TriangleDrawMode::Fan; args.ccw = bottomCap; args.uniforms.color = solid; - PolyTriangleDrawer::draw(args, TriDrawVariant::FillNormal, TriBlendMode::Copy); - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); + args.blendmode = TriBlendMode::Copy; + PolyTriangleDrawer::draw(args); } void PolySkyDome::CreateDome() diff --git a/src/r_poly_sprite.cpp b/src/r_poly_sprite.cpp index e5d8e0ce5..2cb285298 100644 --- a/src/r_poly_sprite.cpp +++ b/src/r_poly_sprite.cpp @@ -258,7 +258,11 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const Vec4f &clipPla blendmode = TriBlendMode::Add; } - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, blendmode); + args.subsectorTest = true; + args.writeSubsector = false; + args.writeStencil = false; + args.blendmode = blendmode; + PolyTriangleDrawer::draw(args); } bool RenderPolySprite::IsThingCulled(AActor *thing) diff --git a/src/r_poly_triangle.cpp b/src/r_poly_triangle.cpp index 90f78b639..1edd73c71 100644 --- a/src/r_poly_triangle.cpp +++ b/src/r_poly_triangle.cpp @@ -77,12 +77,12 @@ void PolyTriangleDrawer::toggle_mirror() mirror = !mirror; } -void PolyTriangleDrawer::draw(const PolyDrawArgs &args, TriDrawVariant variant, TriBlendMode blendmode) +void PolyTriangleDrawer::draw(const PolyDrawArgs &args) { - DrawerCommandQueue::QueueCommand(args, variant, blendmode, mirror); + DrawerCommandQueue::QueueCommand(args, mirror); } -void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, TriDrawVariant variant, TriBlendMode blendmode, WorkerThreadData *thread) +void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, WorkerThreadData *thread) { if (drawargs.vcount < 3) return; @@ -92,46 +92,20 @@ void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, TriDrawVarian PolyDrawFuncPtr drawfuncs[3]; int num_drawfuncs = 0; - int bmode = (int)blendmode; - switch (variant) - { - case TriDrawVariant::DrawNormal: - drawfuncs[num_drawfuncs++] = &ScreenTriangle::SetupNormal; + drawfuncs[num_drawfuncs++] = drawargs.subsectorTest ? &ScreenTriangle::SetupSubsector : &ScreenTriangle::SetupNormal; + + int bmode = (int)drawargs.blendmode; + if (drawargs.writeColor && drawargs.texturePixels) drawfuncs[num_drawfuncs++] = dest_bgra ? llvm->TriDraw32[bmode] : llvm->TriDraw8[bmode]; - drawfuncs[num_drawfuncs++] = &ScreenTriangle::SubsectorWrite; - break; - - case TriDrawVariant::FillNormal: - drawfuncs[num_drawfuncs++] = &ScreenTriangle::SetupNormal; + else if (drawargs.writeColor) drawfuncs[num_drawfuncs++] = dest_bgra ? llvm->TriFill32[bmode] : llvm->TriFill8[bmode]; - drawfuncs[num_drawfuncs++] = &ScreenTriangle::SubsectorWrite; - break; - - case TriDrawVariant::DrawSubsector: - drawfuncs[num_drawfuncs++] = &ScreenTriangle::SetupSubsector; - drawfuncs[num_drawfuncs++] = dest_bgra ? llvm->TriDraw32[bmode] : llvm->TriDraw8[bmode]; - break; - - case TriDrawVariant::FillSubsector: - drawfuncs[num_drawfuncs++] = &ScreenTriangle::SetupSubsector; - drawfuncs[num_drawfuncs++] = dest_bgra ? llvm->TriFill32[bmode] : llvm->TriFill8[bmode]; - break; - - case TriDrawVariant::Stencil: - drawfuncs[num_drawfuncs++] = &ScreenTriangle::SetupNormal; - drawfuncs[num_drawfuncs++] = &ScreenTriangle::StencilWrite; - break; - - case TriDrawVariant::StencilClose: - drawfuncs[num_drawfuncs++] = &ScreenTriangle::SetupNormal; + + if (drawargs.writeStencil) drawfuncs[num_drawfuncs++] = &ScreenTriangle::StencilWrite; + + if (drawargs.writeSubsector) drawfuncs[num_drawfuncs++] = &ScreenTriangle::SubsectorWrite; - break; - - default: - break; - } - + TriDrawTriangleArgs args; args.dest = dest; args.pitch = dest_pitch; @@ -384,8 +358,8 @@ void PolyTriangleDrawer::clipedge(const ShadedTriVertex *verts, TriVertex *clipp ///////////////////////////////////////////////////////////////////////////// -DrawPolyTrianglesCommand::DrawPolyTrianglesCommand(const PolyDrawArgs &args, TriDrawVariant variant, TriBlendMode blendmode, bool mirror) - : args(args), variant(variant), blendmode(blendmode) +DrawPolyTrianglesCommand::DrawPolyTrianglesCommand(const PolyDrawArgs &args, bool mirror) + : args(args) { if (mirror) this->args.ccw = !this->args.ccw; @@ -402,25 +376,13 @@ void DrawPolyTrianglesCommand::Execute(DrawerThread *thread) thread_data.FullSpans = thread->FullSpansBuffer.data(); thread_data.PartialBlocks = thread->PartialBlocksBuffer.data(); - PolyTriangleDrawer::draw_arrays(args, variant, blendmode, &thread_data); + PolyTriangleDrawer::draw_arrays(args, &thread_data); } FString DrawPolyTrianglesCommand::DebugInfo() { - FString variantstr; - switch (variant) - { - default: variantstr = "Unknown"; break; - case TriDrawVariant::DrawNormal: variantstr = "DrawNormal"; break; - case TriDrawVariant::FillNormal: variantstr = "FillNormal"; break; - case TriDrawVariant::DrawSubsector: variantstr = "DrawSubsector"; break; - case TriDrawVariant::FillSubsector: variantstr = "FillSubsector"; break; - case TriDrawVariant::FuzzSubsector: variantstr = "FuzzSubsector"; break; - case TriDrawVariant::Stencil: variantstr = "Stencil"; break; - } - FString blendmodestr; - switch (blendmode) + switch (args.blendmode) { default: blendmodestr = "Unknown"; break; case TriBlendMode::Copy: blendmodestr = "Copy"; break; @@ -440,8 +402,8 @@ FString DrawPolyTrianglesCommand::DebugInfo() } FString info; - info.Format("DrawPolyTriangles: variant = %s, blend mode = %s, color = %d, light = %d, textureWidth = %d, textureHeight = %d, texture = %s, translation = %s, colormaps = %s", - variantstr.GetChars(), blendmodestr.GetChars(), args.uniforms.color, args.uniforms.light, args.textureWidth, args.textureHeight, + info.Format("DrawPolyTriangles: blend mode = %s, color = %d, light = %d, textureWidth = %d, textureHeight = %d, texture = %s, translation = %s, colormaps = %s", + blendmodestr.GetChars(), args.uniforms.color, args.uniforms.light, args.textureWidth, args.textureHeight, args.texturePixels ? "ptr" : "null", args.translation ? "ptr" : "null", args.colormaps ? "ptr" : "null"); return info; } diff --git a/src/r_poly_triangle.h b/src/r_poly_triangle.h index 4fc302eab..5b66e80e2 100644 --- a/src/r_poly_triangle.h +++ b/src/r_poly_triangle.h @@ -49,6 +49,11 @@ public: int vcount = 0; TriangleDrawMode mode = TriangleDrawMode::Normal; bool ccw = false; + // bool stencilTest = true; // Always true for now + bool subsectorTest = false; + bool writeStencil = true; + bool writeColor = true; + bool writeSubsector = true; const uint8_t *texturePixels = nullptr; int textureWidth = 0; int textureHeight = 0; @@ -57,6 +62,7 @@ public: uint8_t stencilwritevalue = 0; const uint8_t *colormaps = nullptr; float clipPlane[4]; + TriBlendMode blendmode = TriBlendMode::Copy; void SetClipPlane(float a, float b, float c, float d) { @@ -159,12 +165,12 @@ class PolyTriangleDrawer { public: static void set_viewport(int x, int y, int width, int height, DCanvas *canvas); - static void draw(const PolyDrawArgs &args, TriDrawVariant variant, TriBlendMode blendmode); + static void draw(const PolyDrawArgs &args); static void toggle_mirror(); private: static ShadedTriVertex shade_vertex(const TriMatrix &objectToClip, const float *clipPlane, const TriVertex &v); - static void draw_arrays(const PolyDrawArgs &args, TriDrawVariant variant, TriBlendMode blendmode, WorkerThreadData *thread); + static void draw_arrays(const PolyDrawArgs &args, WorkerThreadData *thread); static void draw_shaded_triangle(const ShadedTriVertex *vertices, bool ccw, TriDrawTriangleArgs *args, WorkerThreadData *thread, PolyDrawFuncPtr *drawfuncs, int num_drawfuncs); static bool cullhalfspace(float clipdistance1, float clipdistance2, float &t1, float &t2); static void clipedge(const ShadedTriVertex *verts, TriVertex *clippedvert, int &numclipvert); @@ -249,15 +255,13 @@ private: class DrawPolyTrianglesCommand : public DrawerCommand { public: - DrawPolyTrianglesCommand(const PolyDrawArgs &args, TriDrawVariant variant, TriBlendMode blendmode, bool mirror); + DrawPolyTrianglesCommand(const PolyDrawArgs &args, bool mirror); void Execute(DrawerThread *thread) override; FString DebugInfo() override; private: PolyDrawArgs args; - TriDrawVariant variant; - TriBlendMode blendmode; }; class PolyVertexBuffer diff --git a/src/r_poly_wall.cpp b/src/r_poly_wall.cpp index bcb5bb16b..ebb355431 100644 --- a/src/r_poly_wall.cpp +++ b/src/r_poly_wall.cpp @@ -264,7 +264,9 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane if (Polyportal) { args.stencilwritevalue = Polyportal->StencilValue; - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); + args.writeColor = false; + args.writeSubsector = false; + PolyTriangleDrawer::draw(args); Polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, args.uniforms.subsectorDepth }); int sx1, sx2; @@ -274,17 +276,21 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const Vec4f &clipPlane } else if (!Masked) { - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawNormal, TriBlendMode::Copy); - PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); + args.blendmode = TriBlendMode::Copy; + PolyTriangleDrawer::draw(args); } else { args.uniforms.destalpha = (Line->flags & ML_ADDTRANS) ? 256 : (uint32_t)(256 - Line->alpha * 256); args.uniforms.srcalpha = (uint32_t)(Line->alpha * 256); + args.subsectorTest = true; + args.writeSubsector = false; + args.writeStencil = false; if (args.uniforms.destalpha == 0 && args.uniforms.srcalpha == 256) - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, TriBlendMode::AlphaBlend); + args.blendmode = TriBlendMode::AlphaBlend; else - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, TriBlendMode::Add); + args.blendmode = TriBlendMode::Add; + PolyTriangleDrawer::draw(args); } RenderPolyDecal::RenderWallDecals(worldToClip, clipPlane, LineSeg, SubsectorDepth, StencilValue); diff --git a/src/r_poly_wallsprite.cpp b/src/r_poly_wallsprite.cpp index e7fe267b8..fe12b271d 100644 --- a/src/r_poly_wallsprite.cpp +++ b/src/r_poly_wallsprite.cpp @@ -121,5 +121,9 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli args.SetTexture(tex); args.SetColormap(sub->sector->ColorMap); args.SetClipPlane(clipPlane.x, clipPlane.y, clipPlane.z, clipPlane.w); - PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, TriBlendMode::AlphaBlend); + args.subsectorTest = true; + args.writeSubsector = false; + args.writeStencil = false; + args.blendmode = TriBlendMode::AlphaBlend; + PolyTriangleDrawer::draw(args); }