diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2017-05-04 16:01:16 +0300 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2017-05-08 19:39:55 +0300 |
commit | 20810f988a735e0d43f9abff9260ea0784cd218c (patch) | |
tree | 57121706a03488bda12d40451671961bb8653a58 /src | |
parent | 1c9af3226f0ad306cf2ec8be9ff1558938f69736 (diff) | |
download | qtlocation-mapboxgl-20810f988a735e0d43f9abff9260ea0784cd218c.tar.gz |
[core] render light
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/render_light.cpp | 25 | ||||
-rw-r--r-- | src/mbgl/renderer/render_light.hpp | 18 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 24 | ||||
-rw-r--r-- | src/mbgl/style/style.hpp | 11 |
6 files changed, 72 insertions, 12 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index bba6d50a98..52ac323df4 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -967,7 +967,7 @@ void Map::setLight(std::unique_ptr<style::Light> light) { return; } - impl->style->light = std::move(light); + impl->style->setLight(std::move(light)); } style::Light* Map::getLight() { @@ -975,7 +975,7 @@ style::Light* Map::getLight() { return nullptr; } - return impl->style->light.get(); + return impl->style->getLight(); } #pragma mark - Defaults diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 60c4757893..eed3bfcd8b 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -144,7 +144,7 @@ void Painter::render(const Style& style, const FrameData& frame_, View& view, Sp spriteAtlas = style.spriteAtlas.get(); lineAtlas = style.lineAtlas.get(); - evaluatedLight = style.evaluatedLight; + evaluatedLight = style.getRenderLight()->getEvaluated(); RenderData renderData = style.getRenderData(frame.debugOptions, state.getAngle()); const std::vector<RenderItem>& order = renderData.order; diff --git a/src/mbgl/renderer/render_light.cpp b/src/mbgl/renderer/render_light.cpp new file mode 100644 index 0000000000..6f154de2e2 --- /dev/null +++ b/src/mbgl/renderer/render_light.cpp @@ -0,0 +1,25 @@ +#include <mbgl/renderer/render_light.hpp> + +namespace mbgl { + +RenderLight::RenderLight(const style::Light light_) + : light(std::move(light_)) { +} + +void RenderLight::transition(const CascadeParameters& parameters) { + transitioning = TransitioningLight(light, std::move(transitioning), parameters); +} + +void RenderLight::evaluate(const PropertyEvaluationParameters& parameters) { + evaluated = EvaluatedLight(transitioning, parameters); +} + +bool RenderLight::hasTransition() const { + return transitioning.hasTransition(); +} + +const EvaluatedLight& RenderLight::getEvaluated() const { + return evaluated; +} + +} // namespace mbgl diff --git a/src/mbgl/renderer/render_light.hpp b/src/mbgl/renderer/render_light.hpp index 8f59299552..e609550445 100644 --- a/src/mbgl/renderer/render_light.hpp +++ b/src/mbgl/renderer/render_light.hpp @@ -69,4 +69,22 @@ public: using TransitioningLight = Transitioning<style::LightProperties>; using EvaluatedLight = Evaluated<style::LightProperties>; +class Painter; + +class RenderLight { +public: + RenderLight(const style::Light); + + void transition(const CascadeParameters&); + void evaluate(const PropertyEvaluationParameters&); + bool hasTransition() const; + + const EvaluatedLight& getEvaluated() const; + +private: + TransitioningLight transitioning; + EvaluatedLight evaluated; + style::Light light; +}; + } // namespace mbgl diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 63fb602616..080911b746 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -59,6 +59,7 @@ Style::Style(Scheduler& scheduler_, FileSource& fileSource_, float pixelRatio) spriteAtlas(std::make_unique<SpriteAtlas>(Size{ 1024, 1024 }, pixelRatio)), lineAtlas(std::make_unique<LineAtlas>(Size{ 256, 512 })), light(std::make_unique<Light>()), + renderLight(std::make_unique<RenderLight>(*light)), observer(&nullObserver) { glyphAtlas->setObserver(this); spriteAtlas->setObserver(this); @@ -147,7 +148,7 @@ void Style::setJSON(const std::string& json) { defaultZoom = parser.zoom; defaultBearing = parser.bearing; defaultPitch = parser.pitch; - light = std::make_unique<Light>(parser.light); + setLight(std::make_unique<Light>(parser.light)); glyphAtlas->setURL(parser.glyphURL); spriteAtlas->load(parser.spriteURL, scheduler, fileSource); @@ -310,6 +311,19 @@ void Style::removeRenderLayer(const std::string& id) { } } +void Style::setLight(std::unique_ptr<Light> light_) { + light = std::move(light_); + renderLight = std::make_unique<RenderLight>(*light); +} + +Light* Style::getLight() const { + return light.get(); +} + +RenderLight* Style::getRenderLight() const { + return renderLight.get(); +} + std::string Style::getName() const { return name; } @@ -364,11 +378,11 @@ void Style::update(const UpdateParameters& parameters) { const bool evaluate = cascade || zoomChanged || parameters.updateFlags & Update::RecalculateStyle; if (cascade) { - transitioningLight = TransitioningLight(*light, std::move(transitioningLight), cascadeParameters); + renderLight->transition(cascadeParameters); } - if (evaluate || transitioningLight.hasTransition()) { - evaluatedLight = EvaluatedLight(transitioningLight, evaluationParameters); + if (evaluate || renderLight->hasTransition()) { + renderLight->evaluate(evaluationParameters); } for (const auto& renderSource : renderSources) { @@ -443,7 +457,7 @@ RenderSource* Style::getRenderSource(const std::string& id) const { } bool Style::hasTransitions() const { - if (transitioningLight.hasTransition()) { + if (renderLight->hasTransition()) { return true; } diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 7024927db4..2756be1edd 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -101,6 +101,10 @@ public: bool hasClass(const std::string&) const; std::vector<std::string> getClasses() const; + void setLight(std::unique_ptr<Light>); + Light* getLight() const; + RenderLight* getRenderLight() const; + RenderData getRenderData(MapDebugOptions, float angle) const; std::vector<Feature> queryRenderedFeatures(const ScreenLineString& geometry, @@ -118,10 +122,6 @@ public: std::unique_ptr<SpriteAtlas> spriteAtlas; std::unique_ptr<LineAtlas> lineAtlas; - std::unique_ptr<Light> light; - TransitioningLight transitioningLight; - EvaluatedLight evaluatedLight; - RenderSource* getRenderSource(const std::string& id) const; private: @@ -133,6 +133,9 @@ private: std::vector<std::string> classes; TransitionOptions transitionOptions; + std::unique_ptr<Light> light; + std::unique_ptr<RenderLight> renderLight; + // Defaults std::string name; LatLng defaultLatLng; |