From c914a7a7fea6a54c0ab3f5b5231978a512a278b7 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 13 Nov 2016 13:24:36 +0100 Subject: [PATCH] Cull walls --- src/r_poly.cpp | 22 ++++++++++++++++++---- src/r_poly.h | 3 +-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/r_poly.cpp b/src/r_poly.cpp index e54452e10..a34853e2e 100644 --- a/src/r_poly.cpp +++ b/src/r_poly.cpp @@ -46,10 +46,7 @@ void RenderPolyBsp::Render() // Setup working buffers PolyVertexBuffer::Clear(); - SolidSegments.clear(); - SolidSegments.reserve(SolidCullScale + 2); - SolidSegments.push_back({ -0x7fff, -SolidCullScale }); - SolidSegments.push_back({ SolidCullScale , 0x7fff }); + ClearSolidSegments(); SectorSpriteRanges.clear(); SectorSpriteRanges.resize(numsectors); SortedSprites.clear(); @@ -92,6 +89,7 @@ void RenderPolyBsp::Render() } // Render front to back + ClearSolidSegments(); if (r_debug_cull) { for (auto it = PvsSectors.rbegin(); it != PvsSectors.rend(); ++it) @@ -363,6 +361,12 @@ void RenderPolyBsp::AddLine(seg_t *line, sector_t *frontsector, uint32_t subsect if (pt1.Y * (pt1.X - pt2.X) + pt1.X * (pt2.Y - pt1.Y) >= 0) return; + // Cull wall if not visible + int sx1, sx2; + bool hasSegmentRange = GetSegmentRangeForLine(line->v1->fX(), line->v1->fY(), line->v2->fX(), line->v2->fY(), sx1, sx2); + if (hasSegmentRange && IsSegmentCulled(sx1, sx2)) + return; + double frontceilz1 = frontsector->ceilingplane.ZatPoint(line->v1); double frontfloorz1 = frontsector->floorplane.ZatPoint(line->v1); double frontceilz2 = frontsector->ceilingplane.ZatPoint(line->v2); @@ -384,6 +388,8 @@ void RenderPolyBsp::AddLine(seg_t *line, sector_t *frontsector, uint32_t subsect wall.UnpeggedCeil = frontceilz1; wall.Texpart = side_t::mid; wall.Render(worldToClip); + if (hasSegmentRange) + MarkSegmentCulled(sx1, sx2); } } else @@ -972,6 +978,14 @@ void RenderPolyBsp::RenderPlayerSprite(DPSprite *sprite, AActor *owner, float bo //R_DrawVisSprite(vis); } +void RenderPolyBsp::ClearSolidSegments() +{ + SolidSegments.clear(); + SolidSegments.reserve(SolidCullScale + 2); + SolidSegments.push_back({ -0x7fff, -SolidCullScale }); + SolidSegments.push_back({ SolidCullScale , 0x7fff }); +} + bool RenderPolyBsp::IsSegmentCulled(int x1, int x2) const { int next = 0; diff --git a/src/r_poly.h b/src/r_poly.h index 45cbcf864..b2a024488 100644 --- a/src/r_poly.h +++ b/src/r_poly.h @@ -132,11 +132,10 @@ private: // Checks BSP node/subtree bounding box. // Returns true if some part of the bbox might be visible. bool CheckBBox(float *bspcoord); - bool GetSegmentRangeForLine(double x1, double y1, double x2, double y2, int &sx1, int &sx2) const; - void MarkSegmentCulled(int x1, int x2); bool IsSegmentCulled(int x1, int x2) const; + void ClearSolidSegments(); std::vector PvsSectors; uint32_t NextSubsectorDepth = 0;