- Collect all PVS information first so that processing the individual sectors can be done on multiple threads

This commit is contained in:
Magnus Norddahl 2017-09-07 00:34:09 +02:00
commit 7a1274ab76
30 changed files with 630 additions and 265 deletions

View file

@ -33,12 +33,13 @@
#include "polyrenderer/poly_renderer.h"
#include "r_sky.h"
#include "polyrenderer/scene/poly_light.h"
#include "polyrenderer/poly_renderthread.h"
#include "g_levellocals.h"
EXTERN_CVAR(Bool, r_drawmirrors)
EXTERN_CVAR(Bool, r_fogboundary)
bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, std::vector<PolyTranslucentObject*> &translucentWallsOutput, std::vector<std::unique_ptr<PolyDrawLinePortal>> &linePortals, line_t *lastPortalLine)
bool RenderPolyWall::RenderLine(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, std::vector<PolyTranslucentObject*> &translucentWallsOutput, std::vector<std::unique_ptr<PolyDrawLinePortal>> &linePortals, line_t *lastPortalLine)
{
double frontceilz1 = frontsector->ceilingplane.ZatPoint(line->v1);
double frontfloorz1 = frontsector->floorplane.ZatPoint(line->v1);
@ -105,7 +106,7 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlan
wall.Wallpart = side_t::mid;
wall.Texture = GetTexture(wall.Line, wall.Side, side_t::mid);
wall.Polyportal = polyportal;
wall.Render(worldToClip, clipPlane);
wall.Render(thread, worldToClip, clipPlane);
return true;
}
}
@ -141,7 +142,7 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlan
wall.BottomTexZ = MIN(MIN(backceilz1, frontceilz1), MIN(backceilz2, frontceilz2));
wall.Wallpart = side_t::top;
wall.Texture = GetTexture(wall.Line, wall.Side, side_t::top);
wall.Render(worldToClip, clipPlane);
wall.Render(thread, worldToClip, clipPlane);
}
if ((bottomfloorz1 < bottomceilz1 || bottomfloorz2 < bottomceilz2) && line->sidedef && !bothSkyFloor)
@ -153,7 +154,7 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlan
wall.UnpeggedCeil2 = topceilz2;
wall.Wallpart = side_t::bottom;
wall.Texture = GetTexture(wall.Line, wall.Side, side_t::bottom);
wall.Render(worldToClip, clipPlane);
wall.Render(thread, worldToClip, clipPlane);
}
if (line->sidedef)
@ -170,12 +171,12 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const PolyClipPlan
FTexture *midtex = TexMan(line->sidedef->GetTexture(side_t::mid), true);
if ((midtex && midtex->UseType != FTexture::TEX_Null) || wall.FogBoundary)
translucentWallsOutput.push_back(PolyRenderer::Instance()->FrameMemory.NewObject<PolyTranslucentWall>(wall));
translucentWallsOutput.push_back(thread->FrameMemory->NewObject<PolyTranslucentWall>(wall));
if (polyportal)
{
wall.Polyportal = polyportal;
wall.Render(worldToClip, clipPlane);
wall.Render(thread, worldToClip, clipPlane);
}
}
}
@ -189,7 +190,7 @@ bool RenderPolyWall::IsFogBoundary(sector_t *front, sector_t *back)
(front->GetTexture(sector_t::ceiling) != skyflatnum || back->GetTexture(sector_t::ceiling) != skyflatnum);
}
void RenderPolyWall::Render3DFloorLine(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, F3DFloor *fakeFloor, std::vector<PolyTranslucentObject*> &translucentWallsOutput)
void RenderPolyWall::Render3DFloorLine(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, F3DFloor *fakeFloor, std::vector<PolyTranslucentObject*> &translucentWallsOutput)
{
if (!(fakeFloor->flags & FF_EXISTS)) return;
if (!(fakeFloor->flags & FF_RENDERPLANES)) return;
@ -235,9 +236,9 @@ void RenderPolyWall::Render3DFloorLine(const TriMatrix &worldToClip, const PolyC
wall.Texture = GetTexture(wall.Line, wall.Side, side_t::mid);
if (!wall.Masked)
wall.Render(worldToClip, clipPlane);
wall.Render(thread, worldToClip, clipPlane);
else
translucentWallsOutput.push_back(PolyRenderer::Instance()->FrameMemory.NewObject<PolyTranslucentWall>(wall));
translucentWallsOutput.push_back(thread->FrameMemory->NewObject<PolyTranslucentWall>(wall));
}
void RenderPolyWall::SetCoords(const DVector2 &v1, const DVector2 &v2, double ceil1, double floor1, double ceil2, double floor2)
@ -250,13 +251,13 @@ void RenderPolyWall::SetCoords(const DVector2 &v1, const DVector2 &v2, double ce
this->floor2 = floor2;
}
void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane)
void RenderPolyWall::Render(PolyRenderThread *thread, const TriMatrix &worldToClip, const PolyClipPlane &clipPlane)
{
bool foggy = false;
if (!Texture && !Polyportal && !FogBoundary)
return;
TriVertex *vertices = PolyRenderer::Instance()->FrameMemory.AllocMemory<TriVertex>(4);
TriVertex *vertices = thread->FrameMemory->AllocMemory<TriVertex>(4);
vertices[0].x = (float)v1.X;
vertices[0].y = (float)v1.Y;
@ -329,7 +330,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &c
args.SetDepthTest(true);
args.SetWriteDepth(true);
args.SetWriteStencil(false);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
args.DrawArray(thread, vertices, 4, PolyDrawMode::TriangleFan);
if (!Texture)
return;
}
@ -339,13 +340,13 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &c
args.SetWriteStencil(true, Polyportal->StencilValue);
args.SetWriteColor(false);
args.SetWriteDepth(false);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
args.DrawArray(thread, vertices, 4, PolyDrawMode::TriangleFan);
Polyportal->Shape.push_back({ vertices, 4, true });
}
else if (!Masked)
{
args.SetStyle(TriBlendMode::TextureOpaque);
DrawStripes(args, vertices);
DrawStripes(thread, args, vertices);
}
else
{
@ -355,13 +356,13 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &c
args.SetDepthTest(true);
args.SetWriteDepth(true);
args.SetWriteStencil(false);
DrawStripes(args, vertices);
DrawStripes(thread, args, vertices);
}
RenderPolyDecal::RenderWallDecals(worldToClip, clipPlane, LineSeg, StencilValue);
RenderPolyDecal::RenderWallDecals(thread, worldToClip, clipPlane, LineSeg, StencilValue);
}
void RenderPolyWall::DrawStripes(PolyDrawArgs &args, TriVertex *vertices)
void RenderPolyWall::DrawStripes(PolyRenderThread *thread, PolyDrawArgs &args, TriVertex *vertices)
{
const auto &lightlist = Line->frontsector->e->XFloor.lightlist;
if (lightlist.Size() > 0)
@ -384,7 +385,7 @@ void RenderPolyWall::DrawStripes(PolyDrawArgs &args, TriVertex *vertices)
args.SetClipPlane(1, topPlane);
args.SetClipPlane(2, bottomPlane);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
args.DrawArray(thread, vertices, 4, PolyDrawMode::TriangleFan);
FDynamicColormap *basecolormap = GetColorTable(lit->extra_colormap, Line->frontsector->SpecialColors[sector_t::walltop]);
@ -407,11 +408,11 @@ void RenderPolyWall::DrawStripes(PolyDrawArgs &args, TriVertex *vertices)
args.SetClipPlane(1, topPlane);
args.SetClipPlane(2, PolyClipPlane());
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
args.DrawArray(thread, vertices, 4, PolyDrawMode::TriangleFan);
}
else
{
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
args.DrawArray(thread, vertices, 4, PolyDrawMode::TriangleFan);
}
}