Drawable Renderer (#1570), [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2023-07-07 22:04:06 +00:00
committed by Bart Louwers
parent 5b3af77450
commit d3b993ad3d
14 changed files with 149 additions and 100 deletions

View File

@@ -52,8 +52,7 @@ public:
sharedType(other.sharedType),
sharedOffset(other.sharedOffset),
sharedVertexOffset(other.sharedVertexOffset),
sharedStride(other.sharedStride)
{}
sharedStride(other.sharedStride) {}
VertexAttribute(VertexAttribute&& other)
: index(other.index),
dataType(other.dataType),
@@ -62,8 +61,7 @@ public:
sharedType(other.sharedType),
sharedOffset(other.sharedOffset),
sharedVertexOffset(other.sharedVertexOffset),
sharedStride(other.sharedStride)
{}
sharedStride(other.sharedStride) {}
public:
virtual ~VertexAttribute() = default;
@@ -138,7 +136,11 @@ public:
uint32_t getSharedOffset() const { return sharedOffset; }
uint32_t getSharedVertexOffset() const { return sharedVertexOffset; }
uint32_t getSharedStride() const { return sharedStride; }
void setSharedRawData(std::shared_ptr<VertexVectorBase> data, uint32_t offset, uint32_t vertexOffset, uint32_t stride_, AttributeDataType type) {
void setSharedRawData(std::shared_ptr<VertexVectorBase> data,
uint32_t offset,
uint32_t vertexOffset,
uint32_t stride_,
AttributeDataType type) {
sharedRawData = std::move(data);
sharedType = type;
sharedOffset = offset;

View File

@@ -38,8 +38,7 @@ UniqueDrawable& DrawableBuilder::getCurrentDrawable(bool createIfNone) {
}
void DrawableBuilder::flush() {
if (curVertexCount())
{
if (curVertexCount()) {
const auto& draw = getCurrentDrawable(/*createIfNone=*/true);
draw->setEnabled(enabled);
draw->setLineWidth(static_cast<int32_t>(lineWidth));

View File

@@ -13,7 +13,6 @@ std::size_t VertexAttribute::getCount() const {
return sharedRawData ? sharedRawData->getRawCount() : items.size();
}
std::unique_ptr<VertexAttribute> VertexAttributeArray::nullref = nullptr;
VertexAttributeArray::VertexAttributeArray(int initCapacity)

View File

@@ -14,12 +14,11 @@ struct VertexBufferBase {
class VertexVectorBase {
public:
VertexVectorBase() = default;
VertexVectorBase(const VertexVectorBase&) {} // buffer is not copied
VertexVectorBase(VertexVectorBase&& other) :
buffer(std::move(other.buffer)),
dirty(other.dirty),
released(other.released)
{}
VertexVectorBase(const VertexVectorBase&) {} // buffer is not copied
VertexVectorBase(VertexVectorBase&& other)
: buffer(std::move(other.buffer)),
dirty(other.dirty),
released(other.released) {}
virtual ~VertexVectorBase() = default;
virtual const void* getRawData() const = 0;
@@ -47,12 +46,12 @@ public:
using Vertex = V;
VertexVector() = default;
VertexVector(const VertexVector<V>& other) :
VertexVectorBase(other),
v(other.v) {}
VertexVector(VertexVector<V>&& other) :
VertexVectorBase(std::move(other)),
v(std::move(other.v)) {}
VertexVector(const VertexVector<V>& other)
: VertexVectorBase(other),
v(other.v) {}
VertexVector(VertexVector<V>&& other)
: VertexVectorBase(std::move(other)),
v(std::move(other.v)) {}
~VertexVector() override = default;
template <typename Arg>

View File

@@ -139,15 +139,16 @@ struct VertexBufferGL : public gfx::VertexBufferBase {
namespace {
const std::unique_ptr<gfx::VertexBufferResource> noBuffer;
}
const gfx::UniqueVertexBufferResource& UploadPass::getBuffer(const gfx::VertexVectorBasePtr& vec, const gfx::BufferUsageType usage) {
const gfx::UniqueVertexBufferResource& UploadPass::getBuffer(const gfx::VertexVectorBasePtr& vec,
const gfx::BufferUsageType usage) {
if (vec) {
const auto* rawBufPtr = vec->getRawData();
const auto rawBufSize = static_cast<int>(vec->getRawCount() * vec->getRawSize());
// If we already have a buffer...
if (auto* rawData = static_cast<VertexBufferGL*>(vec->getBuffer()); rawData && rawData->resource) {
auto& resource = static_cast<gl::VertexBufferResource&>(*rawData->resource);
// If it's changed, update it
if (rawBufSize <= resource.byteSize) {
if (vec->getDirty()) {
@@ -282,7 +283,7 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
b->vertexBufferResource = vertBuf.get();
}
});
outBuffers.emplace_back(std::move(vertBuf));
} else {
assert(false);
@@ -290,8 +291,8 @@ gfx::AttributeBindingArray UploadPass::buildAttributeBindings(
}
}
assert(std::all_of(bindings.begin(), bindings.end(), [](const auto& b){ return !b || b->vertexBufferResource; }));
assert(std::all_of(bindings.begin(), bindings.end(), [](const auto& b) { return !b || b->vertexBufferResource; }));
return bindings;
}
#endif

View File

@@ -113,11 +113,15 @@ bool VertexAttributeGL::get(const gfx::VertexAttribute::ElementType& element, GL
return gl::get<float3>(element, buffer);
case GL_FLOAT_VEC4:
case GL_FLOAT_MAT2:
return gl::get<float4>(element, buffer) || gl::get<int4, float4>(element, buffer, [](int4 x) {
return gl::get<float4>(element, buffer) ||
gl::get<int4, float4>(element,
buffer,
[](int4 x) {
return float4{(float)x[0], (float)x[1], (float)x[2], (float)x[3]};
}) ||
gl::get<ushort8, float4>(element, buffer, [](ushort8 x) {
return float4{(float)x[0], (float)x[1], (float)x[2], (float)x[3]};
}) || gl::get<ushort8, float4>(element, buffer, [](ushort8 x) {
return float4{(float)x[0], (float)x[1], (float)x[2], (float)x[3]};
});
});
case GL_INT:
return gl::get<std::int32_t>(element, buffer) || gl::get<float, std::int32_t>(element, buffer);
case GL_UNSIGNED_INT:

View File

@@ -265,7 +265,6 @@ bool RenderCircleLayer::queryIntersectsFeature(const GeometryCoordinates& queryG
#if MLN_DRAWABLE_RENDERER
namespace {
struct alignas(16) CircleInterpolateUBO {
float color_t;
float radius_t;
@@ -363,12 +362,12 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
gfx::VertexAttributeArray circleVertexAttrs;
const auto propertiesAsUniforms = circleVertexAttrs.readDataDrivenPaintProperties<CircleColor,
CircleRadius,
CircleBlur,
CircleOpacity,
CircleStrokeColor,
CircleStrokeWidth,
CircleStrokeOpacity>(
CircleRadius,
CircleBlur,
CircleOpacity,
CircleStrokeColor,
CircleStrokeWidth,
CircleStrokeOpacity>(
paintPropertyBinders, evaluated);
const auto circleShader = circleShaderGroup->getOrCreateShader(context, propertiesAsUniforms);
@@ -377,7 +376,11 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
}
if (const auto& attr = circleVertexAttrs.add(VertexAttribName)) {
attr->setSharedRawData(bucket.sharedVertices, offsetof(CircleLayoutVertex, a1), 0, sizeof(CircleLayoutVertex), gfx::AttributeDataType::Short2);
attr->setSharedRawData(bucket.sharedVertices,
offsetof(CircleLayoutVertex, a1),
0,
sizeof(CircleLayoutVertex),
gfx::AttributeDataType::Short2);
}
circleBuilder = context.createDrawableBuilder("circle");
@@ -388,7 +391,7 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
circleBuilder->setRenderPass(renderPass);
circleBuilder->setVertexAttributes(std::move(circleVertexAttrs));
circleBuilder->setRawVertices({}, vertexCount, gfx::AttributeDataType::Short2);
circleBuilder->setSegments(
gfx::Triangles(), bucket.triangles.vector(), bucket.segments.data(), bucket.segments.size());

View File

@@ -450,10 +450,18 @@ void RenderFillExtrusionLayer::update(gfx::ShaderRegistry& shaders,
}
if (const auto& attr = vertexAttrs.getOrAdd(PosAttribName)) {
attr->setSharedRawData(bucket.sharedVertices, offsetof(FillExtrusionLayoutVertex, a1), 0, sizeof(FillExtrusionLayoutVertex), gfx::AttributeDataType::Short2);
attr->setSharedRawData(bucket.sharedVertices,
offsetof(FillExtrusionLayoutVertex, a1),
0,
sizeof(FillExtrusionLayoutVertex),
gfx::AttributeDataType::Short2);
}
if (const auto& attr = vertexAttrs.getOrAdd(NormAttribName)) {
attr->setSharedRawData(bucket.sharedVertices, offsetof(FillExtrusionLayoutVertex, a2), 0, sizeof(FillExtrusionLayoutVertex), gfx::AttributeDataType::Short4);
attr->setSharedRawData(bucket.sharedVertices,
offsetof(FillExtrusionLayoutVertex, a2),
0,
sizeof(FillExtrusionLayoutVertex),
gfx::AttributeDataType::Short4);
}
colorBuilder->setEnableStencil(doDepthPass);

View File

@@ -421,12 +421,16 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
// `Fill*Program` all use `style::FillPaintProperties`
gfx::VertexAttributeArray vertexAttrs;
const auto uniformProps =
vertexAttrs.readDataDrivenPaintProperties<FillColor, FillOpacity, FillOutlineColor, FillPattern>(
binders, evaluated);
vertexAttrs.readDataDrivenPaintProperties<FillColor, FillOpacity, FillOutlineColor, FillPattern>(binders,
evaluated);
const auto vertexCount = bucket.vertices.elements();
if (const auto& attr = vertexAttrs.add(PosAttribName)) {
attr->setSharedRawData(bucket.sharedVertices, offsetof(FillLayoutVertex, a1), 0, sizeof(FillLayoutVertex), gfx::AttributeDataType::Short2);
attr->setSharedRawData(bucket.sharedVertices,
offsetof(FillLayoutVertex, a1),
0,
sizeof(FillLayoutVertex),
gfx::AttributeDataType::Short2);
}
if (unevaluated.get<FillPattern>().isUndefined()) {
@@ -436,10 +440,9 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
const auto fillShader = std::static_pointer_cast<gfx::ShaderProgramBase>(
fillShaderGroup->getOrCreateShader(context, uniformProps));
const auto outlineShader = doOutline
? std::static_pointer_cast<gfx::ShaderProgramBase>(
outlineShaderGroup->getOrCreateShader(context, uniformProps))
: nullptr;
const auto outlineShader = doOutline ? std::static_pointer_cast<gfx::ShaderProgramBase>(
outlineShaderGroup->getOrCreateShader(context, uniformProps))
: nullptr;
if (!fillBuilder && fillShader) {
if (auto builder = context.createDrawableBuilder(layerPrefix + "fill")) {
@@ -497,10 +500,10 @@ void RenderFillLayer::update(gfx::ShaderRegistry& shaders,
const auto fillShader = std::static_pointer_cast<gfx::ShaderProgramBase>(
patternShaderGroup->getOrCreateShader(context, uniformProps));
const auto outlineShader = doOutline ? std::static_pointer_cast<gfx::ShaderProgramBase>(
outlinePatternShaderGroup->getOrCreateShader(
context, uniformProps))
: nullptr;
const auto outlineShader = doOutline
? std::static_pointer_cast<gfx::ShaderProgramBase>(
outlinePatternShaderGroup->getOrCreateShader(context, uniformProps))
: nullptr;
if (!patternBuilder) {
if (auto builder = context.createDrawableBuilder(layerPrefix + "fill-pattern")) {

View File

@@ -281,7 +281,7 @@ constexpr auto HeatmapTextureShaderGroupName = "HeatmapTextureShader";
constexpr auto HeatmapInterpolateUBOName = "HeatmapInterpolateUBO";
constexpr auto VertexAttribName = "a_pos";
}
} // namespace
void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
gfx::Context& context,
@@ -371,8 +371,9 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
gfx::VertexAttributeArray heatmapVertexAttrs;
const auto propertiesAsUniforms = heatmapVertexAttrs.readDataDrivenPaintProperties<HeatmapWeight, HeatmapRadius>(
paintPropertyBinders, evaluated);
const auto propertiesAsUniforms =
heatmapVertexAttrs.readDataDrivenPaintProperties<HeatmapWeight, HeatmapRadius>(paintPropertyBinders,
evaluated);
const auto heatmapShader = heatmapShaderGroup->getOrCreateShader(context, propertiesAsUniforms);
if (!heatmapShader) {
@@ -380,7 +381,11 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
}
if (const auto& attr = heatmapVertexAttrs.add(VertexAttribName)) {
attr->setSharedRawData(bucket.sharedVertices, offsetof(HeatmapLayoutVertex, a1), 0, sizeof(HeatmapLayoutVertex), gfx::AttributeDataType::Short2);
attr->setSharedRawData(bucket.sharedVertices,
offsetof(HeatmapLayoutVertex, a1),
0,
sizeof(HeatmapLayoutVertex),
gfx::AttributeDataType::Short2);
}
heatmapBuilder = context.createDrawableBuilder("heatmap");
@@ -436,7 +441,11 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
gfx::VertexAttributeArray textureVertexAttrs;
if (const auto& attr = textureVertexAttrs.add(VertexAttribName)) {
attr->setSharedRawData(sharedTextureVertices, offsetof(HeatmapLayoutVertex, a1), 0, sizeof(HeatmapLayoutVertex), gfx::AttributeDataType::Short2);
attr->setSharedRawData(sharedTextureVertices,
offsetof(HeatmapLayoutVertex, a1),
0,
sizeof(HeatmapLayoutVertex),
gfx::AttributeDataType::Short2);
}
heatmapTextureBuilder = context.createDrawableBuilder("heatmapTexture");

View File

@@ -73,7 +73,7 @@ private:
gfx::ShaderGroupPtr heatmapShaderGroup;
gfx::ShaderProgramBasePtr heatmapTextureShader;
RenderTargetPtr renderTarget;
using TextureVertexVector = gfx::VertexVector<HeatmapTextureLayoutVertex>;
std::shared_ptr<TextureVertexVector> sharedTextureVertices;
#endif

View File

@@ -104,7 +104,7 @@ void RenderLineLayer::prepare(const LayerPrepareParameters& params) {
params.lineAtlas.getDashPatternTexture(
evaluated.get<LineDasharray>().from, evaluated.get<LineDasharray>().to, cap);
}
#if MLN_DRAWABLE_RENDERER
updateRenderTileIDs();
#endif // MLN_DRAWABLE_RENDERER
@@ -477,23 +477,29 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
return builder;
};
auto addAttributes = [&](gfx::DrawableBuilder& builder,
const LineBucket& bucket,
gfx::VertexAttributeArray&& vertexAttrs) {
auto addAttributes =
[&](gfx::DrawableBuilder& builder, const LineBucket& bucket, gfx::VertexAttributeArray&& vertexAttrs) {
const auto vertexCount = bucket.vertices.elements();
builder.setRawVertices({}, vertexCount, gfx::AttributeDataType::Short4);
const auto vertexCount = bucket.vertices.elements();
builder.setRawVertices({}, vertexCount, gfx::AttributeDataType::Short4);
if (const auto& attr = vertexAttrs.add(VertexAttribName)) {
attr->setSharedRawData(bucket.sharedVertices,
offsetof(LineLayoutVertex, a1),
0,
sizeof(LineLayoutVertex),
gfx::AttributeDataType::Short2);
}
if (const auto& attr = vertexAttrs.add(VertexAttribName)) {
attr->setSharedRawData(bucket.sharedVertices, offsetof(LineLayoutVertex, a1), 0, sizeof(LineLayoutVertex), gfx::AttributeDataType::Short2);
}
if (const auto& attr = vertexAttrs.add(DataAttribName)) {
attr->setSharedRawData(bucket.sharedVertices,
offsetof(LineLayoutVertex, a2),
0,
sizeof(LineLayoutVertex),
gfx::AttributeDataType::UByte4);
}
if (const auto& attr = vertexAttrs.add(DataAttribName)) {
attr->setSharedRawData(bucket.sharedVertices, offsetof(LineLayoutVertex, a2), 0, sizeof(LineLayoutVertex), gfx::AttributeDataType::UByte4);
}
builder.setVertexAttributes(std::move(vertexAttrs));
};
builder.setVertexAttributes(std::move(vertexAttrs));
};
auto setSegments = [&](std::unique_ptr<gfx::DrawableBuilder>& builder, const LineBucket& bucket) {
builder->setSegments(
@@ -594,13 +600,13 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
// dash array line (SDF)
gfx::VertexAttributeArray vertexAttrs;
const auto propertiesAsUniforms = vertexAttrs.readDataDrivenPaintProperties<LineColor,
LineBlur,
LineOpacity,
LineGapWidth,
LineOffset,
LineWidth,
LineFloorWidth>(paintPropertyBinders,
evaluated);
LineBlur,
LineOpacity,
LineGapWidth,
LineOffset,
LineWidth,
LineFloorWidth>(
paintPropertyBinders, evaluated);
auto builder = createLineBuilder("lineSDF",
lineSDFShaderGroup->getOrCreateShader(context, propertiesAsUniforms));
@@ -707,12 +713,12 @@ void RenderLineLayer::update(gfx::ShaderRegistry& shaders,
// simple line
gfx::VertexAttributeArray vertexAttrs;
const auto propertiesAsUniforms = vertexAttrs.readDataDrivenPaintProperties<LineColor,
LineBlur,
LineOpacity,
LineGapWidth,
LineOffset,
LineWidth>(paintPropertyBinders,
evaluated);
LineBlur,
LineOpacity,
LineGapWidth,
LineOffset,
LineWidth>(paintPropertyBinders,
evaluated);
auto builder = createLineBuilder("line", lineShaderGroup->getOrCreateShader(context, propertiesAsUniforms));
// vertices, attributes and segments

View File

@@ -756,21 +756,21 @@ void updateTileDrawable(gfx::Drawable& drawable,
if (!drawable.getData()) {
return;
}
auto& drawData = static_cast<gfx::SymbolDrawableData&>(*drawable.getData());
const auto isText = (drawData.symbolType == SymbolType::Text);
const auto currentZoom = static_cast<float>(state.getZoom());
// This property can be set after the initial appearance of the tile, as part of the layout process.
drawData.bucketVariablePlacement = bucket.hasVariablePlacement;
const auto tileUBO = buildTileUBO(bucket, drawData, currentZoom);
const auto interpolateUBO = buildInterpUBO(paintProps, isText, currentZoom);
auto& uniforms = drawable.mutableUniformBuffers();
uniforms.createOrUpdate(SymbolLayerTweaker::SymbolDrawableTilePropsUBOName, &tileUBO, context);
uniforms.createOrUpdate(SymbolLayerTweaker::SymbolDrawableInterpolateUBOName, &interpolateUBO, context);
// TODO: detect whether anything has actually changed
// See `Placement::updateBucketDynamicVertices`
const auto sdfIcons = (drawData.symbolType == SymbolType::IconSDF);
@@ -779,11 +779,13 @@ void updateTileDrawable(gfx::Drawable& drawable,
auto& attribs = drawable.mutableVertexAttributes();
if (const auto& attr = attribs.get(projPosAttribName)) {
using Vertex = gfx::Vertex<SymbolDynamicLayoutAttributes>;
attr->setSharedRawData(buffer.sharedDynamicVertices, offsetof(Vertex, a1), 0, sizeof(Vertex), gfx::AttributeDataType::Float3);
attr->setSharedRawData(
buffer.sharedDynamicVertices, offsetof(Vertex, a1), 0, sizeof(Vertex), gfx::AttributeDataType::Float3);
}
if (const auto& attr = attribs.get(fadeOpacityAttribName)) {
using Vertex = gfx::Vertex<SymbolOpacityAttributes>;
attr->setSharedRawData(buffer.sharedOpacityVertices, offsetof(Vertex, a1), 0, sizeof(Vertex), gfx::AttributeDataType::Float);
attr->setSharedRawData(
buffer.sharedOpacityVertices, offsetof(Vertex, a1), 0, sizeof(Vertex), gfx::AttributeDataType::Float);
}
}
@@ -917,25 +919,38 @@ void RenderSymbolLayer::update(gfx::ShaderRegistry& shaders,
auto& tileInfo = tileCache[tile.id];
gfx::VertexAttributeArray attrs;
const auto vertexCount = buffer.vertices().elements();
if (const auto& attr = attrs.add(posOffsetAttribName)) {
attr->setSharedRawData(buffer.sharedVertices, offsetof(SymbolLayoutVertex, a1), 0, sizeof(SymbolLayoutVertex), gfx::AttributeDataType::Short4);
attr->setSharedRawData(buffer.sharedVertices,
offsetof(SymbolLayoutVertex, a1),
0,
sizeof(SymbolLayoutVertex),
gfx::AttributeDataType::Short4);
}
if (const auto& attr = attrs.add(dataAttibName)) {
attr->setSharedRawData(buffer.sharedVertices, offsetof(SymbolLayoutVertex, a2), 0, sizeof(SymbolLayoutVertex), gfx::AttributeDataType::UShort4);
attr->setSharedRawData(buffer.sharedVertices,
offsetof(SymbolLayoutVertex, a2),
0,
sizeof(SymbolLayoutVertex),
gfx::AttributeDataType::UShort4);
}
if (const auto& attr = attrs.add(pixOffsetAttribName)) {
attr->setSharedRawData(buffer.sharedVertices, offsetof(SymbolLayoutVertex, a3), 0, sizeof(SymbolLayoutVertex), gfx::AttributeDataType::Short4);
attr->setSharedRawData(buffer.sharedVertices,
offsetof(SymbolLayoutVertex, a3),
0,
sizeof(SymbolLayoutVertex),
gfx::AttributeDataType::Short4);
}
if (const auto& attr = attrs.add(projPosAttribName)) {
using Vertex = gfx::Vertex<SymbolDynamicLayoutAttributes>;
attr->setSharedRawData(buffer.sharedDynamicVertices, offsetof(Vertex, a1), 0, sizeof(Vertex), gfx::AttributeDataType::Float3);
attr->setSharedRawData(
buffer.sharedDynamicVertices, offsetof(Vertex, a1), 0, sizeof(Vertex), gfx::AttributeDataType::Float3);
}
if (const auto& attr = attrs.add(fadeOpacityAttribName)) {
using Vertex = gfx::Vertex<SymbolOpacityAttributes>;
attr->setSharedRawData(buffer.sharedOpacityVertices, offsetof(Vertex, a1), 0, sizeof(Vertex), gfx::AttributeDataType::Float);
attr->setSharedRawData(
buffer.sharedOpacityVertices, offsetof(Vertex, a1), 0, sizeof(Vertex), gfx::AttributeDataType::Float);
}
const auto uniformProps = isText ? attrs.readDataDrivenPaintProperties<TextOpacity,

View File

@@ -907,7 +907,8 @@ bool Placement::updateBucketDynamicVertices(SymbolBucket& bucket,
hideGlyphs(placedIcon.glyphOffsets.size(), iconBuffer.dynamicVertices());
} else {
for (std::size_t j = 0; j < placedIcon.glyphOffsets.size(); ++j) {
addDynamicAttributes(pair->second.second, placedIcon.angle, iconBuffer.dynamicVertices());
addDynamicAttributes(
pair->second.second, placedIcon.angle, iconBuffer.dynamicVertices());
}
}
}