diff --git a/src/r_poly.cpp b/src/r_poly.cpp index 4ea047925e..2e100b3955 100644 --- a/src/r_poly.cpp +++ b/src/r_poly.cpp @@ -117,6 +117,8 @@ void PolyRenderer::ClearBuffers() PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0); PolySubsectorGBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight()); NextStencilValue = 0; + SeenLinePortals.clear(); + SeenMirrors.clear(); } void PolyRenderer::SetSceneViewport() @@ -170,3 +172,13 @@ void PolyRenderer::SetupPerspectiveMatrix() WorldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView; } + +bool PolyRenderer::InsertSeenLinePortal(FLinePortal *portal) +{ + return SeenLinePortals.insert(portal).second; +} + +bool PolyRenderer::InsertSeenMirror(line_t *mirrorLine) +{ + return SeenMirrors.insert(mirrorLine).second; +} diff --git a/src/r_poly.h b/src/r_poly.h index bc108a8a13..f34106a4b2 100644 --- a/src/r_poly.h +++ b/src/r_poly.h @@ -47,6 +47,9 @@ public: uint32_t GetNextStencilValue() { uint32_t value = NextStencilValue; NextStencilValue += 2; return value; } + bool InsertSeenLinePortal(FLinePortal *portal); + bool InsertSeenMirror(line_t *mirrorLine); + private: void ClearBuffers(); void SetSceneViewport(); @@ -57,4 +60,7 @@ private: PolySkyDome Skydome; RenderPolyPlayerSprites PlayerSprites; uint32_t NextStencilValue = 0; + + std::set SeenLinePortals; + std::set SeenMirrors; }; diff --git a/src/r_poly_wall.cpp b/src/r_poly_wall.cpp index 384529da08..efc9530138 100644 --- a/src/r_poly_wall.cpp +++ b/src/r_poly_wall.cpp @@ -40,24 +40,30 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, const Vec4f &clipP PolyDrawLinePortal *polyportal = nullptr; if (line->backsector == nullptr && line->linedef && line->sidedef == line->linedef->sidedef[0] && (line->linedef->special == Line_Mirror && r_drawmirrors)) { - linePortals.push_back(std::make_unique(line->linedef)); - polyportal = linePortals.back().get(); + if (PolyRenderer::Instance()->InsertSeenMirror(line->linedef)) + { + linePortals.push_back(std::make_unique(line->linedef)); + polyportal = linePortals.back().get(); + } } else if (line->linedef && line->linedef->isVisualPortal()) { FLinePortal *portal = line->linedef->getPortal(); - for (auto &p : linePortals) + if (PolyRenderer::Instance()->InsertSeenLinePortal(portal)) { - if (p->Portal == portal) // To do: what other criterias do we need to check for? + for (auto &p : linePortals) { - polyportal = p.get(); - break; + if (p->Portal == portal) // To do: what other criterias do we need to check for? + { + polyportal = p.get(); + break; + } + } + if (!polyportal) + { + linePortals.push_back(std::make_unique(portal)); + polyportal = linePortals.back().get(); } - } - if (!polyportal) - { - linePortals.push_back(std::make_unique(portal)); - polyportal = linePortals.back().get(); } }