From 7ddb5e8d3618048abe2d4e84ca8aee8505967ac7 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 21 Aug 2020 17:17:19 +0200 Subject: [PATCH] Add a dirty flag to only update the layermanager once per frame --- modules/globebrowsing/src/renderableglobe.cpp | 20 ++++++++++++++++++- modules/globebrowsing/src/renderableglobe.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/globebrowsing/src/renderableglobe.cpp b/modules/globebrowsing/src/renderableglobe.cpp index 86ef86bd2e..f8455e5ca8 100644 --- a/modules/globebrowsing/src/renderableglobe.cpp +++ b/modules/globebrowsing/src/renderableglobe.cpp @@ -923,6 +923,20 @@ void RenderableGlobe::update(const UpdateData& data) { _shadowComponent.update(data); } + // abock (2020-08-21) + // This is a bit nasty every since we removed the second update call from the render + // loop. The problem is when we enable a new layer, the dirty flags above will be set + // to true, but the update method hasn't run yet. So we need to move the layerManager + // update method to the render function call, but we don't want to *actually* update + // the layers once per render call; hence this nasty dirty flag + // + // How it is without in the frame when we enable a layer: + // + // RenderableGlobe::update() // updated with the old number of layers + // // Lua script to enable layer is executed and sets the dirty flags + // RenderableGlobe::render() // rendering with the new number of layers but the + // // LayerManager hasn't updated yet :o + _layerManagerDirty = true; } bool RenderableGlobe::renderedWithDesiredData() const { @@ -955,7 +969,11 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&, { ZoneScoped - _layerManager.update(); + + if (_layerManagerDirty) { + _layerManager.update(); + _layerManagerDirty = false; + } if (_nLayersIsDirty) { std::array lgs = diff --git a/modules/globebrowsing/src/renderableglobe.h b/modules/globebrowsing/src/renderableglobe.h index 6e7386cd84..4304bc7c60 100644 --- a/modules/globebrowsing/src/renderableglobe.h +++ b/modules/globebrowsing/src/renderableglobe.h @@ -289,6 +289,7 @@ private: bool _chunkCornersDirty = true; bool _nLayersIsDirty = true; bool _allChunksAvailable = true; + bool _layerManagerDirty = true; size_t _iterationsOfAvailableData = 0; size_t _iterationsOfUnavailableData = 0; Layer* _lastChangedLayer = nullptr;