Custom drawable layer: Simple Fill (#1810)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alex Cristici <alex.cristici@gmail.com>
This commit is contained in:
Stefan Karschti
2023-11-06 20:43:58 +02:00
committed by GitHub
parent ef69472f56
commit a73e88fee2
11 changed files with 551 additions and 221 deletions

View File

@@ -204,6 +204,8 @@ public:
/// return the curent vertex count
std::size_t curVertexCount() const;
bool empty() const { return !(drawables.size() || curVertexCount()); }
protected:
/// Create an instance of the appropriate drawable type
virtual UniqueDrawable createDrawable() const = 0;

View File

@@ -0,0 +1,25 @@
#pragma once
#include <mbgl/util/geometry.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/gfx/vertex_vector.hpp>
#include <mbgl/gfx/index_vector.hpp>
#include <mbgl/programs/fill_program.hpp>
namespace mbgl {
namespace gfx {
void generateFillBuffers(const GeometryCollection& geometry,
gfx::VertexVector<FillLayoutVertex>& vertices,
SegmentVector<FillAttributes>& triangleSegments,
gfx::IndexVector<Triangles>& triangles);
void generateFillAndOutineBuffers(const GeometryCollection& geometry,
gfx::VertexVector<FillLayoutVertex>& vertices,
SegmentVector<FillAttributes>& lineSegments,
gfx::IndexVector<gfx::Lines>& lines,
SegmentVector<FillAttributes>& triangleSegments,
gfx::IndexVector<gfx::Triangles>& triangles);
} // namespace gfx
} // namespace mbgl

View File

@@ -41,6 +41,11 @@ public:
gfx::PolylineGeneratorOptions geometry;
};
struct FillOptions {
Color color;
float opacity = 1.f;
};
public:
/// @brief Construct a new Interface object (internal core use only)
Interface(RenderLayer& layer,
@@ -72,6 +77,13 @@ public:
*/
void setLineOptions(const LineOptions& options);
/**
* @brief Set the fill options
*
* @param options
*/
void setFillOptions(const FillOptions& options);
/**
* @brief Add a polyline
*
@@ -80,17 +92,14 @@ public:
*/
void addPolyline(const GeometryCoordinates& coordinates);
void addFill(const GeometryCollection& geometry);
/**
* @brief Finishe the current drawable building session
* @brief Finish the current drawable building session
*
*/
void finish();
protected:
gfx::ShaderPtr lineShaderDefault() const;
std::unique_ptr<gfx::DrawableBuilder> createBuilder(const std::string& name, gfx::ShaderPtr shader) const;
public:
RenderLayer& layer;
LayerGroupBasePtr& layerGroup;
@@ -102,9 +111,17 @@ public:
UniqueChangeRequestVec& changes;
private:
gfx::ShaderPtr lineShaderDefault() const;
gfx::ShaderPtr fillShaderDefault() const;
std::unique_ptr<gfx::DrawableBuilder> createBuilder(const std::string& name, gfx::ShaderPtr shader) const;
gfx::ShaderPtr lineShader;
gfx::ShaderPtr fillShader;
std::unique_ptr<gfx::DrawableBuilder> builder;
std::optional<OverscaledTileID> tileID;
LineOptions lineOptions;
FillOptions fillOptions;
};
class CustomDrawableLayer final : public Layer {