From fd98607c5fcb14aaa29c046a0b7115f47aaf2ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 20 Aug 2015 15:34:32 -0400 Subject: [PATCH] only update the render order array when there are changes to tiles --- src/mbgl/map/map_context.cpp | 5 +++++ src/mbgl/map/source.cpp | 9 +++++++-- src/mbgl/renderer/painter.cpp | 28 +++++++++++----------------- src/mbgl/renderer/painter.hpp | 6 ++++-- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index a8dd86284..19e8d02ec 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -334,6 +334,7 @@ bool MapContext::renderSync(const TransformState& state, const FrameData& frame) if (!painter) { painter = std::make_unique(data); painter->setup(); + painter->updateRenderOrder(*style); } painter->setDebug(data.getDebug()); @@ -400,6 +401,10 @@ void MapContext::setSprite(const std::string& name, std::shared_ptrupdateRenderOrder(*style); + } + updateFlags |= Update::Repaint; asyncUpdate->send(); } diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 518468af6..4b2ae2cfb 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -529,9 +529,14 @@ void Source::invalidateTiles(const std::unordered_set& ids } void Source::updateTilePtrs() { - tilePtrs.clear(); + std::vector newPtrs; for (const auto& pair : tiles) { - tilePtrs.push_back(pair.second.get()); + newPtrs.push_back(pair.second.get()); + } + + if (tilePtrs != newPtrs) { + tilePtrs = newPtrs; + emitTileLoaded(true); } } diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 1a69b8496..70c621564 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -181,9 +181,6 @@ void Painter::render(const Style& style, TransformState state_, const FrameData& resize(); changeMatrix(); - // Figure out what buckets we have to draw and what order we have to draw them in. - const auto order = determineRenderOrder(style); - // - UPLOAD PASS ------------------------------------------------------------------------------- // Uploads all required buffers and images before we do any actual rendering. { @@ -202,7 +199,6 @@ void Painter::render(const Style& style, TransformState state_, const FrameData& } } - // - CLIPPING MASKS ---------------------------------------------------------------------------- // Draws the clipping masks to the stencil buffer. { @@ -273,6 +269,8 @@ void Painter::renderPass(RenderPass pass_, const float strataThickness) { pass = pass_; + const double zoom = state.getZoom(); + MBGL_DEBUG_GROUP(pass == RenderPass::Opaque ? "opaque" : "translucent"); if (debug::renderTree) { @@ -285,6 +283,13 @@ void Painter::renderPass(RenderPass pass_, for (; it != end; ++it, i += increment) { const auto& item = *it; if (item.bucket && item.tile) { + // Skip this layer if it's outside the range of min/maxzoom. + // This may occur when there /is/ a bucket created for this layer, but the min/max-zoom + // is set to a fractional value, or value that is larger than the source maxzoom. + if (item.layer.bucket->min_zoom > zoom || + item.layer.bucket->max_zoom <= zoom) { + continue; + } if (item.layer.hasRenderPass(pass)) { MBGL_DEBUG_GROUP(item.layer.id + " - " + std::string(item.tile->id)); setStrata(i * strataThickness); @@ -303,8 +308,8 @@ void Painter::renderPass(RenderPass pass_, } } -std::vector Painter::determineRenderOrder(const Style& style) { - std::vector order; +void Painter::updateRenderOrder(const Style& style) { + order.clear(); for (const auto& layerPtr : style.layers) { const auto& layer = *layerPtr; @@ -341,15 +346,6 @@ std::vector Painter::determineRenderOrder(const Style& style) { continue; } - // Skip this layer if it's outside the range of min/maxzoom. - // This may occur when there /is/ a bucket created for this layer, but the min/max-zoom - // is set to a fractional value, or value that is larger than the source maxzoom. - const double zoom = state.getZoom(); - if (layer.bucket->min_zoom > zoom || - layer.bucket->max_zoom <= zoom) { - continue; - } - const auto& tiles = source->getTiles(); for (auto tile : tiles) { assert(tile); @@ -363,8 +359,6 @@ std::vector Painter::determineRenderOrder(const Style& style) { } } } - - return order; } void Painter::renderBackground(const StyleLayer &layer_desc) { diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index ab100b986..06810927b 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -134,12 +134,12 @@ public: bool needsAnimation() const; + void updateRenderOrder(const Style& style); + private: void setupShaders(); mat4 translatedMatrix(const mat4& matrix, const std::array &translation, const TileID &id, TranslateAnchorType anchor); - std::vector determineRenderOrder(const Style& style); - template void renderPass(RenderPass, Iterator it, Iterator end, @@ -201,6 +201,8 @@ private: const float strata_epsilon = 1.0f / (1 << 16); Color background = {{ 0, 0, 0, 0 }}; + std::vector order; + public: FrameHistory frameHistory;