summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/layers/render_location_indicator_layer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/renderer/layers/render_location_indicator_layer.cpp')
-rw-r--r--src/mbgl/renderer/layers/render_location_indicator_layer.cpp40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp
index 933f674b89..c3872e92d0 100644
--- a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp
+++ b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp
@@ -1,5 +1,6 @@
#include <array>
#include <mapbox/cheap_ruler.hpp>
+#include <mbgl/geometry/feature_index.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/gfx/renderer_backend.hpp>
#include <mbgl/gl/context.hpp>
@@ -266,6 +267,7 @@ public:
~Texture() { release(); }
void release() {
MBGL_CHECK_ERROR(glDeleteTextures(1, &texId));
+ texId = 0;
image = nullptr;
}
/*
@@ -338,7 +340,12 @@ public:
float pixelRatio = 1.0f;
};
- RenderLocationIndicatorImpl() : ruler(0, mapbox::cheap_ruler::CheapRuler::Meters) {}
+ RenderLocationIndicatorImpl(std::string sourceLayer)
+ : ruler(0, mapbox::cheap_ruler::CheapRuler::Meters),
+ feature(std::make_shared<mbgl::Feature>()),
+ featureEnvelope(std::make_shared<mapbox::geometry::polygon<int64_t>>()) {
+ feature->sourceLayer = std::move(sourceLayer);
+ }
static bool hasAnisotropicFiltering() {
const auto* extensions = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
@@ -404,7 +411,6 @@ public:
projectionCircle = params.projectionMatrix;
const Point<double> positionMercator = project(params.puckPosition, *params.state);
- mat4 translation;
matrix::identity(translation);
matrix::translate(translation, translation, positionMercator.x, positionMercator.y, 0.0);
matrix::multiply(projectionCircle, projectionCircle, translation);
@@ -422,6 +428,25 @@ public:
}
}
oldParams = params;
+ dirtyFeature = true;
+ }
+
+ void updateFeature() {
+ if (!dirtyFeature) return;
+ dirtyFeature = false;
+ featureEnvelope->clear();
+ if (!texPuck || !texPuck->isValid()) return;
+
+ feature->geometry =
+ mapbox::geometry::point<double>{oldParams.puckPosition.latitude(), oldParams.puckPosition.longitude()};
+ mapbox::geometry::linear_ring<int64_t> border;
+ for (const auto& v : puckGeometry) {
+ vec4 p{v.x, v.y, 0, 1};
+ matrix::transformMat4(p, p, translation);
+ border.push_back(Point<int64_t>{int64_t(p[0]), int64_t(p[1])});
+ }
+ border.push_back(border.front());
+ featureEnvelope->push_back(border);
}
protected:
@@ -682,6 +707,7 @@ protected:
std::array<vec2, 4> puckGeometry;
std::array<vec2, 4> hatGeometry;
std::array<vec2, 4> texCoords;
+ mbgl::mat4 translation;
mbgl::mat4 projectionCircle;
mbgl::mat4 projectionPuck;
@@ -690,9 +716,12 @@ protected:
bool bearingChanged = false;
mbgl::LocationIndicatorRenderParameters oldParams;
bool initialized = false;
+ bool dirtyFeature = true;
public:
mbgl::LocationIndicatorRenderParameters parameters;
+ std::shared_ptr<mbgl::Feature> feature;
+ std::shared_ptr<mapbox::geometry::polygon<int64_t>> featureEnvelope;
static bool anisotropicFilteringAvailable;
};
@@ -709,7 +738,7 @@ inline const LocationIndicatorLayer::Impl& impl(const Immutable<style::Layer::Im
RenderLocationIndicatorLayer::RenderLocationIndicatorLayer(Immutable<style::LocationIndicatorLayer::Impl> _impl)
: RenderLayer(makeMutable<LocationIndicatorLayerProperties>(std::move(_impl))),
- renderImpl(std::make_unique<RenderLocationIndicatorImpl>()),
+ renderImpl(std::make_unique<RenderLocationIndicatorImpl>(impl(baseImpl).id)),
unevaluated(impl(baseImpl).paint.untransitioned()) {
assert(gfx::BackendScope::exists());
}
@@ -804,4 +833,9 @@ void RenderLocationIndicatorLayer::render(PaintParameters& paintParameters) {
glContext.setDirtyState();
}
+void RenderLocationIndicatorLayer::populateDynamicRenderFeatureIndex(DynamicFeatureIndex& index) const {
+ renderImpl->updateFeature();
+ if (!renderImpl->featureEnvelope->empty()) index.insert(renderImpl->feature, renderImpl->featureEnvelope);
+}
+
} // namespace mbgl