Shared attributes (#1898)
This commit is contained in:
@@ -72,7 +72,6 @@ void RenderHeatmapLayer::evaluate(const PropertyEvaluationParameters& parameters
|
||||
if (auto tileLayerGroup = renderTarget->getLayerGroup(0)) {
|
||||
auto newTweaker = std::make_shared<HeatmapLayerTweaker>(getID(), evaluatedProperties);
|
||||
|
||||
// propertiesAsUniforms isn't recalculated every update, so carry it over
|
||||
if (layerTweaker) {
|
||||
newTweaker->setPropertiesAsUniforms(layerTweaker->getPropertiesAsUniforms());
|
||||
}
|
||||
@@ -352,7 +351,12 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
|
||||
[&](gfx::Drawable& drawable) { return drawable.getTileID() && !hasRenderTile(*drawable.getTileID()); });
|
||||
|
||||
const auto& evaluated = static_cast<const HeatmapLayerProperties&>(*evaluatedProperties).evaluated;
|
||||
mbgl::unordered_set<StringIdentity> propertiesAsUniforms;
|
||||
std::optional<mbgl::unordered_set<StringIdentity>> propertiesAsUniforms;
|
||||
#if !defined(NDEBUG)
|
||||
std::optional<mbgl::unordered_set<StringIdentity>> previousPropertiesAsUniforms;
|
||||
#endif
|
||||
|
||||
gfx::ShaderPtr heatmapShader;
|
||||
|
||||
for (const RenderTile& tile : *renderTiles) {
|
||||
const auto& tileID = tile.getOverscaledTileID();
|
||||
@@ -388,15 +392,6 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
|
||||
return interpolateBuffer;
|
||||
};
|
||||
|
||||
gfx::VertexAttributeArray heatmapVertexAttrs;
|
||||
propertiesAsUniforms.clear();
|
||||
heatmapVertexAttrs.readDataDrivenPaintProperties<HeatmapWeight, HeatmapRadius>(
|
||||
paintPropertyBinders, evaluated, propertiesAsUniforms);
|
||||
|
||||
if (layerTweaker) {
|
||||
layerTweaker->setPropertiesAsUniforms(propertiesAsUniforms);
|
||||
}
|
||||
|
||||
const auto updatedCount = tileLayerGroup->visitDrawables(renderPass, tileID, [&](gfx::Drawable& drawable) {
|
||||
if (drawable.getLayerTweaker() != layerTweaker) {
|
||||
// This drawable was produced on a previous style/bucket, and should not be updated.
|
||||
@@ -417,12 +412,36 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto heatmapShader = heatmapShaderGroup->getOrCreateShader(context, propertiesAsUniforms);
|
||||
if (!propertiesAsUniforms) {
|
||||
propertiesAsUniforms.emplace();
|
||||
}
|
||||
#if !defined(NDEBUG)
|
||||
else {
|
||||
propertiesAsUniforms->clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
auto heatmapVertexAttrs = context.createVertexAttributeArray();
|
||||
heatmapVertexAttrs->readDataDrivenPaintProperties<HeatmapWeight, HeatmapRadius>(
|
||||
paintPropertyBinders, evaluated, *propertiesAsUniforms);
|
||||
|
||||
#if !defined(NDEBUG)
|
||||
// We assume the properties are the same across tiles.
|
||||
if (previousPropertiesAsUniforms) {
|
||||
assert(*propertiesAsUniforms == previousPropertiesAsUniforms);
|
||||
} else {
|
||||
previousPropertiesAsUniforms = propertiesAsUniforms;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!heatmapShader) {
|
||||
continue;
|
||||
heatmapShader = heatmapShaderGroup->getOrCreateShader(context, *propertiesAsUniforms);
|
||||
if (!heatmapShader) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (const auto& attr = heatmapVertexAttrs.add(idVertexAttribName)) {
|
||||
if (const auto& attr = heatmapVertexAttrs->add(idVertexAttribName)) {
|
||||
attr->setSharedRawData(bucket.sharedVertices,
|
||||
offsetof(HeatmapLayoutVertex, a1),
|
||||
/*vertexOffset=*/0,
|
||||
@@ -441,7 +460,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
|
||||
heatmapBuilder->setSegments(
|
||||
gfx::Triangles(), bucket.sharedTriangles, bucket.segments.data(), bucket.segments.size());
|
||||
|
||||
heatmapBuilder->flush();
|
||||
heatmapBuilder->flush(context);
|
||||
|
||||
for (auto& drawable : heatmapBuilder->clearDrawables()) {
|
||||
drawable->setTileID(tileID);
|
||||
@@ -458,6 +477,10 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
|
||||
}
|
||||
}
|
||||
|
||||
if (layerTweaker && propertiesAsUniforms) {
|
||||
layerTweaker->setPropertiesAsUniforms(*propertiesAsUniforms);
|
||||
}
|
||||
|
||||
// Set up texture layer group
|
||||
if (!layerGroup) {
|
||||
if (auto layerGroup_ = context.createLayerGroup(layerIndex, /*initialCapacity=*/1, getID())) {
|
||||
@@ -494,8 +517,8 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
|
||||
}
|
||||
const auto textureVertexCount = sharedTextureVertices->elements();
|
||||
|
||||
gfx::VertexAttributeArray textureVertexAttrs;
|
||||
if (const auto& attr = textureVertexAttrs.add(idVertexAttribName)) {
|
||||
auto textureVertexAttrs = context.createVertexAttributeArray();
|
||||
if (const auto& attr = textureVertexAttrs->add(idVertexAttribName)) {
|
||||
attr->setSharedRawData(sharedTextureVertices,
|
||||
offsetof(HeatmapLayoutVertex, a1),
|
||||
/*vertexOffset=*/0,
|
||||
@@ -530,7 +553,7 @@ void RenderHeatmapLayer::update(gfx::ShaderRegistry& shaders,
|
||||
heatmapTextureBuilder->setTexture(std::move(texture), colorRampLocation.value());
|
||||
}
|
||||
|
||||
heatmapTextureBuilder->flush();
|
||||
heatmapTextureBuilder->flush(context);
|
||||
|
||||
for (auto& drawable : heatmapTextureBuilder->clearDrawables()) {
|
||||
drawable->setLayerTweaker(textureTweaker);
|
||||
|
||||
Reference in New Issue
Block a user