-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom Drawable Layer v1 + DrawableBuilder thick lines (#1699)
- Loading branch information
1 parent
6a8be9a
commit 89b9c39
Showing
56 changed files
with
1,638 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#pragma once | ||
|
||
#include <mbgl/tile/geometry_tile_data.hpp> | ||
#include <mbgl/style/types.hpp> | ||
#include <mbgl/gfx/vertex_vector.hpp> | ||
#include <mbgl/gfx/index_vector.hpp> | ||
#include <mbgl/programs/segment.hpp> | ||
#include <mbgl/util/math.hpp> | ||
|
||
#include <cstdint> | ||
#include <cstddef> | ||
#include <memory> | ||
#include <vector> | ||
#include <functional> | ||
#include <optional> | ||
|
||
namespace mbgl { | ||
namespace gfx { | ||
|
||
class PolylineGeneratorDistances { | ||
public: | ||
PolylineGeneratorDistances(double clipStart_, double clipEnd_, double total_) | ||
: clipStart(clipStart_), | ||
clipEnd(clipEnd_), | ||
total(total_) {} | ||
|
||
// Scale line distance from tile units to [0, 2^15). | ||
double scaleToMaxLineDistance(double tileDistance) const; | ||
|
||
private: | ||
double clipStart; | ||
double clipEnd; | ||
double total; | ||
}; | ||
|
||
struct PolylineGeneratorOptions { | ||
FeatureType type{FeatureType::LineString}; | ||
style::LineJoinType joinType{style::LineJoinType::Miter}; | ||
float miterLimit{2.f}; | ||
style::LineCapType beginCap{style::LineCapType::Butt}; | ||
style::LineCapType endCap{style::LineCapType::Butt}; | ||
float roundLimit{1.f}; | ||
uint32_t overscaling{1}; // TODO: what is this??? | ||
std::optional<PolylineGeneratorDistances> lineDistances; | ||
}; | ||
|
||
template <class PolylineLayoutVertex, class PolylineSegment> | ||
class PolylineGenerator { | ||
public: | ||
using Vertices = gfx::VertexVector<PolylineLayoutVertex>; | ||
using Segments = std::vector<PolylineSegment>; | ||
using LayoutVertexFunc = std::function<PolylineLayoutVertex( | ||
Point<int16_t> p, Point<double> e, bool round, bool up, int8_t dir, int32_t linesofar /*= 0*/)>; | ||
using CreateSegmentFunc = std::function<PolylineSegment(std::size_t vertexOffset, std::size_t indexOffset)>; | ||
using GetSegmentFunc = std::function<mbgl::SegmentBase&(PolylineSegment& segment)>; | ||
using Indexes = gfx::IndexVector<gfx::Triangles>; | ||
|
||
public: | ||
PolylineGenerator(Vertices& polylineVertices, | ||
LayoutVertexFunc layoutVertexFunc, | ||
Segments& polylineSegments, | ||
CreateSegmentFunc createSegmentFunc, | ||
GetSegmentFunc getSegmentFunc, | ||
Indexes& polylineIndexes); | ||
~PolylineGenerator() = default; | ||
|
||
void generate(const GeometryCoordinates& coordinates, const PolylineGeneratorOptions& options); | ||
|
||
private: | ||
struct TriangleElement; | ||
|
||
void addCurrentVertex(const GeometryCoordinate& currentCoordinate, | ||
double& distance, | ||
const Point<double>& normal, | ||
double endLeft, | ||
double endRight, | ||
bool round, | ||
std::size_t startVertex, | ||
std::vector<TriangleElement>& triangleStore, | ||
std::optional<PolylineGeneratorDistances> lineDistances); | ||
void addPieSliceVertex(const GeometryCoordinate& currentVertex, | ||
double distance, | ||
const Point<double>& extrude, | ||
bool lineTurnsLeft, | ||
std::size_t startVertex, | ||
std::vector<TriangleElement>& triangleStore, | ||
std::optional<PolylineGeneratorDistances> lineDistances); | ||
|
||
private: | ||
Vertices& vertices; | ||
LayoutVertexFunc layoutVertex; | ||
Segments& segments; | ||
CreateSegmentFunc createSegment; | ||
GetSegmentFunc getSegment; | ||
Indexes& indexes; | ||
|
||
std::ptrdiff_t e1; | ||
std::ptrdiff_t e2; | ||
std::ptrdiff_t e3; | ||
}; | ||
|
||
} // namespace gfx | ||
} // namespace mbgl |
18 changes: 18 additions & 0 deletions
18
include/mbgl/layermanager/custom_drawable_layer_factory.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <mbgl/layermanager/layer_factory.hpp> | ||
#include <mbgl/style/layer.hpp> | ||
|
||
#include <array> | ||
|
||
namespace mbgl { | ||
|
||
class CustomDrawableLayerFactory : public LayerFactory { | ||
protected: | ||
const style::LayerTypeInfo* getTypeInfo() const noexcept final; | ||
std::unique_ptr<style::Layer> createLayer(const std::string& id, | ||
const style::conversion::Convertible& value) noexcept final; | ||
std::unique_ptr<RenderLayer> createRenderLayer(Immutable<style::Layer::Impl>) noexcept final; | ||
}; | ||
|
||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include <mbgl/style/layer.hpp> | ||
#include <mbgl/gfx/shader_registry.hpp> | ||
#include <mbgl/map/transform_state.hpp> | ||
#include <mbgl/renderer/update_parameters.hpp> | ||
#include <mbgl/renderer/render_tree.hpp> | ||
#include <mbgl/renderer/change_request.hpp> | ||
|
||
#include <array> | ||
#include <memory> | ||
|
||
namespace mbgl { | ||
namespace style { | ||
|
||
class CustomDrawableLayerHost { | ||
public: | ||
virtual ~CustomDrawableLayerHost() = default; | ||
|
||
virtual void initialize() = 0; | ||
|
||
virtual void update(RenderLayer& proxyLayer, | ||
gfx::ShaderRegistry& shaders, | ||
gfx::Context& context, | ||
const TransformState& state, | ||
const std::shared_ptr<UpdateParameters>&, | ||
const RenderTree& renderTree, | ||
UniqueChangeRequestVec& changes) = 0; | ||
|
||
virtual void deinitialize() = 0; | ||
}; | ||
|
||
class CustomDrawableLayer final : public Layer { | ||
public: | ||
CustomDrawableLayer(const std::string& id, std::unique_ptr<CustomDrawableLayerHost> host); | ||
|
||
CustomDrawableLayer(const CustomDrawableLayer&) = delete; | ||
~CustomDrawableLayer() final; | ||
class Impl; | ||
const Impl& impl() const; | ||
Mutable<Impl> mutableImpl() const; | ||
|
||
private: | ||
std::optional<conversion::Error> setPropertyInternal(const std::string& name, | ||
const conversion::Convertible& value) final; | ||
StyleProperty getProperty(const std::string&) const final; | ||
std::unique_ptr<Layer> cloneRef(const std::string& id) const final; | ||
Mutable<Layer::Impl> mutableBaseImpl() const final; | ||
}; | ||
|
||
} // namespace style | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.