diff --git a/src/r_poly.cpp b/src/r_poly.cpp index 171d7e0ade..13ecd26258 100644 --- a/src/r_poly.cpp +++ b/src/r_poly.cpp @@ -44,7 +44,7 @@ void RenderPolyScene::Render() ClearBuffers(); SetSceneViewport(); SetupPerspectiveMatrix(); - MainPortal.SetViewpoint(WorldToClip, 0); + MainPortal.SetViewpoint(WorldToClip, GetNextStencilValue()); MainPortal.Render(); Skydome.Render(WorldToClip); MainPortal.RenderTranslucent(); @@ -63,6 +63,7 @@ void RenderPolyScene::ClearBuffers() PolyVertexBuffer::Clear(); PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0); PolySubsectorGBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight()); + NextStencilValue = 0; } void RenderPolyScene::SetSceneViewport() diff --git a/src/r_poly.h b/src/r_poly.h index 99e86307bb..3bd9bb319a 100644 --- a/src/r_poly.h +++ b/src/r_poly.h @@ -41,6 +41,8 @@ public: void RenderRemainingPlayerSprites(); static RenderPolyScene *Instance(); + + uint32_t GetNextStencilValue() { uint32_t value = NextStencilValue; NextStencilValue += 2; return value; } private: void ClearBuffers(); @@ -51,4 +53,5 @@ private: RenderPolyPortal MainPortal; PolySkyDome Skydome; RenderPolyPlayerSprites PlayerSprites; + uint32_t NextStencilValue = 0; }; diff --git a/src/r_poly_plane.cpp b/src/r_poly_plane.cpp index c8248bed66..60b9d7569a 100644 --- a/src/r_poly_plane.cpp +++ b/src/r_poly_plane.cpp @@ -264,7 +264,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, subsector_t *sub, uin } else { - args.stencilwritevalue = 252; + args.stencilwritevalue = polyportal->StencilValue; PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth }); } @@ -273,7 +273,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, subsector_t *sub, uin { if (portal) { - args.stencilwritevalue = 252; + args.stencilwritevalue = polyportal->StencilValue; polyportal->Shape.push_back({ args.vinput, args.vcount, args.ccw, subsectorDepth }); } else diff --git a/src/r_poly_portal.cpp b/src/r_poly_portal.cpp index 805195835d..4f42ab77e0 100644 --- a/src/r_poly_portal.cpp +++ b/src/r_poly_portal.cpp @@ -26,6 +26,7 @@ #include "sbar.h" #include "r_data/r_translate.h" #include "r_poly_portal.h" +#include "r_poly.h" #include "gl/data/gl_data.h" CVAR(Bool, r_debug_cull, 0, 0) @@ -192,14 +193,15 @@ void RenderPolyPortal::RenderTranslucent() { for (auto it = SectorPortals.rbegin(); it != SectorPortals.rend(); ++it) { - (*it)->RenderTranslucent(); + auto &portal = *it; + portal->RenderTranslucent(); PolyDrawArgs args; args.objectToClip = &WorldToClip; args.mode = TriangleDrawMode::Fan; - args.stenciltestvalue = 253; - args.stencilwritevalue = 1; - for (const auto &verts : (*it)->Shape) + args.stenciltestvalue = portal->StencilValue + 1; + args.stencilwritevalue = StencilValue; + for (const auto &verts : portal->Shape) { args.vinput = verts.Vertices; args.vcount = verts.Count; @@ -211,14 +213,15 @@ void RenderPolyPortal::RenderTranslucent() for (auto it = LinePortals.rbegin(); it != LinePortals.rend(); ++it) { - (*it)->RenderTranslucent(); + auto &portal = *it; + portal->RenderTranslucent(); PolyDrawArgs args; args.objectToClip = &WorldToClip; args.mode = TriangleDrawMode::Fan; - args.stenciltestvalue = 253; - args.stencilwritevalue = 1; - for (const auto &verts : (*it)->Shape) + args.stenciltestvalue = portal->StencilValue + 1; + args.stencilwritevalue = StencilValue; + for (const auto &verts : portal->Shape) { args.vinput = verts.Vertices; args.vcount = verts.Count; @@ -257,6 +260,7 @@ void RenderPolyPortal::RenderTranslucent() PolyDrawSectorPortal::PolyDrawSectorPortal(FSectorPortal *portal, bool ceiling) : Portal(portal), Ceiling(ceiling) { + StencilValue = RenderPolyScene::Instance()->GetNextStencilValue(); } void PolyDrawSectorPortal::Render() @@ -289,7 +293,7 @@ void PolyDrawSectorPortal::Render() TriMatrix::translate((float)-ViewPos.X, (float)-ViewPos.Y, (float)-ViewPos.Z); TriMatrix worldToClip = TriMatrix::perspective(fovy, ratio, 5.0f, 65535.0f) * worldToView; - RenderPortal.SetViewpoint(worldToClip, 252); + RenderPortal.SetViewpoint(worldToClip, StencilValue); RenderPortal.Render(); RestoreGlobals(); @@ -349,6 +353,8 @@ void PolyDrawSectorPortal::RestoreGlobals() PolyDrawLinePortal::PolyDrawLinePortal(line_t *src, line_t *dest, bool mirror) : Src(src), Dest(dest) { // To do: do what R_EnterPortal and PortalDrawseg does + + StencilValue = RenderPolyScene::Instance()->GetNextStencilValue(); } void PolyDrawLinePortal::Render() diff --git a/src/r_poly_portal.h b/src/r_poly_portal.h index 8878f496d8..b910034a2c 100644 --- a/src/r_poly_portal.h +++ b/src/r_poly_portal.h @@ -128,6 +128,7 @@ public: void RenderTranslucent(); FSectorPortal *Portal; + uint32_t StencilValue = 0; std::vector Shape; private: @@ -153,6 +154,7 @@ public: void Render(); void RenderTranslucent(); + uint32_t StencilValue = 0; std::vector Shape; private: