[core] Move layer specific color ramp updates behind common update() method

This commit is contained in:
Alexander Shalamov
2018-10-25 17:30:59 +03:00
parent f6ad5f378e
commit a7274f66d0
7 changed files with 26 additions and 12 deletions

View File

@@ -185,6 +185,10 @@ void RenderHeatmapLayer::render(PaintParameters& parameters, RenderSource*) {
}
}
void RenderHeatmapLayer::update() {
updateColorRamp();
}
void RenderHeatmapLayer::updateColorRamp() {
auto colorValue = unevaluated.get<HeatmapColor>().getValue();
if (colorValue.isUndefined()) {

View File

@@ -18,6 +18,7 @@ public:
bool hasTransition() const override;
bool hasCrossfade() const override;
void render(PaintParameters&, RenderSource*) override;
void update() final;
bool queryIntersectsFeature(
const GeometryCoordinates&,
@@ -27,8 +28,6 @@ public:
const float,
const mat4&) const override;
void updateColorRamp();
std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;
// Paint properties
@@ -40,6 +39,9 @@ public:
PremultipliedImage colorRamp;
optional<OffscreenTexture> renderTexture;
optional<gl::Texture> colorRampTexture;
private:
void updateColorRamp();
};
template <>

View File

@@ -294,4 +294,8 @@ float RenderLineLayer::getLineWidth(const GeometryTileFeature& feature, const fl
}
void RenderLineLayer::update() {
updateColorRamp();
}
} // namespace mbgl

View File

@@ -32,6 +32,7 @@ public:
bool hasTransition() const override;
bool hasCrossfade() const override;
void render(PaintParameters&, RenderSource*) override;
void update() final;
RenderLinePaintProperties::PossiblyEvaluated paintProperties() const;
@@ -43,7 +44,6 @@ public:
const float,
const mat4&) const override;
void updateColorRamp();
std::unique_ptr<Bucket> createBucket(const BucketParameters&, const std::vector<const RenderLayer*>&) const override;
std::unique_ptr<Layout> createLayout(const BucketParameters&,
@@ -59,6 +59,7 @@ public:
private:
float getLineWidth(const GeometryTileFeature&, const float) const;
void updateColorRamp();
CrossfadeParameters crossfade;
PremultipliedImage colorRamp;
optional<gl::Texture> colorRampTexture;

View File

@@ -86,6 +86,10 @@ void RenderLayer::sortRenderTiles(const TransformState&) {
std::sort(renderTiles.begin(), renderTiles.end(), [](const auto& a, const auto& b) { return a.get().id < b.get().id; });
}
void RenderLayer::update() {
// no-op
}
RenderLayer::RenderTiles RenderLayer::filterRenderTiles(RenderTiles tiles, FilterFunctionPtr filterFn) const {
assert(filterFn != nullptr);
RenderTiles filtered;

View File

@@ -95,7 +95,14 @@ public:
void setImpl(Immutable<style::Layer::Impl>);
virtual void markContextDestroyed();
// TODO: Figure out how to remove this or whether layers other than
// RenderHeatmapLayer and RenderLineLayer need paint property updates,
// similar to color ramp. Temporarily moved to the base.
virtual void update();
friend std::string layoutKey(const RenderLayer&);
protected:
// Checks whether the current hardware can render this layer. If it can't, we'll show a warning
// in the console to inform the developer.

View File

@@ -15,7 +15,6 @@
#include <mbgl/renderer/layers/render_custom_layer.hpp>
#include <mbgl/renderer/layers/render_fill_extrusion_layer.hpp>
#include <mbgl/renderer/layers/render_fill_layer.hpp>
#include <mbgl/renderer/layers/render_heatmap_layer.hpp>
#include <mbgl/renderer/layers/render_hillshade_layer.hpp>
#include <mbgl/renderer/style_diff.hpp>
#include <mbgl/renderer/query.hpp>
@@ -186,14 +185,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) {
if (layerAdded || layerChanged) {
layer.transition(transitionParameters);
if (layer.is<RenderHeatmapLayer>()) {
layer.as<RenderHeatmapLayer>()->updateColorRamp();
}
if (layer.is<RenderLineLayer>()) {
layer.as<RenderLineLayer>()->updateColorRamp();
}
layer.update();
}
if (layerAdded || layerChanged || zoomChanged || layer.hasTransition() || layer.hasCrossfade()) {