Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triangulated fill outlines #1780

Closed
wants to merge 70 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
b92ecfe
unoptimized v1 with magenta color outlines
stefankarschti Oct 18, 2023
c81c7c1
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 18, 2023
5c5bfa5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2023
6721c5e
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 19, 2023
ef597df
fill outline (non-pattern) implementation
stefankarschti Oct 19, 2023
0ab6865
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2023
be19c3a
implement fill pattern outline
stefankarschti Oct 19, 2023
c8f35e8
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 19, 2023
081e0fa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2023
c34669d
fix legacy compilation errors
stefankarschti Oct 19, 2023
d64a271
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 19, 2023
a9e2ede
pass color and opacity
stefankarschti Oct 19, 2023
5c5b283
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 20, 2023
420c382
eliminate duplicate calls to updateRenderTileIDs
stefankarschti Oct 20, 2023
47d1a3b
fix fill outline, non-pattern case
stefankarschti Oct 20, 2023
0ebea92
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 20, 2023
e5d1477
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 20, 2023
c4e1757
change outline to 1.0f to pass maximum render tests
stefankarschti Oct 20, 2023
6787046
Merge branch 'metal-fill-outline' of github.com:stefankarschti/maplib…
stefankarschti Oct 20, 2023
93e515b
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 23, 2023
928a491
use vector instead of map for uniform buffer array
stefankarschti Oct 23, 2023
194bb2b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2023
4728e55
update some UBOs just once per drawable
stefankarschti Oct 23, 2023
24d413f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2023
c3234a0
Revert "use vector instead of map for uniform buffer array"
stefankarschti Oct 24, 2023
75c9a56
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 24, 2023
7591a87
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 26, 2023
82f4d86
Merge branch 'main' into metal-fill-outline
stefankarschti Oct 27, 2023
9c18928
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 6, 2023
5ea5ffd
turn off synchronous metal rendering
stefankarschti Nov 6, 2023
acf4f31
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 6, 2023
584f12d
merge fixes
stefankarschti Nov 7, 2023
2cdb0a7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2023
793aafa
correction
stefankarschti Nov 7, 2023
1fbe5b0
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 7, 2023
f3ea78d
parameter order for legacy build
stefankarschti Nov 7, 2023
2ce98b3
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 8, 2023
7c9385f
initial version of the basic line shader
stefankarschti Nov 8, 2023
e5df393
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 8, 2023
b821d7c
LineBasicShader v2. Removed blur, gap width and offset capabilities
stefankarschti Nov 8, 2023
3a5403d
compile time option to enable or disable triangulated lines (MLN_TRIA…
stefankarschti Nov 9, 2023
68bb5cd
conditional code for triangulated outlines
stefankarschti Nov 9, 2023
c7b850f
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 9, 2023
f6f124f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 9, 2023
0006630
add new shader file to bazel shader file list
stefankarschti Nov 9, 2023
b03770c
Merge branch 'metal-fill-outline' of github.com:stefankarschti/maplib…
stefankarschti Nov 9, 2023
0b1009c
enable by default
stefankarschti Nov 9, 2023
f1f2f41
change test threshold
stefankarschti Nov 9, 2023
1ae292b
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 10, 2023
380b0e4
fix simple line failing render tests
stefankarschti Nov 10, 2023
72187f1
use simple lines for pattern fill outlines in either case.
stefankarschti Nov 10, 2023
dcbc56b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 10, 2023
0324bcd
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 15, 2023
7efc3a6
enable triangulated fill outlines by default
stefankarschti Nov 15, 2023
f9fe5eb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2023
bf6ced7
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 15, 2023
0981a85
Merge branch 'main' into metal-fill-outline
alexcristici Nov 15, 2023
7312ca4
Merge branch 'main' into metal-fill-outline
alexcristici Nov 15, 2023
b3d2a6b
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 16, 2023
8f2df8a
polyline generator refactor
stefankarschti Nov 17, 2023
42e8bd4
use a layer tweaker for triangulated line drawables
stefankarschti Nov 17, 2023
a465b02
fix property source
stefankarschti Nov 17, 2023
9d6a4aa
fixes
stefankarschti Nov 17, 2023
39cf4f9
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 17, 2023
c2a8801
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 17, 2023
51ad59b
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 20, 2023
4f3243b
initial implementation of lineToFillVertexIndex in the fill bucket
stefankarschti Nov 20, 2023
475876c
interim solution for color interpolation
stefankarschti Nov 20, 2023
124229f
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 21, 2023
42048d9
Merge branch 'main' into metal-fill-outline
stefankarschti Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platform/ios/src/MLNMapView+Metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void swap() override {

// Un-comment for synchronous, which can help troubleshoot rendering problems,
// particularly those related to resource tracking and multiple queued buffers.
//[commandBuffer waitUntilCompleted];
[commandBuffer waitUntilCompleted];
stefankarschti marked this conversation as resolved.
Show resolved Hide resolved

commandBuffer = nil;
commandBufferPtr.reset();
Expand Down
83 changes: 83 additions & 0 deletions src/mbgl/renderer/buckets/fill_bucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <mbgl/renderer/layers/render_fill_layer.hpp>
#include <mbgl/util/math.hpp>

#if MLN_DRAWABLE_RENDERER
#include <mbgl/gfx/polyline_generator.hpp>
#endif

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4244)
Expand Down Expand Up @@ -53,6 +57,7 @@ FillBucket::~FillBucket() {
sharedVertices->release();
}

#if MLN_LEGACY_RENDERER
void FillBucket::addFeature(const GeometryTileFeature& feature,
const GeometryCollection& geometry,
const ImagePositions& patternPositions,
Expand Down Expand Up @@ -132,6 +137,84 @@ void FillBucket::addFeature(const GeometryTileFeature& feature,
}
}
}
#endif

