diff --git a/src/rendering/hwrenderer/doom_levelmesh.cpp b/src/rendering/hwrenderer/doom_levelmesh.cpp index fedb61f9f..4587f69a9 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.cpp +++ b/src/rendering/hwrenderer/doom_levelmesh.cpp @@ -183,6 +183,19 @@ void DoomLevelMesh::BeginFrame(FLevelLocals& doomMap) } CreateLights(doomMap); + UpdateWallPortals(); +} + +void DoomLevelMesh::UpdateWallPortals() +{ + WallPortals.Clear(); + for (int sideIndex : SidePortals) + { + for (HWWall& wall : Sides[sideIndex].WallPortals) + { + WallPortals.Push(&wall); + } + } } void DoomLevelMesh::CreateLights(FLevelLocals& doomMap) @@ -393,6 +406,8 @@ void DoomLevelMesh::FreeSide(FLevelLocals& doomMap, unsigned int sideIndex) for (auto& uni : Sides[sideIndex].Uniforms) FreeUniforms(uni.Start, uni.Count); Sides[sideIndex].Uniforms.Clear(); + + Sides[sideIndex].WallPortals.Clear(); } void DoomLevelMesh::FreeFlat(FLevelLocals& doomMap, unsigned int sectorIndex) @@ -537,9 +552,16 @@ void DoomLevelMesh::UpdateSide(FLevelLocals& doomMap, unsigned int sideIndex) state.AlphaFunc(Alpha_GEqual, 0.f); CreateWallSurface(side, disp, state, result.list, false, true, sideIndex); + if (result.portals.Size() != 0 && !Sides[sideIndex].InSidePortalsList) + { + // Register side having portals + SidePortals.Push(sideIndex); + Sides[sideIndex].InSidePortalsList = true; + } + for (HWWall& portal : result.portals) { - WallPortals.Push(portal); + Sides[sideIndex].WallPortals.Push(portal); } CreateWallSurface(side, disp, state, result.portals, true, false, sideIndex); diff --git a/src/rendering/hwrenderer/doom_levelmesh.h b/src/rendering/hwrenderer/doom_levelmesh.h index 0b29e9785..7529a153f 100644 --- a/src/rendering/hwrenderer/doom_levelmesh.h +++ b/src/rendering/hwrenderer/doom_levelmesh.h @@ -55,6 +55,8 @@ struct SideSurfaceBlock int FirstSurface = -1; TArray Geometries; TArray Uniforms; + TArray WallPortals; + bool InSidePortalsList = false; }; struct FlatSurfaceBlock @@ -77,7 +79,8 @@ public: void BuildSectorGroups(const FLevelLocals& doomMap); - TArray WallPortals; + TArray SidePortals; + TArray WallPortals; TArray sectorGroup; // index is sector, value is sectorGroup TArray sectorPortals[2]; // index is sector+plane, value is index into the portal list @@ -112,6 +115,8 @@ private: void FreeSide(FLevelLocals& doomMap, unsigned int sideIndex); void FreeFlat(FLevelLocals& doomMap, unsigned int sectorIndex); + void UpdateWallPortals(); + void SetSubsectorLightmap(int surfaceIndex); void SetSideLightmap(int surfaceIndex); diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 4ddcd679d..bdaa89214 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -445,13 +445,13 @@ void HWDrawInfo::CreateScene(bool drawpsprites, FRenderState& state) state.SetDepthMask(false); state.EnableTexture(false); state.SetEffect(EFF_PORTAL); - for (HWWall& wall : portals) + for (HWWall* wall : portals) { state.BeginQuery(); - wall.MakeVertices(state, false); - wall.RenderWall(state, HWWall::RWF_BLANK); - wall.vertcount = 0; + wall->MakeVertices(state, false); + wall->RenderWall(state, HWWall::RWF_BLANK); + wall->vertcount = 0; state.EndQuery(); } @@ -471,14 +471,17 @@ void HWDrawInfo::CreateScene(bool drawpsprites, FRenderState& state) } state.SetCulling(Cull_None); - // retrieve the query results and use them to fill the portal manager with portals - state.GetQueryResults(queryStart, queryEnd - queryStart, QueryResultsBuffer); - for (unsigned int i = 0, count = QueryResultsBuffer.Size(); i < count; i++) + if (queryStart != queryEnd) { - bool portalVisible = QueryResultsBuffer[i]; - if (portalVisible) + // retrieve the query results and use them to fill the portal manager with portals + state.GetQueryResults(queryStart, queryEnd - queryStart, QueryResultsBuffer); + for (unsigned int i = 0, count = QueryResultsBuffer.Size(); i < count; i++) { - PutWallPortal(portals[i], state); + bool portalVisible = QueryResultsBuffer[i]; + if (portalVisible) + { + PutWallPortal(*portals[i], state); + } } }