From bcdbbbcac2e331ea3a23085b1e0f5a0f5d25e0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 1 Nov 2016 16:14:33 +0100 Subject: [PATCH] [core] don't assign clip IDs to tiles that aren't rendered --- src/mbgl/algorithm/generate_clip_ids_impl.hpp | 7 +++++ src/mbgl/renderer/render_tile.hpp | 1 + src/mbgl/style/source_impl.cpp | 6 ++-- src/mbgl/style/source_impl.hpp | 2 +- src/mbgl/style/style.cpp | 1 + test/algorithm/generate_clip_ids.test.cpp | 1 + test/api/annotations.test.cpp | 29 ++++++++++++++++++ .../annotations/debug_empty/expected.png | Bin 0 -> 1238 bytes .../annotations/debug_sparse/expected.png | Bin 0 -> 2933 bytes 9 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/annotations/debug_empty/expected.png create mode 100644 test/fixtures/annotations/debug_sparse/expected.png diff --git a/src/mbgl/algorithm/generate_clip_ids_impl.hpp b/src/mbgl/algorithm/generate_clip_ids_impl.hpp index 47f7df12f..9b550fcbb 100644 --- a/src/mbgl/algorithm/generate_clip_ids_impl.hpp +++ b/src/mbgl/algorithm/generate_clip_ids_impl.hpp @@ -15,6 +15,10 @@ void ClipIDGenerator::update(Renderables& renderables) { for (auto it = renderables.begin(); it != end; it++) { auto& tileID = it->first; auto& renderable = it->second; + if (!renderable.used) { + continue; + } + renderable.clip = {}; Leaf leaf{ renderable.clip }; @@ -58,6 +62,9 @@ void ClipIDGenerator::update(Renderables& renderables) { uint8_t count = 1; for (auto& pair : renderables) { auto& renderable = pair.second; + if (!renderable.used) { + continue; + } renderable.clip.mask |= mask; // Assign only to clip IDs that have no value yet. diff --git a/src/mbgl/renderer/render_tile.hpp b/src/mbgl/renderer/render_tile.hpp index 74669faaf..e2e0c3d65 100644 --- a/src/mbgl/renderer/render_tile.hpp +++ b/src/mbgl/renderer/render_tile.hpp @@ -24,6 +24,7 @@ public: Tile& tile; ClipID clip; mat4 matrix; + bool used = false; mat4 translatedMatrix(const std::array& translate, style::TranslateAnchorType anchor, diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index 75668fc3b..d31a6bf5a 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -70,11 +70,13 @@ void Source::Impl::startRender(algorithm::ClipIDGenerator& generator, void Source::Impl::finishRender(Painter& painter) { for (auto& pair : renderTiles) { auto& tile = pair.second; - painter.renderTileDebug(tile); + if (tile.used) { + painter.renderTileDebug(tile); + } } } -const std::map& Source::Impl::getRenderTiles() const { +std::map& Source::Impl::getRenderTiles() { return renderTiles; } diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index 1041ebffe..e6340ae1c 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -63,7 +63,7 @@ public: const TransformState&); void finishRender(Painter&); - const std::map& getRenderTiles() const; + std::map& getRenderTiles(); std::unordered_map> queryRenderedFeatures(const QueryParameters&) const; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index f14be5139..acbc949b4 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -404,6 +404,7 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions) const { auto bucket = tile.tile.getBucket(*layer); if (bucket) { result.order.emplace_back(*layer, &tile, bucket); + tile.used = true; } } } diff --git a/test/algorithm/generate_clip_ids.test.cpp b/test/algorithm/generate_clip_ids.test.cpp index 5b7f4afb2..8ca0191b3 100644 --- a/test/algorithm/generate_clip_ids.test.cpp +++ b/test/algorithm/generate_clip_ids.test.cpp @@ -6,6 +6,7 @@ using namespace mbgl; struct Renderable { ClipID clip; + bool used = true; bool operator==(const Renderable& rhs) const { return clip == rhs.clip; diff --git a/test/api/annotations.test.cpp b/test/api/annotations.test.cpp index 06a0a61b0..b143bd961 100644 --- a/test/api/annotations.test.cpp +++ b/test/api/annotations.test.cpp @@ -419,3 +419,32 @@ TEST(Annotations, VisibleFeatures) { features.erase(std::unique(features.begin(), features.end(), sameID), features.end()); EXPECT_EQ(features.size(), ids.size()); } + + +TEST(Annotations, DebugEmpty) { + // This test should render nothing, not even the tile borders. Tile borders are only rendered + // when there is an actual tile we're trying to render, but since there is no annotation, we + // should not render them. + AnnotationTest test; + + test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); + test.map.setDebug(MapDebugOptions::TileBorders); + test.map.setZoom(1); + + test.checkRendering("debug_empty"); +} + + +TEST(Annotations, DebugSparse) { + // This test should only render the top right tile with the associated tile border, but no other + // tiles because they're all empty. + AnnotationTest test; + + test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json")); + test.map.setDebug(MapDebugOptions::TileBorders); + test.map.setZoom(1); + test.map.addAnnotationIcon("default_marker", namedMarker("default_marker.png")); + test.map.addAnnotation(SymbolAnnotation { Point(10, 10), "default_marker" }); + + test.checkRendering("debug_sparse"); +} diff --git a/test/fixtures/annotations/debug_empty/expected.png b/test/fixtures/annotations/debug_empty/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..04f8682f8806e2d9a513e366fb46fb1b2336a583 GIT binary patch literal 1238 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;3=Aw2JY5_^ zDj45hFa#+)wBW1%+iZ>whr|O7jLd925(WvQjL|?CO$np9fG)Y<12Z$D4FjXpE{9-X PX~f{^>gTe~DWM4f@<$XU literal 0 HcmV?d00001 diff --git a/test/fixtures/annotations/debug_sparse/expected.png b/test/fixtures/annotations/debug_sparse/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..3c1ad1599cccc1116793e8b5801441b40047253c GIT binary patch literal 2933 zcmeHJ`CroM7XE@bZd2hfuGrwzQe737BEMpj0tsAVITB3^evaYrDK!9U^tbbq-0bk6xa?|aU9o^#&M=gsy-d+gIT z)&>AzpXWK(9{>QPazTLRXDSmCUmLj>CH&yw4A2HmmHpN zJy|Pl8C*;*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