#if MLN_DRAWABLE_RENDERER
void FillBucket::addFeature(const GeometryTileFeature& feature,
const GeometryCollection& geometry,
const ImagePositions& patternPositions,
const PatternLayerMap& patternDependencies,
std::size_t index,
const CanonicalTileID& canonical) {
gfx::PolylineGenerator<LineLayoutVertex, Segment<LineAttributes>> generator(
lineVertices,
LineProgram::layoutVertex,
lineSegments,
[](std::size_t vertexOffset, std::size_t indexOffset) -> Segment<LineAttributes> {
return Segment<LineAttributes>(vertexOffset, indexOffset);
},
[](auto& seg) -> Segment<LineAttributes>& { return seg; },
lineIndexes);

gfx::PolylineGeneratorOptions options;
options.type = FeatureType::Polygon;

for (auto& polygon : classifyRings(geometry)) {
// Optimize polygons with many interior rings for earcut tesselation.
limitHoles(polygon, 500);

std::size_t totalVertices = 0;

for (const auto& ring : polygon) {
totalVertices += ring.size();
if (totalVertices > std::numeric_limits<uint16_t>::max()) throw GeometryTooLongException();
}

// generate outline
for (const auto& ring : polygon) {
generator.generate(ring, options);
}

// generate fill
std::size_t startVertices = vertices.elements();
for (const auto& ring : polygon) {
for (auto& p : ring) {
vertices.emplace_back(FillProgram::layoutVertex(p));
}
}
std::vector<uint32_t> indices = mapbox::earcut(polygon);
std::size_t nIndices = indices.size();
assert(nIndices % 3 == 0);

if (triangleSegments.empty() ||
triangleSegments.back().vertexLength + totalVertices > std::numeric_limits<uint16_t>::max()) {
triangleSegments.emplace_back(startVertices, triangles.elements());
}

auto& triangleSegment = triangleSegments.back();
assert(triangleSegment.vertexLength <= std::numeric_limits<uint16_t>::max());
const auto triangleIndex = static_cast<uint16_t>(triangleSegment.vertexLength);

for (std::size_t i = 0; i < nIndices; i += 3) {
triangles.emplace_back(
triangleIndex + indices[i], triangleIndex + indices[i + 1], triangleIndex + indices[i + 2]);
}

triangleSegment.vertexLength += totalVertices;
triangleSegment.indexLength += nIndices;
}

for (auto& pair : paintPropertyBinders) {
const auto it = patternDependencies.find(pair.first);
if (it != patternDependencies.end()) {
pair.second.populateVertexVectors(
feature, vertices.elements(), index, patternPositions, it->second, canonical);
} else {
pair.second.populateVertexVectors(feature, vertices.elements(), index, patternPositions, {}, canonical);
}
}
}
#endif

void FillBucket::upload([[maybe_unused]] gfx::UploadPass& uploadPass) {
#if MLN_LEGACY_RENDERER
Expand Down
27 changes: 22 additions & 5 deletions src/mbgl/renderer/buckets/fill_bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <mbgl/programs/fill_program.hpp>
#include <mbgl/style/layers/fill_layer_properties.hpp>

#if MLN_DRAWABLE_RENDERER
#include <mbgl/programs/line_program.hpp>
#endif

#include <vector>

namespace mbgl {
Expand Down Expand Up @@ -40,22 +44,35 @@ class FillBucket final : public Bucket {

void update(const FeatureStates&, const GeometryTileLayer&, const std::string&, const ImagePositions&) override;

#if MLN_DRAWABLE_RENDERER
using LineVertexVector = gfx::VertexVector<LineLayoutVertex>;
const std::shared_ptr<LineVertexVector> sharedLineVertices = std::make_shared<LineVertexVector>();
LineVertexVector& lineVertices = *sharedLineVertices;

using LineIndexVector = gfx::IndexVector<gfx::Triangles>;
const std::shared_ptr<LineIndexVector> sharedLineIndexes = std::make_shared<LineIndexVector>();
LineIndexVector& lineIndexes = *sharedLineIndexes;

SegmentVector<LineAttributes> lineSegments;
#endif

using VertexVector = gfx::VertexVector<FillLayoutVertex>;
const std::shared_ptr<VertexVector> sharedVertices = std::make_shared<VertexVector>();
VertexVector& vertices = *sharedVertices;

using LineIndexVector = gfx::IndexVector<gfx::Lines>;
const std::shared_ptr<LineIndexVector> sharedLines = std::make_shared<LineIndexVector>();
LineIndexVector& lines = *sharedLines;

using TriangleIndexVector = gfx::IndexVector<gfx::Triangles>;
const std::shared_ptr<TriangleIndexVector> sharedTriangles = std::make_shared<TriangleIndexVector>();
TriangleIndexVector& triangles = *sharedTriangles;

SegmentVector<FillAttributes> lineSegments;
SegmentVector<FillAttributes> triangleSegments;

#if MLN_LEGACY_RENDERER
using LineIndexVector = gfx::IndexVector<gfx::Lines>;
const std::shared_ptr<LineIndexVector> sharedLines = std::make_shared<LineIndexVector>();
LineIndexVector& lines = *sharedLines;

SegmentVector<FillAttributes> lineSegments;

std::optional<gfx::VertexBuffer<FillLayoutVertex>> vertexBuffer;
std::optional<gfx::IndexBuffer> lineIndexBuffer;
std::optional<gfx::IndexBuffer> triangleIndexBuffer;
Expand Down
Loading
Loading