diff options
author | Gali Nelle <galinelle.mapbox@gmail.com> | 2020-04-15 18:15:29 +0300 |
---|---|---|
committer | galinelle <paolo.angelelli@mapbox.com> | 2020-04-17 22:26:32 +0300 |
commit | fea8a83e7f72ba59e41e713b3a37f6b946565d74 (patch) | |
tree | a1ca136e4d33d63f9ffb07cf6aa107c331ace992 /src/mbgl/renderer/layers | |
parent | c4b061bd959a0efa5d0202d16d39e92e4f416abb (diff) | |
download | qtlocation-mapboxgl-fea8a83e7f72ba59e41e713b3a37f6b946565d74.tar.gz |
Introduce a mean to add render features in layers with no sources
This change also uses the support in the LocationIndicator layer, to
return a point feature when queried in correspondence of the location
indicator.
Diffstat (limited to 'src/mbgl/renderer/layers')
-rw-r--r-- | src/mbgl/renderer/layers/render_location_indicator_layer.cpp | 40 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_location_indicator_layer.hpp | 1 |
2 files changed, 38 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 diff --git a/src/mbgl/renderer/layers/render_location_indicator_layer.hpp b/src/mbgl/renderer/layers/render_location_indicator_layer.hpp index 0adb328df9..78d1203731 100644 --- a/src/mbgl/renderer/layers/render_location_indicator_layer.hpp +++ b/src/mbgl/renderer/layers/render_location_indicator_layer.hpp @@ -21,6 +21,7 @@ private: void prepare(const LayerPrepareParameters &) override; void render(PaintParameters &) override; + void populateDynamicRenderFeatureIndex(DynamicFeatureIndex &) const override; bool contextDestroyed = false; std::unique_ptr<RenderLocationIndicatorImpl> renderImpl; |