diff --git a/shaders/drawable.fill_outline.vertex.glsl b/shaders/drawable.fill_outline.vertex.glsl index b201f79a4..3af22f32b 100644 --- a/shaders/drawable.fill_outline.vertex.glsl +++ b/shaders/drawable.fill_outline.vertex.glsl @@ -1,6 +1,7 @@ layout (std140) uniform FillOutlineDrawableUBO { highp mat4 u_matrix; highp vec2 u_world; + highp vec2 pad; }; layout (std140) uniform FillOutlineEvaluatedPropsUBO { highp vec4 u_outline_color; diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index 2975eb084..b7bb9b957 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -485,50 +485,92 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, // interpolation UBOs const float zoom = static_cast(state.getZoom()); - const LineInterpolationUBO lineInterpolationUBO{ - /*color_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*blur_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*opacity_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*gapwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*offset_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*width_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - 0, - 0}; - const LineGradientInterpolationUBO lineGradientInterpolationUBO{ - /*blur_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*opacity_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*gapwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*offset_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*width_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - 0, - 0, - 0}; - const LinePatternInterpolationUBO linePatternInterpolationUBO{ - /*blur_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*opacity_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*offset_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*gapwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*width_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*pattern_from_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*pattern_to_t =*/std::get<1>(paintPropertyBinders.get()->interpolationFactor(zoom)), - 0}; - const LineSDFInterpolationUBO lineSDFInterpolationUBO{ - /*color_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*blur_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*opacity_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*gapwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*offset_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*width_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - /*floorwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), - 0}; + + std::optional lineInterpolationUBO = std::nullopt; + std::optional lineGradientInterpolationUBO = std::nullopt; + std::optional linePatternInterpolationUBO = std::nullopt; + std::optional lineSDFInterpolationUBO = std::nullopt; + + auto getLineInterpolationUBO = [&]() -> const LineInterpolationUBO& { + if (!lineInterpolationUBO) { + lineInterpolationUBO = { + /*color_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*blur_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*opacity_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*gapwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*offset_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*width_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + 0, + 0}; + } + + return *lineInterpolationUBO; + }; + + auto getLineGradientInterpolationUBO = [&]() -> const LineGradientInterpolationUBO& { + if (!lineGradientInterpolationUBO) { + lineGradientInterpolationUBO = { + /*blur_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*opacity_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*gapwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*offset_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*width_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + 0, + 0, + 0}; + } + + return *lineGradientInterpolationUBO; + }; + + auto getLinePatternInterpolationUBO = [&]() -> const LinePatternInterpolationUBO& { + if (!linePatternInterpolationUBO) { + linePatternInterpolationUBO = { + /*blur_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*opacity_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*offset_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*gapwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*width_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*pattern_from_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*pattern_to_t =*/std::get<1>(paintPropertyBinders.get()->interpolationFactor(zoom)), + 0}; + } + + return *linePatternInterpolationUBO; + }; + + auto getLineSDFInterpolationUBO = [&]() -> const LineSDFInterpolationUBO& { + if (!lineSDFInterpolationUBO) { + lineSDFInterpolationUBO = { + /*color_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*blur_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*opacity_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*gapwidth_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*offset_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*width_t =*/std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + /*floorwidth_t =*/ + std::get<0>(paintPropertyBinders.get()->interpolationFactor(zoom)), + 0}; + } + + return *lineSDFInterpolationUBO; + }; // tile dependent properties UBOs: + std::optional linePatternTilePropertiesUBO = std::nullopt; const auto& linePatternValue = evaluated.get().constantOr(Faded{"", ""}); const std::optional patternPosA = tile.getPattern(linePatternValue.from.id()); const std::optional patternPosB = tile.getPattern(linePatternValue.to.id()); - const LinePatternTilePropertiesUBO linePatternTilePropertiesUBO{ - /*pattern_from =*/patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, - /*pattern_to =*/patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}}; + + auto getLinePatternTilePropertiesUBO = [&]() -> const LinePatternTilePropertiesUBO& { + if (!linePatternTilePropertiesUBO) { + linePatternTilePropertiesUBO = { + /*pattern_from =*/patternPosA ? util::cast(patternPosA->tlbr()) : std::array{0}, + /*pattern_to =*/patternPosB ? util::cast(patternPosB->tlbr()) : std::array{0}}; + } + + return *linePatternTilePropertiesUBO; + }; auto updateExisting = [&](gfx::Drawable& drawable) { if (drawable.getLayerTweaker() != layerTweaker) { @@ -542,25 +584,25 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, // simple line interpolation UBO if (shaderUniforms.get(idLineInterpolationUBOName)) { - drawableUniforms.createOrUpdate(idLineInterpolationUBOName, &lineInterpolationUBO, context); + drawableUniforms.createOrUpdate(idLineInterpolationUBOName, &getLineInterpolationUBO(), context); } // gradient line interpolation UBO else if (shaderUniforms.get(idLineGradientInterpolationUBOName)) { drawableUniforms.createOrUpdate( - idLineGradientInterpolationUBOName, &lineGradientInterpolationUBO, context); + idLineGradientInterpolationUBOName, &getLineGradientInterpolationUBO(), context); } // pattern line interpolation UBO else if (shaderUniforms.get(idLinePatternInterpolationUBOName)) { // interpolation drawableUniforms.createOrUpdate( - idLinePatternInterpolationUBOName, &linePatternInterpolationUBO, context); + idLinePatternInterpolationUBOName, &getLinePatternInterpolationUBO(), context); // tile properties drawableUniforms.createOrUpdate( - idLinePatternTilePropertiesUBOName, &linePatternTilePropertiesUBO, context); + idLinePatternTilePropertiesUBOName, &getLinePatternTilePropertiesUBO(), context); } // SDF line interpolation UBO else if (shaderUniforms.get(idLineSDFInterpolationUBOName)) { - drawableUniforms.createOrUpdate(idLineSDFInterpolationUBOName, &lineSDFInterpolationUBO, context); + drawableUniforms.createOrUpdate(idLineSDFInterpolationUBOName, &getLineSDFInterpolationUBO(), context); } // TODO: vertex attributes or `propertiesAsUniforms` updated, is that needed? @@ -608,7 +650,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setLayerTweaker(layerTweaker); drawable->setData(std::make_unique(cap)); drawable->mutableUniformBuffers().createOrUpdate( - idLineSDFInterpolationUBOName, &lineSDFInterpolationUBO, context); + idLineSDFInterpolationUBOName, &getLineSDFInterpolationUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; @@ -665,9 +707,9 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); drawable->mutableUniformBuffers().createOrUpdate( - idLinePatternInterpolationUBOName, &linePatternInterpolationUBO, context); + idLinePatternInterpolationUBOName, &getLinePatternInterpolationUBO(), context); drawable->mutableUniformBuffers().createOrUpdate( - idLinePatternTilePropertiesUBOName, &linePatternTilePropertiesUBO, context); + idLinePatternTilePropertiesUBOName, &getLinePatternTilePropertiesUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; @@ -717,7 +759,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); drawable->mutableUniformBuffers().createOrUpdate( - idLineGradientInterpolationUBOName, &lineGradientInterpolationUBO, context); + idLineGradientInterpolationUBOName, &getLineGradientInterpolationUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; @@ -754,7 +796,7 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders, drawable->setTileID(tileID); drawable->setLayerTweaker(layerTweaker); drawable->mutableUniformBuffers().createOrUpdate( - idLineInterpolationUBOName, &lineInterpolationUBO, context); + idLineInterpolationUBOName, &getLineInterpolationUBO(), context); tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable)); ++stats.drawablesAdded; diff --git a/src/mbgl/shaders/mtl/line.cpp b/src/mbgl/shaders/mtl/line.cpp index d7412dd7e..5de634630 100644 --- a/src/mbgl/shaders/mtl/line.cpp +++ b/src/mbgl/shaders/mtl/line.cpp @@ -14,7 +14,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{8, true, false, sizeof(LineGradientUBO), "LineDynamicUBO"}, + UniformBlockInfo{8, true, false, sizeof(LineDynamicUBO), "LineDynamicUBO"}, UniformBlockInfo{9, true, true, sizeof(LineUBO), "LineUBO"}, UniformBlockInfo{10, true, true, sizeof(LinePropertiesUBO), "LinePropertiesUBO"}, UniformBlockInfo{11, true, false, sizeof(LineInterpolationUBO), "LineInterpolationUBO"}, @@ -33,7 +33,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{9, true, false, sizeof(LineGradientUBO), "LineDynamicUBO"}, + UniformBlockInfo{9, true, false, sizeof(LineDynamicUBO), "LineDynamicUBO"}, UniformBlockInfo{10, true, true, sizeof(LinePatternUBO), "LinePatternUBO"}, UniformBlockInfo{11, true, true, sizeof(LinePatternPropertiesUBO), "LinePatternPropertiesUBO"}, UniformBlockInfo{12, true, false, sizeof(LinePatternInterpolationUBO), "LinePatternInterpolationUBO"}, @@ -55,7 +55,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{9, true, false, sizeof(LineGradientUBO), "LineDynamicUBO"}, + UniformBlockInfo{9, true, false, sizeof(LineDynamicUBO), "LineDynamicUBO"}, UniformBlockInfo{10, true, true, sizeof(LineSDFUBO), "LineSDFUBO"}, UniformBlockInfo{11, true, true, sizeof(LineSDFPropertiesUBO), "LineSDFPropertiesUBO"}, UniformBlockInfo{12, true, false, sizeof(LineSDFInterpolationUBO), "LineSDFInterpolationUBO"}, diff --git a/src/mbgl/shaders/mtl/line_gradient.cpp b/src/mbgl/shaders/mtl/line_gradient.cpp index 9fcb5d65d..f0c8d9eac 100644 --- a/src/mbgl/shaders/mtl/line_gradient.cpp +++ b/src/mbgl/shaders/mtl/line_gradient.cpp @@ -13,7 +13,7 @@ const std::array ShaderSource ShaderSource::uniforms = { - UniformBlockInfo{7, true, false, sizeof(LineGradientUBO), "LineDynamicUBO"}, + UniformBlockInfo{7, true, false, sizeof(LineDynamicUBO), "LineDynamicUBO"}, UniformBlockInfo{8, true, true, sizeof(LineGradientUBO), "LineGradientUBO"}, UniformBlockInfo{9, true, true, sizeof(LineGradientPropertiesUBO), "LineGradientPropertiesUBO"}, UniformBlockInfo{10, true, false, sizeof(LineGradientInterpolationUBO), "LineGradientInterpolationUBO"},