diff --git a/src/hwrenderer/scene/hw_portal.cpp b/src/hwrenderer/scene/hw_portal.cpp index 9cb35c696c..787ef0b83f 100644 --- a/src/hwrenderer/scene/hw_portal.cpp +++ b/src/hwrenderer/scene/hw_portal.cpp @@ -185,6 +185,33 @@ void HWPortal::DrawPortalStencil(FRenderState &state, int pass) mPrimIndices[i * 2] = lines[i].vertindex; mPrimIndices[i * 2 + 1] = lines[i].vertcount; } + + if (NeedCap() && lines.Size() > 1 && planesused != 0) + { + screen->mVertexData->Map(); + if (planesused & (1 << sector_t::floor)) + { + auto verts = screen->mVertexData->AllocVertices(4); + auto ptr = verts.first; + ptr[0].Set((float)boundingBox.left, -32767.f, (float)boundingBox.top, 0, 0); + ptr[1].Set((float)boundingBox.right, -32767.f, (float)boundingBox.top, 0, 0); + ptr[2].Set((float)boundingBox.left, -32767.f, (float)boundingBox.bottom, 0, 0); + ptr[3].Set((float)boundingBox.right, -32767.f, (float)boundingBox.bottom, 0, 0); + mBottomCap = verts.second; + } + if (planesused & (1 << sector_t::ceiling)) + { + auto verts = screen->mVertexData->AllocVertices(4); + auto ptr = verts.first; + ptr[0].Set((float)boundingBox.left, 32767.f, (float)boundingBox.top, 0, 0); + ptr[1].Set((float)boundingBox.right, 32767.f, (float)boundingBox.top, 0, 0); + ptr[2].Set((float)boundingBox.left, 32767.f, (float)boundingBox.bottom, 0, 0); + ptr[3].Set((float)boundingBox.right, 32767.f, (float)boundingBox.bottom, 0, 0); + mTopCap = verts.second; + } + screen->mVertexData->Unmap(); + } + } for (unsigned int i = 0; i < mPrimIndices.Size(); i += 2) @@ -196,26 +223,15 @@ void HWPortal::DrawPortalStencil(FRenderState &state, int pass) // The cap's depth handling needs special treatment so that it won't block further portal caps. if (pass == STP_DepthRestore) state.SetDepthRange(1, 1); - if (planesused & (1 << sector_t::floor)) + if (mBottomCap != ~0u) { - auto verts = screen->mVertexData->AllocVertices(4); - auto ptr = verts.first; - ptr[0].Set((float)boundingBox.left, -32767.f, (float)boundingBox.top, 0, 0); - ptr[1].Set((float)boundingBox.right, -32767.f, (float)boundingBox.top, 0, 0); - ptr[2].Set((float)boundingBox.left, -32767.f, (float)boundingBox.bottom, 0, 0); - ptr[3].Set((float)boundingBox.right, -32767.f, (float)boundingBox.bottom, 0, 0); - state.Draw(DT_TriangleStrip, verts.second, 4, false); + state.Draw(DT_TriangleStrip, mBottomCap, 4, false); } - if (planesused & (1 << sector_t::ceiling)) + if (mTopCap != ~0u) { - auto verts = screen->mVertexData->AllocVertices(4); - auto ptr = verts.first; - ptr[0].Set((float)boundingBox.left, 32767.f, (float)boundingBox.top, 0, 0); - ptr[1].Set((float)boundingBox.right, 32767.f, (float)boundingBox.top, 0, 0); - ptr[2].Set((float)boundingBox.left, 32767.f, (float)boundingBox.bottom, 0, 0); - ptr[3].Set((float)boundingBox.right, 32767.f, (float)boundingBox.bottom, 0, 0); - state.Draw(DT_TriangleStrip, verts.second, 4, false); + state.Draw(DT_TriangleStrip, mTopCap, 4, false); } + if (pass == STP_DepthRestore) state.SetDepthRange(0, 1); } } diff --git a/src/hwrenderer/scene/hw_portal.h b/src/hwrenderer/scene/hw_portal.h index f9d9e243c6..879420c106 100644 --- a/src/hwrenderer/scene/hw_portal.h +++ b/src/hwrenderer/scene/hw_portal.h @@ -55,6 +55,7 @@ class HWPortal ActorRenderFlags savedvisibility; TArray mPrimIndices; + unsigned int mTopCap = ~0u, mBottomCap = ~0u; void DrawPortalStencil(FRenderState &state, int pass);