Share bucket indices (#1358)
Co-authored-by: Stefan Karschti <stefan.karschti@gmail.com>
This commit is contained in:
committed by
Bart Louwers
parent
996b388601
commit
7f862cd8ff
@@ -299,6 +299,12 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
std::vector<SegmentBase>& segments) {
|
||||
constexpr const uint16_t vertexLength = 4;
|
||||
|
||||
if (vertices.empty()) {
|
||||
vertices.reserve(mask.size() * vertexLength);
|
||||
attributes.reserve(mask.size() * vertexLength);
|
||||
indices.reserve(mask.size() * 6);
|
||||
segments.reserve(mask.size());
|
||||
}
|
||||
// Create the vertex buffer for the specified tile mask.
|
||||
for (const auto& id : mask) {
|
||||
// Create a quad for every masked tile.
|
||||
@@ -334,11 +340,12 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
// 0, 1, 2
|
||||
// 1, 2, 3
|
||||
indices.insert(indices.end(),
|
||||
{offset, static_cast<uint16_t>(offset + 1), static_cast<uint16_t>(offset + 2u)});
|
||||
indices.insert(indices.end(),
|
||||
{static_cast<uint16_t>(offset + 1),
|
||||
static_cast<uint16_t>(offset + 2),
|
||||
static_cast<uint16_t>(offset + 3)});
|
||||
{offset,
|
||||
static_cast<uint16_t>(offset + 1u),
|
||||
static_cast<uint16_t>(offset + 2u),
|
||||
static_cast<uint16_t>(offset + 1u),
|
||||
static_cast<uint16_t>(offset + 2u),
|
||||
static_cast<uint16_t>(offset + 3u)});
|
||||
|
||||
segment.vertexLength += vertexLength;
|
||||
segment.indexLength += 6;
|
||||
@@ -350,14 +357,15 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
std::vector<SegmentBase> segments;
|
||||
buildRenderData(bucket.mask, vertices, attributes, indices, segments);
|
||||
builder->addVertices(vertices, 0, vertices.size());
|
||||
builder->setSegments(gfx::Triangles(), indices, segments);
|
||||
builder->setSegments(gfx::Triangles(), indices, segments.data(), segments.size());
|
||||
|
||||
// attributes
|
||||
{
|
||||
gfx::VertexAttributeArray vertexAttrs;
|
||||
if (auto& attr = vertexAttrs.getOrAdd("a_texture_pos")) {
|
||||
if (const auto& attr = vertexAttrs.getOrAdd("a_texture_pos")) {
|
||||
attr->reserve(attributes.size());
|
||||
std::size_t index{0};
|
||||
for (auto& a : attributes) {
|
||||
for (const auto& a : attributes) {
|
||||
attr->set<gfx::VertexAttribute::int2>(index++, {a[0], a[1]});
|
||||
}
|
||||
}
|
||||
@@ -369,18 +377,18 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
};
|
||||
|
||||
auto buildImageDrawables = [&setTextures](std::unique_ptr<gfx::DrawableBuilder>& builder, RasterBucket& bucket) {
|
||||
std::vector<std::array<int16_t, 2>> vertices(bucket.vertices.vector().size());
|
||||
std::transform(
|
||||
bucket.vertices.vector().begin(), bucket.vertices.vector().end(), vertices.begin(), [](const auto& x) {
|
||||
return x.a1;
|
||||
});
|
||||
builder->addVertices(vertices, 0, vertices.size());
|
||||
|
||||
builder->setSegments(gfx::Triangles(), bucket.indices.vector(), bucket.segments.data(), bucket.segments.size());
|
||||
|
||||
// attributes
|
||||
{
|
||||
gfx::VertexAttributeArray vertexAttrs;
|
||||
|
||||
if (auto& attr = vertexAttrs.add("a_pos")) {
|
||||
attr->setSharedRawData(bucket.sharedVertices,
|
||||
offsetof(RasterLayoutVertex, a1),
|
||||
/*vertexOffset=*/0,
|
||||
sizeof(RasterLayoutVertex),
|
||||
gfx::AttributeDataType::Short2);
|
||||
}
|
||||
|
||||
if (auto& attr = vertexAttrs.getOrAdd("a_texture_pos")) {
|
||||
std::size_t index{0};
|
||||
for (auto& v : bucket.vertices.vector()) {
|
||||
@@ -390,6 +398,9 @@ void RenderRasterLayer::update(gfx::ShaderRegistry& shaders,
|
||||
builder->setVertexAttributes(std::move(vertexAttrs));
|
||||
}
|
||||
|
||||
builder->setRawVertices({}, bucket.vertices.elements(), gfx::AttributeDataType::Short2);
|
||||
builder->setSegments(gfx::Triangles(), bucket.sharedTriangles, bucket.segments.data(), bucket.segments.size());
|
||||
|
||||
// textures
|
||||
setTextures(builder, bucket);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user