From e7d6f6a84df879ed2729667d0c2425b5c465e3e3 Mon Sep 17 00:00:00 2001 From: Tim Sylvester Date: Thu, 25 Jan 2024 10:57:53 -0800 Subject: [PATCH] Line tweaker (#2050) --- .../layers/background_layer_tweaker.cpp | 3 ++ .../renderer/layers/circle_layer_tweaker.cpp | 12 ++---- .../layers/fill_extrusion_layer_tweaker.cpp | 7 +--- .../renderer/layers/heatmap_layer_tweaker.cpp | 27 ++++++++------ .../layers/heatmap_texture_layer_tweaker.cpp | 30 ++++++++------- .../layers/heatmap_texture_layer_tweaker.hpp | 1 + .../layers/hillshade_layer_tweaker.cpp | 34 ++++++++++------- .../hillshade_prepare_layer_tweaker.cpp | 19 +++++----- .../renderer/layers/line_layer_tweaker.cpp | 37 ++++++++++--------- .../renderer/layers/raster_layer_tweaker.cpp | 2 + .../layers/render_background_layer.cpp | 5 +-- .../renderer/layers/render_circle_layer.cpp | 5 +-- .../layers/render_fill_extrusion_layer.cpp | 5 +-- .../renderer/layers/render_heatmap_layer.cpp | 26 +++++++------ .../renderer/layers/render_heatmap_layer.hpp | 4 ++ .../layers/render_hillshade_layer.cpp | 31 +++++++--------- .../layers/render_hillshade_layer.hpp | 5 +++ .../renderer/layers/render_line_layer.cpp | 5 +-- .../renderer/layers/render_raster_layer.cpp | 5 +-- src/mbgl/renderer/render_layer.cpp | 25 ------------- src/mbgl/renderer/render_layer.hpp | 5 --- 21 files changed, 141 insertions(+), 152 deletions(-) diff --git a/src/mbgl/renderer/layers/background_layer_tweaker.cpp b/src/mbgl/renderer/layers/background_layer_tweaker.cpp index 3e9c93d322b..faffc5249ec 100644 --- a/src/mbgl/renderer/layers/background_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/background_layer_tweaker.cpp @@ -51,6 +51,9 @@ void BackgroundLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintPara } layerGroup.setEnabled(true); + // properties are re-evaluated every time + propertiesUpdated = false; + std::optional samplerLocation{}; visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { assert(drawable.getTileID()); diff --git a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp index 1755175412a..91a1ef0e9be 100644 --- a/src/mbgl/renderer/layers/circle_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/circle_layer_tweaker.cpp @@ -45,19 +45,14 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .padding = */ 0, 0, 0}; - - if (!paintParamsUniformBuffer) { - paintParamsUniformBuffer = context.createUniformBuffer(&paintParamsUBO, sizeof(paintParamsUBO)); - } else { - paintParamsUniformBuffer->update(&paintParamsUBO, sizeof(CirclePaintParamsUBO)); - } + context.emplaceOrUpdateUniformBuffer(paintParamsUniformBuffer, &paintParamsUBO); const auto zoom = parameters.state.getZoom(); const bool pitchWithMap = evaluated.get() == AlignmentType::Map; const bool scaleWithMap = evaluated.get() == CirclePitchScaleType::Map; // Updated only with evaluated properties - if (!evaluatedPropsUniformBuffer) { + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { const CircleEvaluatedPropsUBO evaluatedPropsUBO = { /* .color = */ constOrDefault(evaluated), /* .stroke_color = */ constOrDefault(evaluated), @@ -69,8 +64,9 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete /* .scale_with_map = */ scaleWithMap, /* .pitch_with_map = */ pitchWithMap, /* .padding = */ 0}; - evaluatedPropsUniformBuffer = context.createUniformBuffer(&evaluatedPropsUBO, sizeof(evaluatedPropsUBO)); + context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); } + propertiesUpdated = false; visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { assert(drawable.getTileID() || !"Circles only render with tiles"); diff --git a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp index 71ceba343fb..4b1e97510ee 100644 --- a/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/fill_extrusion_layer_tweaker.cpp @@ -70,11 +70,8 @@ void FillExtrusionLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintP /* .pad = */ 0, 0, 0}; - if (!propsBuffer) { - propsBuffer = context.createUniformBuffer(¶msUBO, sizeof(paramsUBO)); - } else { - propsBuffer->update(¶msUBO, sizeof(paramsUBO)); - } + context.emplaceOrUpdateUniformBuffer(propsBuffer, ¶msUBO); + propertiesUpdated = false; visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { diff --git a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp index a7e55df952d..ed9ced5f4cf 100644 --- a/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_layer_tweaker.cpp @@ -25,6 +25,7 @@ static const StringIdentity idHeatmapEvaluatedPropsUBOName = stringIndexer().get void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { auto& context = parameters.context; + const auto zoom = parameters.state.getZoom(); const auto& evaluated = static_cast(*evaluatedProperties).evaluated; if (layerGroup.empty()) { @@ -36,17 +37,17 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif - const auto zoom = parameters.state.getZoom(); - - if (!evaluatedPropsUniformBuffer) { - const HeatmapEvaluatedPropsUBO evaluatedPropsUBO = { - /* .weight = */ evaluated.get().constantOr(HeatmapWeight::defaultValue()), - /* .radius = */ evaluated.get().constantOr(HeatmapRadius::defaultValue()), - /* .intensity = */ evaluated.get(), - /* .padding = */ 0}; - evaluatedPropsUniformBuffer = parameters.context.createUniformBuffer(&evaluatedPropsUBO, - sizeof(evaluatedPropsUBO)); - } + const auto getPropsBuffer = [&]() -> auto& { + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { + const HeatmapEvaluatedPropsUBO evaluatedPropsUBO = { + /* .weight = */ evaluated.get().constantOr(HeatmapWeight::defaultValue()), + /* .radius = */ evaluated.get().constantOr(HeatmapRadius::defaultValue()), + /* .intensity = */ evaluated.get(), + /* .padding = */ 0}; + parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); + } + return evaluatedPropsUniformBuffer; + }; visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -56,7 +57,7 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); auto& uniforms = drawable.mutableUniformBuffers(); - uniforms.addOrReplace(idHeatmapEvaluatedPropsUBOName, evaluatedPropsUniformBuffer); + uniforms.addOrReplace(idHeatmapEvaluatedPropsUBOName, getPropsBuffer()); constexpr bool nearClipped = false; constexpr bool inViewportPixelUnits = false; @@ -69,6 +70,8 @@ void HeatmapLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamet uniforms.createOrUpdate(idHeatmapDrawableUBOName, &drawableUBO, context); }); + + propertiesUpdated = false; } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp index 3f622b90fcb..d964bbddd6d 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.cpp @@ -30,23 +30,27 @@ void HeatmapTextureLayerTweaker::execute(LayerGroupBase& layerGroup, const Paint const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif + const auto getDrawableUBO = [&]() -> auto& { + if (!drawableBuffer) { + const auto& size = parameters.staticData.backendSize; + mat4 viewportMat; + matrix::ortho(viewportMat, 0, size.width, size.height, 0, -1, 1); + const HeatmapTextureDrawableUBO drawableUBO = { + /* .matrix = */ util::cast(viewportMat), + /* .world = */ {static_cast(size.width), static_cast(size.height)}, + /* .opacity = */ evaluated.get(), + /* .pad1 = */ 0, + }; + parameters.context.emplaceOrUpdateUniformBuffer(drawableBuffer, &drawableUBO); + } + return drawableBuffer; + }; + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!checkTweakDrawable(drawable)) { return; } - - const auto& size = parameters.staticData.backendSize; - mat4 viewportMat; - matrix::ortho(viewportMat, 0, size.width, size.height, 0, -1, 1); - const HeatmapTextureDrawableUBO drawableUBO = { - /* .matrix = */ util::cast(viewportMat), - /* .world = */ {static_cast(size.width), static_cast(size.height)}, - /* .opacity = */ evaluated.get(), - /* .pad1 = */ 0, - }; - - drawable.mutableUniformBuffers().createOrUpdate( - idHeatmapTextureDrawableUBOName, &drawableUBO, parameters.context); + drawable.mutableUniformBuffers().addOrReplace(idHeatmapTextureDrawableUBOName, getDrawableUBO()); }); } diff --git a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.hpp b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.hpp index 62c5a12f98b..350cac89a59 100644 --- a/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.hpp +++ b/src/mbgl/renderer/layers/heatmap_texture_layer_tweaker.hpp @@ -18,6 +18,7 @@ class HeatmapTextureLayerTweaker : public LayerTweaker { void execute(LayerGroupBase&, const PaintParameters&) override; protected: + gfx::UniformBufferPtr drawableBuffer; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp index 702b94d9a3c..28d2d0c3584 100644 --- a/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_layer_tweaker.cpp @@ -15,8 +15,9 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idHillshadeDrawableUBOName = stringIndexer().get("HillshadeDrawableUBO"); -static const StringIdentity idHillshadeEvaluatedPropsUBOName = stringIndexer().get("HillshadeEvaluatedPropsUBO"); +namespace { +const StringIdentity idHillshadeDrawableUBOName = stringIndexer().get("HillshadeDrawableUBO"); +const StringIdentity idHillshadeEvaluatedPropsUBOName = stringIndexer().get("HillshadeEvaluatedPropsUBO"); std::array getLatRange(const UnwrappedTileID& id) { const LatLng latlng0 = LatLng(id); @@ -27,10 +28,12 @@ std::array getLatRange(const UnwrappedTileID& id) { std::array getLight(const PaintParameters& parameters, const HillshadePaintProperties::PossiblyEvaluated& evaluated) { float azimuthal = util::deg2radf(evaluated.get()); - if (evaluated.get() == HillshadeIlluminationAnchorType::Viewport) + if (evaluated.get() == HillshadeIlluminationAnchorType::Viewport) { azimuthal = azimuthal - static_cast(parameters.state.getBearing()); + } return {{evaluated.get(), azimuthal}}; } +} // namespace void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { const auto& evaluated = static_cast(*evaluatedProperties).evaluated; @@ -44,13 +47,16 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str()); #endif - if (!evaluatedPropsUniformBuffer) { - HillshadeEvaluatedPropsUBO evaluatedPropsUBO = {/* .highlight = */ evaluated.get(), - /* .shadow = */ evaluated.get(), - /* .accent = */ evaluated.get()}; - evaluatedPropsUniformBuffer = parameters.context.createUniformBuffer(&evaluatedPropsUBO, - sizeof(evaluatedPropsUBO)); - } + const auto getPropsBuffer = [&]() -> auto& { + if (!evaluatedPropsUniformBuffer || propertiesUpdated) { + const HillshadeEvaluatedPropsUBO evaluatedPropsUBO = { + /* .highlight = */ evaluated.get(), + /* .shadow = */ evaluated.get(), + /* .accent = */ evaluated.get()}; + parameters.context.emplaceOrUpdateUniformBuffer(evaluatedPropsUniformBuffer, &evaluatedPropsUBO); + } + return evaluatedPropsUniformBuffer; + }; visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!drawable.getTileID() || !checkTweakDrawable(drawable)) { @@ -59,16 +65,18 @@ void HillshadeLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParam const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped(); - drawable.mutableUniformBuffers().addOrReplace(idHillshadeEvaluatedPropsUBOName, evaluatedPropsUniformBuffer); + auto& uniforms = drawable.mutableUniformBuffers(); + uniforms.addOrReplace(idHillshadeEvaluatedPropsUBOName, getPropsBuffer()); const auto matrix = getTileMatrix( tileID, parameters, {0.f, 0.f}, TranslateAnchorType::Viewport, false, false, drawable, true); HillshadeDrawableUBO drawableUBO = {/* .matrix = */ util::cast(matrix), /* .latrange = */ getLatRange(tileID), /* .light = */ getLight(parameters, evaluated)}; - - drawable.mutableUniformBuffers().createOrUpdate(idHillshadeDrawableUBOName, &drawableUBO, parameters.context); + uniforms.createOrUpdate(idHillshadeDrawableUBOName, &drawableUBO, parameters.context); }); + + propertiesUpdated = false; } } // namespace mbgl diff --git a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp index 80aa6ff29af..4823460a50c 100644 --- a/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/hillshade_prepare_layer_tweaker.cpp @@ -16,20 +16,21 @@ namespace mbgl { using namespace style; using namespace shaders; -static const StringIdentity idHillshadePrepareDrawableUBOName = stringIndexer().get("HillshadePrepareDrawableUBO"); +namespace { +const StringIdentity idHillshadePrepareDrawableUBOName = stringIndexer().get("HillshadePrepareDrawableUBO"); -const std::array& getUnpackVector(Tileset::DEMEncoding encoding) { - // https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb - static const std::array unpackMapbox = {{6553.6f, 25.6f, 0.1f, 10000.0f}}; - // https://aws.amazon.com/public-datasets/terrain/ - static const std::array unpackTerrarium = {{256.0f, 1.0f, 1.0f / 256.0f, 32768.0f}}; +// https://www.mapbox.com/help/access-elevation-data/#mapbox-terrain-rgb +constexpr std::array unpackMapbox = {{6553.6f, 25.6f, 0.1f, 10000.0f}}; - return encoding == Tileset::DEMEncoding::Terrarium ? unpackTerrarium : unpackMapbox; +// https://aws.amazon.com/public-datasets/terrain/ +constexpr std::array unpackTerrarium = {{256.0f, 1.0f, 1.0f / 256.0f, 32768.0f}}; + +constexpr const std::array& getUnpackVector(const Tileset::DEMEncoding encoding) { + return (encoding == Tileset::DEMEncoding::Terrarium) ? unpackTerrarium : unpackMapbox; } +} // namespace void HillshadePrepareLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { - // const auto& evaluated = static_cast(*evaluatedProperties).evaluated; - if (layerGroup.empty()) { return; } diff --git a/src/mbgl/renderer/layers/line_layer_tweaker.cpp b/src/mbgl/renderer/layers/line_layer_tweaker.cpp index 57929104cf1..f24ceccf1b3 100644 --- a/src/mbgl/renderer/layers/line_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/line_layer_tweaker.cpp @@ -38,13 +38,19 @@ static const StringIdentity idTexImageName = stringIndexer().get("u_image"); void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters& parameters) { auto& context = parameters.context; + const auto zoom = parameters.state.getZoom(); const auto& evaluated = static_cast(*evaluatedProperties).evaluated; const auto& crossfade = static_cast(*evaluatedProperties).crossfade; - const auto zoom = parameters.state.getZoom(); + // Each property UBO is updated at most once if new evaluated properties were set + bool simplePropertiesUpdated = propertiesUpdated; + bool gradientPropertiesUpdated = propertiesUpdated; + bool patternPropertiesUpdated = propertiesUpdated; + bool sdfPropertiesUpdated = propertiesUpdated; + propertiesUpdated = false; const auto getLinePropsBuffer = [&]() { - if (!linePropertiesBuffer) { + if (!linePropertiesBuffer || simplePropertiesUpdated) { const LinePropertiesUBO linePropertiesUBO{ /*color =*/evaluated.get().constantOr(LineColor::defaultValue()), /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), @@ -55,12 +61,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters 0, 0, 0}; - linePropertiesBuffer = context.createUniformBuffer(&linePropertiesUBO, sizeof(linePropertiesUBO)); + context.emplaceOrUpdateUniformBuffer(linePropertiesBuffer, &linePropertiesUBO); + simplePropertiesUpdated = false; } return linePropertiesBuffer; }; const auto getLineGradientPropsBuffer = [&]() { - if (!lineGradientPropertiesBuffer) { + if (!lineGradientPropertiesBuffer || gradientPropertiesUpdated) { const LineGradientPropertiesUBO lineGradientPropertiesUBO{ /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), /*opacity =*/evaluated.get().constantOr(LineOpacity::defaultValue()), @@ -70,13 +77,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters 0, 0, 0}; - lineGradientPropertiesBuffer = context.createUniformBuffer(&lineGradientPropertiesUBO, - sizeof(lineGradientPropertiesUBO)); + context.emplaceOrUpdateUniformBuffer(lineGradientPropertiesBuffer, &lineGradientPropertiesUBO); + gradientPropertiesUpdated = false; } return lineGradientPropertiesBuffer; }; const auto getLinePatternPropsBuffer = [&]() { - if (!linePatternPropertiesBuffer) { + if (!linePatternPropertiesBuffer || patternPropertiesUpdated) { const LinePatternPropertiesUBO linePatternPropertiesUBO{ /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), /*opacity =*/evaluated.get().constantOr(LineOpacity::defaultValue()), @@ -86,13 +93,13 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters 0, 0, 0}; - linePatternPropertiesBuffer = context.createUniformBuffer(&linePatternPropertiesUBO, - sizeof(linePatternPropertiesUBO)); + context.emplaceOrUpdateUniformBuffer(linePatternPropertiesBuffer, &linePatternPropertiesUBO); + patternPropertiesUpdated = false; } return linePatternPropertiesBuffer; }; const auto getLineSDFPropsBuffer = [&]() { - if (!lineSDFPropertiesBuffer) { + if (!lineSDFPropertiesBuffer || sdfPropertiesUpdated) { const LineSDFPropertiesUBO lineSDFPropertiesUBO{ /*color =*/evaluated.get().constantOr(LineColor::defaultValue()), /*blur =*/evaluated.get().constantOr(LineBlur::defaultValue()), @@ -103,19 +110,15 @@ void LineLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParameters /*floorwidth =*/evaluated.get().constantOr(LineFloorWidth::defaultValue()), 0, 0}; - lineSDFPropertiesBuffer = context.createUniformBuffer(&lineSDFPropertiesUBO, sizeof(lineSDFPropertiesUBO)); + context.emplaceOrUpdateUniformBuffer(lineSDFPropertiesBuffer, &lineSDFPropertiesUBO); + sdfPropertiesUpdated = false; } return lineSDFPropertiesBuffer; }; const LineDynamicUBO dynamicUBO = { /*units_to_pixels = */ {1.0f / parameters.pixelsToGLUnits[0], 1.0f / parameters.pixelsToGLUnits[1]}, 0, 0}; - - if (!dynamicBuffer) { - dynamicBuffer = parameters.context.createUniformBuffer(&dynamicUBO, sizeof(dynamicUBO)); - } else { - dynamicBuffer->update(&dynamicUBO, sizeof(dynamicUBO)); - } + context.emplaceOrUpdateUniformBuffer(dynamicBuffer, &dynamicUBO); visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { const auto shader = drawable.getShader(); diff --git a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp index eb91f380ec3..665562d1e69 100644 --- a/src/mbgl/renderer/layers/raster_layer_tweaker.cpp +++ b/src/mbgl/renderer/layers/raster_layer_tweaker.cpp @@ -23,6 +23,8 @@ void RasterLayerTweaker::execute([[maybe_unused]] LayerGroupBase& layerGroup, [[maybe_unused]] const PaintParameters& parameters) { const auto& evaluated = static_cast(*evaluatedProperties).evaluated; + propertiesUpdated = false; + visitLayerGroupDrawables(layerGroup, [&](gfx::Drawable& drawable) { if (!checkTweakDrawable(drawable)) { return; diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index 5fecbcd64d4..437c92dcefb 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -66,9 +66,8 @@ void RenderBackgroundLayer::evaluate(const PropertyEvaluationParameters& paramet evaluatedProperties = std::move(properties); #if MLN_DRAWABLE_RENDERER - if (layerGroup) { - auto newTweaker = std::make_shared(getID(), evaluatedProperties); - replaceTweaker(layerTweaker, std::move(newTweaker), {layerGroup}); + if (layerTweaker) { + layerTweaker->updateProperties(evaluatedProperties); } #endif } diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index b9a1a4371aa..a1343eeec73 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -86,9 +86,8 @@ void RenderCircleLayer::evaluate(const PropertyEvaluationParameters& parameters) evaluatedProperties = std::move(properties); #if MLN_DRAWABLE_RENDERER - if (layerGroup) { - auto newTweaker = std::make_shared(getID(), evaluatedProperties); - replaceTweaker(layerTweaker, std::move(newTweaker), {layerGroup}); + if (layerTweaker) { + layerTweaker->updateProperties(evaluatedProperties); } #endif // MLN_DRAWABLE_RENDERER } diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index f3aebbb2a15..296e73d51e8 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -75,9 +75,8 @@ void RenderFillExtrusionLayer::evaluate(const PropertyEvaluationParameters& para evaluatedProperties = std::move(properties); #if MLN_DRAWABLE_RENDERER - if (layerGroup) { - auto newTweaker = std::make_shared(getID(), evaluatedProperties); - replaceTweaker(layerTweaker, std::move(newTweaker), {layerGroup}); + if (layerTweaker) { + layerTweaker->updateProperties(evaluatedProperties); } #endif // MLN_DRAWABLE_RENDERER } diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index cc69d3e0994..c5af6665eb1 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -53,6 +53,15 @@ void RenderHeatmapLayer::transition(const TransitionParameters& parameters) { updateColorRamp(); } +#if MLN_DRAWABLE_RENDERER +void RenderHeatmapLayer::layerChanged(const TransitionParameters& parameters, + const Immutable& impl, + UniqueChangeRequestVec& changes) { + RenderLayer::layerChanged(parameters, impl, changes); + textureTweaker.reset(); +} +#endif + void RenderHeatmapLayer::evaluate(const PropertyEvaluationParameters& parameters) { auto properties = makeMutable(staticImmutableCast(baseImpl), unevaluated.evaluate(parameters)); @@ -63,16 +72,11 @@ void RenderHeatmapLayer::evaluate(const PropertyEvaluationParameters& parameters evaluatedProperties = std::move(properties); #if MLN_DRAWABLE_RENDERER - if (layerGroup) { - auto newTextureTweaker = std::make_shared(getID(), evaluatedProperties); - replaceTweaker(textureTweaker, std::move(newTextureTweaker), {layerGroup}); + if (layerTweaker) { + layerTweaker->updateProperties(evaluatedProperties); } - - if (renderTarget) { - if (auto tileLayerGroup = renderTarget->getLayerGroup(0)) { - auto newTweaker = std::make_shared(getID(), evaluatedProperties); - replaceTweaker(layerTweaker, std::move(newTweaker), {std::move(tileLayerGroup)}); - } + if (textureTweaker) { + textureTweaker->updateProperties(evaluatedProperties); } #endif } @@ -499,8 +503,6 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders, // TODO: Don't rebuild drawables every time textureLayerGroup->clearDrawables(); - std::unique_ptr heatmapTextureBuilder; - if (!sharedTextureVertices) { sharedTextureVertices = std::make_shared(RenderStaticData::heatmapTextureVertices()); } @@ -515,7 +517,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders, gfx::AttributeDataType::Short2); } - heatmapTextureBuilder = context.createDrawableBuilder("heatmapTexture"); + auto heatmapTextureBuilder = context.createDrawableBuilder("heatmapTexture"); heatmapTextureBuilder->setShader(heatmapTextureShader); heatmapTextureBuilder->setEnableDepth(false); heatmapTextureBuilder->setColorMode(gfx::ColorMode::alphaBlended()); diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.hpp b/src/mbgl/renderer/layers/render_heatmap_layer.hpp index 1fecb7f0a62..7f04191925b 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.hpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.hpp @@ -56,6 +56,10 @@ class RenderHeatmapLayer final : public RenderLayer { void updateColorRamp(); #if MLN_DRAWABLE_RENDERER + void layerChanged(const TransitionParameters& parameters, + const Immutable& impl, + UniqueChangeRequestVec& changes) override; + /// Remove all drawables for the tile from the layer group /// @return The number of drawables actually removed. std::size_t removeTile(RenderPass, const OverscaledTileID&) override; diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp index a0ab12ac628..5d3151e7ed6 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp @@ -64,6 +64,15 @@ void RenderHillshadeLayer::transition(const TransitionParameters& parameters) { unevaluated = impl_cast(baseImpl).paint.transitioned(parameters, std::move(unevaluated)); } +#if MLN_DRAWABLE_RENDERER +void RenderHillshadeLayer::layerChanged(const TransitionParameters& parameters, + const Immutable& impl, + UniqueChangeRequestVec& changes) { + RenderLayer::layerChanged(parameters, impl, changes); + prepareLayerTweaker.reset(); +} +#endif + void RenderHillshadeLayer::evaluate(const PropertyEvaluationParameters& parameters) { auto properties = makeMutable(staticImmutableCast(baseImpl), unevaluated.evaluate(parameters)); @@ -73,25 +82,11 @@ void RenderHillshadeLayer::evaluate(const PropertyEvaluationParameters& paramete properties->renderPasses = mbgl::underlying_type(passes); evaluatedProperties = std::move(properties); #if MLN_DRAWABLE_RENDERER - if (layerGroup) { - auto newTweaker = std::make_shared(getID(), evaluatedProperties); - replaceTweaker(layerTweaker, std::move(newTweaker), {layerGroup}); + if (layerTweaker) { + layerTweaker->updateProperties(evaluatedProperties); } - - if (!activatedRenderTargets.empty()) { - auto newTweaker2 = std::make_shared(getID(), evaluatedProperties); - - std::vector groups; - for (const auto& target : activatedRenderTargets) { - if (const auto& group = target->getLayerGroup(0)) { - groups.push_back(group); - } - } - if (groups.empty()) { - prepareLayerTweaker = newTweaker2; - } else { - replaceTweaker(prepareLayerTweaker, std::move(newTweaker2), groups); - } + if (prepareLayerTweaker) { + prepareLayerTweaker->updateProperties(evaluatedProperties); } #endif } diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.hpp b/src/mbgl/renderer/layers/render_hillshade_layer.hpp index 0c7faadbad6..83fa357ed7b 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.hpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.hpp @@ -45,6 +45,11 @@ class RenderHillshadeLayer : public RenderLayer { #if MLN_DRAWABLE_RENDERER void updateLayerTweaker(); + + void layerChanged(const TransitionParameters& parameters, + const Immutable& impl, + UniqueChangeRequestVec& changes) override; + #endif // MLN_DRAWABLE_RENDERER void prepare(const LayerPrepareParameters&) override; diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index b7bb9b95768..c3a69b9eb6a 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -81,9 +81,8 @@ void RenderLineLayer::evaluate(const PropertyEvaluationParameters& parameters) { evaluatedProperties = std::move(properties); #if MLN_DRAWABLE_RENDERER - if (layerGroup) { - auto newTweaker = std::make_shared(getID(), evaluatedProperties); - replaceTweaker(layerTweaker, std::move(newTweaker), {layerGroup}); + if (layerTweaker) { + layerTweaker->updateProperties(evaluatedProperties); } #endif } diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index e0831cddf44..51f1920aa37 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -54,9 +54,8 @@ void RenderRasterLayer::evaluate(const PropertyEvaluationParameters& parameters) evaluatedProperties = std::move(properties); #if MLN_DRAWABLE_RENDERER - if (layerGroup) { - auto newTweaker = std::make_shared(getID(), evaluatedProperties); - replaceTweaker(layerTweaker, std::move(newTweaker), {layerGroup, imageLayerGroup}); + if (layerTweaker) { + layerTweaker->updateProperties(evaluatedProperties); } #endif } diff --git a/src/mbgl/renderer/render_layer.cpp b/src/mbgl/renderer/render_layer.cpp index 4e1f3e2082f..5a52417694f 100644 --- a/src/mbgl/renderer/render_layer.cpp +++ b/src/mbgl/renderer/render_layer.cpp @@ -70,31 +70,6 @@ std::optional RenderLayer::getSolidBackground() const { } #if MLN_DRAWABLE_RENDERER -void RenderLayer::replaceTweaker(LayerTweakerPtr& curTweaker, - LayerTweakerPtr newTweaker, - const std::vector& layerGroups) { - const auto prevTweaker = curTweaker; - - // We need to re-create the tweaker because it doesn't yet support modifying evaluated - // properties, but we don't want to stop updating drawables (as in the `layerChanged` case) - // so we need to update the tweaker reference on the outstanding drawables so that they - // pass the check in `updateExisting`. - // TODO: Once the tweaker doesn't need to be re-created on each property evaluation, this won't be needed. - for (const auto& group : layerGroups) { - if (group) { - group->addLayerTweaker(newTweaker); - - visitLayerGroupDrawables(*group, [&](gfx::Drawable& drawable) { - if (drawable.getLayerTweaker() == prevTweaker) { - drawable.setLayerTweaker(newTweaker); - } - }); - } - } - - curTweaker = std::move(newTweaker); -} - void RenderLayer::layerChanged(const TransitionParameters&, const Immutable&, UniqueChangeRequestVec&) { diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp index 8d2ae82fac8..ba1e06cdc41 100644 --- a/src/mbgl/renderer/render_layer.hpp +++ b/src/mbgl/renderer/render_layer.hpp @@ -266,11 +266,6 @@ class RenderLayer { /// unchanged bool setRenderTileBucketID(const OverscaledTileID&, util::SimpleIdentity bucketID); - /// Update the layer tweaker and drawables which reference it - static void replaceTweaker(LayerTweakerPtr& toReplace, - LayerTweakerPtr newTweaker, - const std::vector&); - #endif // MLN_DRAWABLE_RENDERER static bool applyColorRamp(const style::ColorRampPropertyValue&, PremultipliedImage&);