Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] don't assign clip IDs to tiles that aren't rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed Nov 8, 2016
1 parent 687ee1e commit 01b378e
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/mbgl/algorithm/generate_clip_ids_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/renderer/render_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RenderTile {
Tile& tile;
ClipID clip;
mat4 matrix;
bool used = false;

mat4 translatedMatrix(const std::array<float, 2>& translate,
style::TranslateAnchorType anchor,
Expand Down
6 changes: 4 additions & 2 deletions src/mbgl/style/source_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnwrappedTileID, RenderTile>& Source::Impl::getRenderTiles() const {
std::map<UnwrappedTileID, RenderTile>& Source::Impl::getRenderTiles() {
return renderTiles;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/source_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Source::Impl : public TileObserver, private util::noncopyable {
const TransformState&);
void finishRender(Painter&);

const std::map<UnwrappedTileID, RenderTile>& getRenderTiles() const;
std::map<UnwrappedTileID, RenderTile>& getRenderTiles();

std::unordered_map<std::string, std::vector<Feature>>
queryRenderedFeatures(const QueryParameters&) const;
Expand Down
1 change: 1 addition & 0 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/algorithm/generate_clip_ids.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using namespace mbgl;

struct Renderable {
ClipID clip;
bool used = true;

bool operator==(const Renderable& rhs) const {
return clip == rhs.clip;
Expand Down
29 changes: 29 additions & 0 deletions test/api/annotations.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(10, 10), "default_marker" });

test.checkRendering("debug_sparse");
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 01b378e

Please sign in to comment.