diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index 9d434ae8a..0e64e755f 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -51,7 +51,6 @@ #include "hwrenderer/scene/hw_drawcontext.h" #include "hw_vrmodes.h" -EXTERN_CVAR(Int, lm_background_updates); EXTERN_CVAR(Bool, cl_capfps) extern bool NoInterpolateView; @@ -97,34 +96,6 @@ void CollectLights(FLevelLocals* Level) } } -void UpdateLightmaps(DFrameBuffer* screen, FRenderState& RenderState) -{ - - // Lightmapping stuff - auto& list = RenderState.GetVisibleSurfaceList(); - auto size = RenderState.GetVisibleSurfaceListCount(); - - list.Resize(min(list.Size(), unsigned(size))); - - if (size < lm_background_updates) - { - int index = 0; - for (auto& e : level.levelMesh->Surfaces) - { - if (e.needsUpdate) - { - list.Push(index); - - if (list.Size() >= lm_background_updates) - break; - } - ++index; - } - } - - screen->UpdateLightmaps(list); -} - //----------------------------------------------------------------------------- // // Renders one viewpoint in a scene @@ -152,7 +123,6 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou screen->mShadowMap->SetCollectLights(nullptr); } - RenderState.ClearVisibleSurfaceList(); screen->SetLevelMesh(camera->Level->levelMesh); static HWDrawContext mainthread_drawctx; @@ -226,8 +196,6 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou screen->NextEye(eyeCount); } - UpdateLightmaps(screen, RenderState); - return mainvp.sector; } diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index b0dbe472a..6bac11510 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -52,6 +52,7 @@ CVAR(Bool, gl_multithread, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) EXTERN_CVAR(Float, r_actorspriteshadowdist) EXTERN_CVAR(Bool, gl_meshcache) +EXTERN_CVAR(Int, lm_background_updates); thread_local bool isWorkerThread; ctpl::thread_pool renderPool(1); @@ -856,8 +857,37 @@ void HWDrawInfo::RenderBSPNode (void *node, FRenderState& state) DoSubsector ((subsector_t *)((uint8_t *)node - 1), state); } +void UpdateLightmaps(DFrameBuffer* screen, FRenderState& RenderState) +{ + // Lightmapping stuff + auto& list = RenderState.GetVisibleSurfaceList(); + auto size = RenderState.GetVisibleSurfaceListCount(); + + list.Resize(min(list.Size(), unsigned(size))); + + if (size < lm_background_updates) + { + int index = 0; + for (auto& e : level.levelMesh->Surfaces) + { + if (e.needsUpdate) + { + list.Push(index); + + if (list.Size() >= lm_background_updates) + break; + } + ++index; + } + } + + screen->UpdateLightmaps(list); +} + void HWDrawInfo::RenderBSP(void *node, bool drawpsprites, FRenderState& state) { + state.ClearVisibleSurfaceList(); + Bsp.Clock(); // Give the DrawInfo the viewpoint in fixed point because that's what the nodes are. @@ -892,4 +922,6 @@ void HWDrawInfo::RenderBSP(void *node, bool drawpsprites, FRenderState& state) if (drawpsprites) PreparePlayerSprites(Viewpoint.sector, in_area, state); + + UpdateLightmaps(screen, state); } diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 46ff650e3..19de0a558 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -191,28 +191,6 @@ void HWFlat::DrawSubsectors(HWDrawInfo *di, FRenderState &state) SetupLights(di, state, section->lighthead, lightdata, sector->PortalGroup); } state.SetLightIndex(dynlightindex); - - const auto* lm = §or->Level->levelMesh->Surfaces[0]; // temporay hack on top of a temporary hack - - for (auto& subsector : section->subsectors) - { - if (auto lightmap = subsector->lightmap[ceiling ? 1 : 0][0]) - { - state.PushVisibleSurface(lightmap - lm, lightmap); - } - } - - if (auto subsectors = sector->Level->levelMesh->XFloorToSurface.CheckKey(sector)) - { - for (auto* surface : *subsectors) - { - if (surface) - { - state.PushVisibleSurface(surface - lm, surface); - } - } - } - state.DrawIndexed(DT_Triangles, iboindex + section->vertexindex, section->vertexcount); flatvertices += section->vertexcount; flatprimitives++; @@ -523,6 +501,31 @@ void HWFlat::ProcessSector(HWDrawInfo *di, FRenderState& state, sector_t * front uint8_t &srf = hacktype? sink : di->section_renderflags[di->Level->sections.SectionIndex(section)]; const auto &vp = di->Viewpoint; + // + // Lightmaps + // + + const auto* lm = §or->Level->levelMesh->Surfaces[0]; // temporay hack on top of a temporary hack + + for (auto& subsector : section->subsectors) + { + if (auto lightmap = subsector->lightmap[ceiling ? 1 : 0][0]) + { + state.PushVisibleSurface(lightmap - lm, lightmap); + } + } + + if (auto subsectors = sector->Level->levelMesh->XFloorToSurface.CheckKey(sector)) + { + for (auto* surface : *subsectors) + { + if (surface) + { + state.PushVisibleSurface(surface - lm, surface); + } + } + } + // // // diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index caa1cd8a7..edeee8262 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -347,11 +347,6 @@ void HWWall::DrawWall(HWDrawInfo *di, FRenderState &state, bool translucent) MakeVertices(di, state, !!(flags & HWWall::HWF_TRANSLUCENT)); } - if (lightmap) - { - state.PushVisibleSurface(lightmap - &seg->Subsector->sector->Level->levelMesh->Surfaces[0], lightmap); - } - state.SetNormal(glseg.Normal()); if (!translucent) { @@ -1270,6 +1265,10 @@ void HWWall::DoTexture(HWDrawInfo *di, FRenderState& state, int _type,seg_t * se if (seg->sidedef->lightmap && type >= RENDERWALL_TOP && type <= RENDERWALL_BOTTOM) { lightmap = seg->sidedef->lightmap[type - RENDERWALL_TOP]; + if (lightmap) + { + state.PushVisibleSurface(lightmap - &seg->Subsector->sector->Level->levelMesh->Surfaces[0], lightmap); + } } else {