diff options
author | Ansis Brammanis <brammanis@gmail.com> | 2015-01-23 17:05:30 -0500 |
---|---|---|
committer | Ansis Brammanis <brammanis@gmail.com> | 2015-01-23 17:05:30 -0500 |
commit | c5d5a799beb0c3211d8a1b28b8b3880acf38d51a (patch) | |
tree | b321cd7bf785ed7e73ad1258e0288d11f6fb51ae /src/mbgl/renderer | |
parent | 0c2ffc251c519af76a0ed6dd1925621ebe393e7b (diff) | |
download | qtlocation-mapboxgl-c5d5a799beb0c3211d8a1b28b8b3880acf38d51a.tar.gz |
Don't permanently crossfade fill patterns.
js: 00e11591106dae7eb02eff0328364d8ec03fdaa5
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 25 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/renderer/painter_fill.cpp | 16 |
3 files changed, 43 insertions, 3 deletions
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 0c17d52b5d..f4b6b80e2e 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -232,7 +232,7 @@ void Painter::render(const Style& style, const std::set<util::ptr<StyleSource>>& drawClippingMasks(sources); - frameHistory.record(time, state.getNormalizedZoom()); + recordZoom(time, state.getNormalizedZoom()); // Actually render the layers if (debug::renderTree) { std::cout << "{" << std::endl; indent++; } @@ -459,3 +459,26 @@ mat4 Painter::translatedMatrix(const mat4& matrix, const std::array<float, 2> &t return vtxMatrix; } } + +void Painter::recordZoom(const timestamp time, const float zoom) { + frameHistory.record(time, zoom); + + if (lastZoom < 0) { + // first frame ever + lastIntegerZoom = std::floor(zoom); + lastZoom = zoom; + } + + // check whether an integer zoom level was passed since the last frame + // and if yes, record it with the time. Used for transitioning patterns. + if (std::floor(lastZoom) < std::floor(zoom)) { + lastIntegerZoom = std::floor(zoom); + lastIntegerZoomTime = time; + + } else if (std::floor(lastZoom) > std::floor(zoom)) { + lastIntegerZoom = std::floor(zoom) + 1; + lastIntegerZoomTime = time; + } + + lastZoom = zoom; +} diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 4d4876a6f1..5a42070200 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -139,6 +139,7 @@ private: mat4 translatedMatrix(const mat4& matrix, const std::array<float, 2> &translation, const Tile::ID &id, TranslateAnchorType anchor); void prepareTile(const Tile& tile); + void recordZoom(const timestamp time, const float zoom); template <typename BucketProperties, typename StyleProperties> void renderSDF(SymbolBucket &bucket, @@ -191,6 +192,10 @@ private: RenderPass pass = RenderPass::Opaque; const float strata_epsilon = 1.0f / (1 << 16); + int lastIntegerZoom; + timestamp lastIntegerZoomTime = 0; + float lastZoom = -1; + public: FrameHistory frameHistory; diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 324dacfcd5..5e8f46d340 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -60,8 +60,20 @@ void Painter::renderFill(FillBucket& bucket, util::ptr<StyleLayer> layer_desc, c // Image fill. if (pass == RenderPass::Translucent) { const SpriteAtlasPosition pos = spriteAtlas.getPosition(properties.image, true); - const float mix = std::fmod(float(state.getZoom()), 1.0f); - const float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z); + float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z); + + float mix; + float duration = 300 * 1_millisecond; + const float fraction = std::fmod(float(state.getZoom()), 1.0f); + float t = std::min((util::now() - lastIntegerZoomTime) / duration, 1.0f); + if (state.getZoom() > lastIntegerZoom) { + // zooming in + mix = fraction + (1.0f - fraction) * t; + factor *= 2.0; + } else { + // zooming out + mix = fraction - fraction * t; + } mat3 patternMatrix; matrix::identity(patternMatrix); |