summaryrefslogtreecommitdiff
path: root/src/mbgl/algorithm
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-07-04 18:18:05 +0200
committerKonstantin Käfer <mail@kkaefer.com>2017-07-06 12:32:54 +0200
commit6d526c7b1dad81c8da1cf0d221d0b83ed2be9862 (patch)
tree9ad1555d4c8cf02d16965a083307d8fdcea5e26e /src/mbgl/algorithm
parentfc48ca18018564e26f0498c4f59f77374c1cadbf (diff)
downloadqtlocation-mapboxgl-6d526c7b1dad81c8da1cf0d221d0b83ed2be9862.tar.gz
[core] refactor ClipID generation
Diffstat (limited to 'src/mbgl/algorithm')
-rw-r--r--src/mbgl/algorithm/generate_clip_ids.hpp4
-rw-r--r--src/mbgl/algorithm/generate_clip_ids_impl.hpp26
2 files changed, 16 insertions, 14 deletions
diff --git a/src/mbgl/algorithm/generate_clip_ids.hpp b/src/mbgl/algorithm/generate_clip_ids.hpp
index d917b398af..c4d332343b 100644
--- a/src/mbgl/algorithm/generate_clip_ids.hpp
+++ b/src/mbgl/algorithm/generate_clip_ids.hpp
@@ -25,8 +25,8 @@ private:
std::unordered_multimap<UnwrappedTileID, Leaf> pool;
public:
- template <typename Renderables>
- void update(Renderables& renderables);
+ template <typename Renderable>
+ void update(std::vector<std::reference_wrapper<Renderable>> renderables);
std::map<UnwrappedTileID, ClipID> getStencils() const;
};
diff --git a/src/mbgl/algorithm/generate_clip_ids_impl.hpp b/src/mbgl/algorithm/generate_clip_ids_impl.hpp
index d63ba27b6b..db62214220 100644
--- a/src/mbgl/algorithm/generate_clip_ids_impl.hpp
+++ b/src/mbgl/algorithm/generate_clip_ids_impl.hpp
@@ -7,14 +7,16 @@
namespace mbgl {
namespace algorithm {
-template <typename Renderables>
-void ClipIDGenerator::update(Renderables& renderables) {
+template <typename Renderable>
+void ClipIDGenerator::update(std::vector<std::reference_wrapper<Renderable>> renderables) {
std::size_t size = 0;
+ std::sort(renderables.begin(), renderables.end(),
+ [](const auto& a, const auto& b) { return a.get().id < b.get().id; });
+
const auto end = renderables.end();
for (auto it = renderables.begin(); it != end; it++) {
- auto& tileID = it->first;
- auto& renderable = it->second;
+ auto& renderable = it->get();
if (!renderable.used) {
continue;
}
@@ -28,17 +30,17 @@ void ClipIDGenerator::update(Renderables& renderables) {
// can never be children of the current wrap.
auto child_it = std::next(it);
const auto children_end = std::lower_bound(
- child_it, end, UnwrappedTileID{ static_cast<int16_t>(tileID.wrap + 1), { 0, 0, 0 } },
- [](auto& a, auto& b) { return a.first < b; });
+ child_it, end, UnwrappedTileID{ static_cast<int16_t>(renderable.id.wrap + 1), { 0, 0, 0 } },
+ [](auto& a, auto& b) { return a.get().id < b; });
for (; child_it != children_end; ++child_it) {
- auto& childTileID = child_it->first;
- if (childTileID.isChildOf(tileID)) {
+ auto& childTileID = child_it->get().id;
+ if (childTileID.isChildOf(it->get().id)) {
leaf.add(childTileID.canonical);
}
}
// Find a leaf with matching children.
- for (auto its = pool.equal_range(tileID); its.first != its.second; ++its.first) {
+ for (auto its = pool.equal_range(renderable.id); its.first != its.second; ++its.first) {
auto& existing = its.first->second;
if (existing == leaf) {
leaf.clip = existing.clip;
@@ -50,7 +52,7 @@ void ClipIDGenerator::update(Renderables& renderables) {
size++;
}
- pool.emplace(tileID, std::move(leaf));
+ pool.emplace(renderable.id, std::move(leaf));
}
if (size > 0) {
@@ -60,8 +62,8 @@ void ClipIDGenerator::update(Renderables& renderables) {
// We are starting our count with 1 since we need at least 1 bit set to distinguish between
// areas without any tiles whatsoever and the current area.
uint8_t count = 1;
- for (auto& pair : renderables) {
- auto& renderable = pair.second;
+ for (auto& it : renderables) {
+ auto& renderable = it.get();
if (!renderable.used) {
continue;
}