Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6e31241

Browse files
author
jonahwilliams
committed
++
1 parent de95aa0 commit 6e31241

File tree

1 file changed

+30
-55
lines changed

1 file changed

+30
-55
lines changed

impeller/entity/geometry/point_field_geometry.cc

Lines changed: 30 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
3232
Scalar radius = std::max(radius_, min_size);
3333

3434
HostBuffer& host_buffer = renderer.GetTransientsBuffer();
35+
VertexBufferBuilder<SolidFillVertexShader::PerVertexData> vtx_builder;
36+
3537
if (round_) {
3638
// Get triangulation relative to {0, 0} so we can translate it to each
3739
// point in turn.
@@ -45,65 +47,38 @@ GeometryResult PointFieldGeometry::GetPositionBuffer(
4547
});
4648
FML_DCHECK(circle_vertices.size() == generator.GetVertexCount());
4749

48-
size_t vertex_count = ((circle_vertices.size() + 2) * points_.size() - 2);
49-
BufferView vertex_data =
50-
host_buffer.Emplace(vertex_count, alignof(Point), [&](uint8_t* data) {
51-
Point* output = reinterpret_cast<Point*>(data);
52-
size_t offset = 0;
53-
54-
for (auto& vertex : circle_vertices) {
55-
output[offset++] = vertex + points_[0];
56-
}
57-
58-
for (auto i = 1u; i < vertex_count; i++) {
59-
output[offset++] = output[offset];
60-
output[offset++] = circle_vertices[0] + points_[i];
61-
for (auto& vertex : circle_vertices) {
62-
output[offset++] = vertex + points_[i];
63-
}
64-
}
65-
});
66-
67-
return GeometryResult{
68-
.type = PrimitiveType::kTriangleStrip,
69-
.vertex_buffer = VertexBuffer{.vertex_buffer = std::move(vertex_data),
70-
.index_buffer = {},
71-
.vertex_count = vertex_count,
72-
.index_type = IndexType::kNone},
73-
.transform = entity.GetShaderTransform(pass),
74-
};
75-
}
50+
vtx_builder.Reserve((circle_vertices.size() + 2) * points_.size() - 2);
51+
for (auto& center : points_) {
52+
if (vtx_builder.HasVertices()) {
53+
vtx_builder.AppendVertex(vtx_builder.Last());
54+
vtx_builder.AppendVertex({center + circle_vertices[0]});
55+
}
7656

77-
size_t vertex_count = 6 * points_.size() - 2;
78-
BufferView vertex_data =
79-
host_buffer.Emplace(vertex_count, alignof(Point), [&](uint8_t* data) {
80-
Point* output = reinterpret_cast<Point*>(data);
81-
size_t offset = 0;
82-
bool has_vertices = false;
83-
84-
for (auto& point : points_) {
85-
Point first = Point(point.x - radius, point.y - radius);
86-
87-
if (has_vertices) {
88-
output[offset++] = output[offset];
89-
output[offset++] = first;
90-
}
91-
92-
// Z pattern from UL -> UR -> LL -> LR
93-
output[offset++] = first;
94-
output[offset++] = Point{point.x + radius, point.y - radius};
95-
output[offset++] = Point{point.x - radius, point.y + radius};
96-
output[offset++] = Point{point.x + radius, point.y + radius};
97-
has_vertices = true;
98-
}
99-
});
57+
for (auto& vertex : circle_vertices) {
58+
vtx_builder.AppendVertex({center + vertex});
59+
}
60+
}
61+
} else {
62+
vtx_builder.Reserve(6 * points_.size() - 2);
63+
for (auto& point : points_) {
64+
auto first = Point(point.x - radius, point.y - radius);
65+
66+
if (vtx_builder.HasVertices()) {
67+
vtx_builder.AppendVertex(vtx_builder.Last());
68+
vtx_builder.AppendVertex({first});
69+
}
70+
71+
// Z pattern from UL -> UR -> LL -> LR
72+
vtx_builder.AppendVertex({first});
73+
vtx_builder.AppendVertex({{point.x + radius, point.y - radius}});
74+
vtx_builder.AppendVertex({{point.x - radius, point.y + radius}});
75+
vtx_builder.AppendVertex({{point.x + radius, point.y + radius}});
76+
}
77+
}
10078

10179
return GeometryResult{
10280
.type = PrimitiveType::kTriangleStrip,
103-
.vertex_buffer = VertexBuffer{.vertex_buffer = std::move(vertex_data),
104-
.index_buffer = {},
105-
.vertex_count = vertex_count,
106-
.index_type = IndexType::kNone},
81+
.vertex_buffer = vtx_builder.CreateVertexBuffer(host_buffer),
10782
.transform = entity.GetShaderTransform(pass),
10883
};
10984
}

0 commit comments

Comments
 (0)