summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r--src/mbgl/renderer/bucket.hpp6
-rw-r--r--src/mbgl/renderer/circle_bucket.cpp23
-rw-r--r--src/mbgl/renderer/circle_bucket.hpp2
-rw-r--r--src/mbgl/renderer/fill_bucket.cpp11
-rw-r--r--src/mbgl/renderer/fill_bucket.hpp2
-rw-r--r--src/mbgl/renderer/line_bucket.cpp35
-rw-r--r--src/mbgl/renderer/line_bucket.hpp5
7 files changed, 84 insertions, 0 deletions
diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp
index 294e50dd8c..84ecabe632 100644
--- a/src/mbgl/renderer/bucket.hpp
+++ b/src/mbgl/renderer/bucket.hpp
@@ -5,6 +5,8 @@
#include <mbgl/tile/geometry_tile_data.hpp>
#include <atomic>
+#include <string>
+#include <unordered_map>
namespace mbgl {
@@ -38,6 +40,10 @@ public:
virtual bool hasData() const = 0;
+ virtual float getQueryRadius(const style::Layer&) const {
+ return 0;
+ };
+
bool needsUpload() const {
return !uploaded;
}
diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp
index e437eff135..94529a66d8 100644
--- a/src/mbgl/renderer/circle_bucket.cpp
+++ b/src/mbgl/renderer/circle_bucket.cpp
@@ -5,6 +5,7 @@
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/circle_layer_impl.hpp>
#include <mbgl/util/constants.hpp>
+#include <mbgl/util/math.hpp>
namespace mbgl {
@@ -97,4 +98,26 @@ void CircleBucket::addFeature(const GeometryTileFeature& feature,
}
}
+template <class Property>
+static float get(const CircleLayer& layer, const std::map<std::string, CircleProgram::PaintPropertyBinders>& paintPropertyBinders) {
+ auto it = paintPropertyBinders.find(layer.getID());
+ if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) {
+ return layer.impl->paint.evaluated.get<Property>().constantOr(Property::defaultValue());
+ } else {
+ return *it->second.statistics<Property>().max();
+ }
+}
+
+float CircleBucket::getQueryRadius(const style::Layer& layer) const {
+ if (!layer.is<CircleLayer>()) {
+ return 0;
+ }
+
+ auto circleLayer = layer.as<CircleLayer>();
+
+ float radius = get<CircleRadius>(*circleLayer, paintPropertyBinders);
+ auto translate = circleLayer->impl->paint.evaluated.get<CircleTranslate>();
+ return radius + util::length(translate[0], translate[1]);
+}
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp
index da12dcdecd..02f60ad2ba 100644
--- a/src/mbgl/renderer/circle_bucket.hpp
+++ b/src/mbgl/renderer/circle_bucket.hpp
@@ -26,6 +26,8 @@ public:
void upload(gl::Context&) override;
void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override;
+ float getQueryRadius(const style::Layer&) const override;
+
gl::VertexVector<CircleLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
gl::SegmentVector<CircleAttributes> segments;
diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp
index d566461673..53bf825d48 100644
--- a/src/mbgl/renderer/fill_bucket.cpp
+++ b/src/mbgl/renderer/fill_bucket.cpp
@@ -4,6 +4,7 @@
#include <mbgl/style/bucket_parameters.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/fill_layer_impl.hpp>
+#include <mbgl/util/math.hpp>
#include <mapbox/earcut.hpp>
@@ -131,4 +132,14 @@ bool FillBucket::hasData() const {
return !triangleSegments.empty() || !lineSegments.empty();
}
+float FillBucket::getQueryRadius(const style::Layer& layer) const {
+ if (!layer.is<FillLayer>()) {
+ return 0;
+ }
+
+ const std::array<float, 2>& translate = layer.as<FillLayer>()->impl->paint.evaluated.get<FillTranslate>();
+ return util::length(translate[0], translate[1]);
+
+}
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp
index f505f313d1..e96cd2ac5e 100644
--- a/src/mbgl/renderer/fill_bucket.hpp
+++ b/src/mbgl/renderer/fill_bucket.hpp
@@ -27,6 +27,8 @@ public:
void upload(gl::Context&) override;
void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override;
+ float getQueryRadius(const style::Layer&) const override;
+
gl::VertexVector<FillLayoutVertex> vertices;
gl::IndexVector<gl::Lines> lines;
gl::IndexVector<gl::Triangles> triangles;
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index 13caea4539..b12bfebf88 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -460,4 +460,39 @@ bool LineBucket::hasData() const {
return !segments.empty();
}
+template <class Property>
+static float get(const LineLayer& layer, const std::map<std::string, LineProgram::PaintPropertyBinders>& paintPropertyBinders) {
+ auto it = paintPropertyBinders.find(layer.getID());
+ if (it == paintPropertyBinders.end() || !it->second.statistics<Property>().max()) {
+ return layer.impl->paint.evaluated.get<Property>().constantOr(Property::defaultValue());
+ } else {
+ return *it->second.statistics<Property>().max();
+ }
+}
+
+float LineBucket::getLineWidth(const style::LineLayer& layer) const {
+ float lineWidth = layer.impl->paint.evaluated.get<LineWidth>();
+ float gapWidth = get<LineGapWidth>(layer, paintPropertyBinders);
+
+ if (gapWidth) {
+ return gapWidth + 2 * lineWidth;
+ } else {
+ return lineWidth;
+ }
+}
+
+float LineBucket::getQueryRadius(const style::Layer& layer) const {
+ if (!layer.is<LineLayer>()) {
+ return 0;
+ }
+
+ auto lineLayer = layer.as<LineLayer>();
+ auto paint = lineLayer->impl->paint;
+
+ const std::array<float, 2>& translate = paint.evaluated.get<LineTranslate>();
+ float offset = get<LineOffset>(*lineLayer, paintPropertyBinders);
+ return getLineWidth(*lineLayer) / 2.0 + std::abs(offset) + util::length(translate[0], translate[1]);
+}
+
+
} // namespace mbgl
diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp
index 5a126ba18e..30198305ad 100644
--- a/src/mbgl/renderer/line_bucket.hpp
+++ b/src/mbgl/renderer/line_bucket.hpp
@@ -14,6 +14,7 @@ namespace mbgl {
namespace style {
class BucketParameters;
+class LineLayer;
} // namespace style
class LineBucket : public Bucket {
@@ -29,6 +30,8 @@ public:
void upload(gl::Context&) override;
void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override;
+ float getQueryRadius(const style::Layer&) const override;
+
style::LineLayoutProperties::PossiblyEvaluated layout;
gl::VertexVector<LineLayoutVertex> vertices;
@@ -59,6 +62,8 @@ private:
std::ptrdiff_t e3;
const uint32_t overscaling;
+
+ float getLineWidth(const style::LineLayer& layer) const;
};
} // namespace mbgl