summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-11-14 11:57:02 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-11-15 12:39:49 -0800
commitbcad3b6d4b4066e151db51a6abc8618ed1d39f46 (patch)
tree8bbe44fc84bbfdf0d90eb98f1d1348a4d0ed584c
parentaeba7cce84bc066d19e8e695be29ce301d06b9c0 (diff)
downloadqtlocation-mapboxgl-bcad3b6d4b4066e151db51a6abc8618ed1d39f46.tar.gz
[core] Use indexed rendering for collision boxes
-rw-r--r--src/mbgl/layout/symbol_layout.cpp30
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp4
-rw-r--r--src/mbgl/renderer/symbol_bucket.cpp3
-rw-r--r--src/mbgl/renderer/symbol_bucket.hpp8
4 files changed, 33 insertions, 12 deletions
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 932745aa57..d974e6a357 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -507,14 +507,28 @@ void SymbolLayout::addToDebugBuffers(CollisionTile& collisionTile, SymbolBucket&
const float maxZoom = util::clamp(zoom + util::log2(box.maxScale), util::MIN_ZOOM_F, util::MAX_ZOOM_F);
const float placementZoom = util::clamp(zoom + util::log2(box.placementScale), util::MIN_ZOOM_F, util::MAX_ZOOM_F);
- collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, tl, maxZoom, placementZoom),
- CollisionBoxProgram::vertex(anchor, tr, maxZoom, placementZoom));
- collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, tr, maxZoom, placementZoom),
- CollisionBoxProgram::vertex(anchor, br, maxZoom, placementZoom));
- collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, br, maxZoom, placementZoom),
- CollisionBoxProgram::vertex(anchor, bl, maxZoom, placementZoom));
- collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, bl, maxZoom, placementZoom),
- CollisionBoxProgram::vertex(anchor, tl, maxZoom, placementZoom));
+ static constexpr std::size_t vertexLength = 4;
+ static constexpr std::size_t indexLength = 8;
+
+ if (collisionBox.segments.empty() || collisionBox.segments.back().vertexLength + vertexLength > std::numeric_limits<uint16_t>::max()) {
+ collisionBox.segments.emplace_back(collisionBox.vertices.vertexSize(), collisionBox.lines.indexSize());
+ }
+
+ auto& segment = collisionBox.segments.back();
+ uint16_t index = segment.vertexLength;
+
+ collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, tl, maxZoom, placementZoom));
+ collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, tr, maxZoom, placementZoom));
+ collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, br, maxZoom, placementZoom));
+ collisionBox.vertices.emplace_back(CollisionBoxProgram::vertex(anchor, bl, maxZoom, placementZoom));
+
+ collisionBox.lines.emplace_back(index + 0, index + 1);
+ collisionBox.lines.emplace_back(index + 1, index + 2);
+ collisionBox.lines.emplace_back(index + 2, index + 3);
+ collisionBox.lines.emplace_back(index + 3, index + 0);
+
+ segment.vertexLength += vertexLength;
+ segment.indexLength += indexLength;
}
};
populateCollisionBox(symbolInstance.textCollisionFeature);
diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp
index d2dee5d99d..8c1948e458 100644
--- a/src/mbgl/renderer/painter_symbol.cpp
+++ b/src/mbgl/renderer/painter_symbol.cpp
@@ -130,7 +130,9 @@ void Painter::renderSymbol(PaintParameters& parameters,
uniforms::u_zoom::Value{ float(state.getZoom() * 10) },
uniforms::u_maxzoom::Value{ float((tile.id.canonical.z + 1) * 10) },
},
- *bucket.collisionBox.vertexBuffer
+ *bucket.collisionBox.vertexBuffer,
+ *bucket.collisionBox.indexBuffer,
+ bucket.collisionBox.segments
);
}
}
diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp
index 7fb3473967..81170646bc 100644
--- a/src/mbgl/renderer/symbol_bucket.cpp
+++ b/src/mbgl/renderer/symbol_bucket.cpp
@@ -29,6 +29,7 @@ void SymbolBucket::upload(gl::Context& context) {
if (!collisionBox.vertices.empty()) {
collisionBox.vertexBuffer = context.createVertexBuffer(std::move(collisionBox.vertices));
+ collisionBox.indexBuffer = context.createIndexBuffer(std::move(collisionBox.lines));
}
uploaded = true;
@@ -55,7 +56,7 @@ bool SymbolBucket::hasIconData() const {
}
bool SymbolBucket::hasCollisionBoxData() const {
- return bool(collisionBox.vertexBuffer);
+ return !collisionBox.segments.empty();
}
} // namespace mbgl
diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp
index f1fc3d324e..327049b280 100644
--- a/src/mbgl/renderer/symbol_bucket.hpp
+++ b/src/mbgl/renderer/symbol_bucket.hpp
@@ -52,8 +52,12 @@ public:
} icon;
struct CollisionBoxBuffer {
- gl::VertexVector<CollisionBoxVertex, gl::Lines> vertices;
- optional<gl::VertexBuffer<CollisionBoxVertex, gl::Lines>> vertexBuffer;
+ gl::VertexVector<CollisionBoxVertex> vertices;
+ gl::IndexVector<gl::Lines> lines;
+ std::vector<gl::Segment> segments;
+
+ optional<gl::VertexBuffer<CollisionBoxVertex>> vertexBuffer;
+ optional<gl::IndexBuffer<gl::Lines>> indexBuffer;
} collisionBox;
};