Skip to content

Commit

Permalink
Move circle UBOs to the tweaker
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSylvester committed Aug 7, 2024
1 parent 1156aab commit 7ee001b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
26 changes: 24 additions & 2 deletions src/mbgl/renderer/layers/circle_layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <mbgl/gfx/context.hpp>
#include <mbgl/gfx/drawable.hpp>
#include <mbgl/programs/circle_program.hpp>
#include <mbgl/renderer/layer_group.hpp>
#include <mbgl/renderer/paint_parameters.hpp>
#include <mbgl/renderer/render_tree.hpp>
Expand Down Expand Up @@ -34,7 +35,7 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete
const auto debugGroup = parameters.encoder->createDebugGroup(label.c_str());
#endif

const auto zoom = parameters.state.getZoom();
const auto zoom = static_cast<float>(parameters.state.getZoom());
const bool pitchWithMap = evaluated.get<CirclePitchAlignment>() == AlignmentType::Map;
const bool scaleWithMap = evaluated.get<CirclePitchScale>() == CirclePitchScaleType::Map;

Expand Down Expand Up @@ -64,14 +65,21 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete
}
const UnwrappedTileID tileID = drawable.getTileID()->toUnwrapped();

auto* binders = static_cast<CircleProgram::Binders*>(drawable.getBinders());
const auto* tile = drawable.getRenderTile();
if (!binders || !tile) {
assert(false);
return;
}

const auto& translation = evaluated.get<CircleTranslate>();
const auto anchor = evaluated.get<CircleTranslateAnchor>();
constexpr bool inViewportPixelUnits = false; // from RenderTile::translatedMatrix
constexpr bool nearClipped = false;
const auto matrix = getTileMatrix(
tileID, parameters, translation, anchor, nearClipped, inViewportPixelUnits, drawable);

const auto pixelsToTileUnits = tileID.pixelsToTileUnits(1.0f, static_cast<float>(zoom));
const auto pixelsToTileUnits = tileID.pixelsToTileUnits(1.0f, zoom);
const auto extrudeScale = pitchWithMap ? std::array<float, 2>{pixelsToTileUnits, pixelsToTileUnits}
: parameters.pixelsToGLUnits;

Expand All @@ -82,6 +90,20 @@ void CircleLayerTweaker::execute(LayerGroupBase& layerGroup, const PaintParamete

auto& drawableUniforms = drawable.mutableUniformBuffers();
drawableUniforms.createOrUpdate(idCircleDrawableUBO, &drawableUBO, context);

const CircleInterpolateUBO interpolateUBO = {
/* .color_t = */ std::get<0>(binders->get<CircleColor>()->interpolationFactor(zoom)),
/* .radius_t = */ std::get<0>(binders->get<CircleRadius>()->interpolationFactor(zoom)),
/* .blur_t = */ std::get<0>(binders->get<CircleBlur>()->interpolationFactor(zoom)),
/* .opacity_t = */ std::get<0>(binders->get<CircleOpacity>()->interpolationFactor(zoom)),
/* .stroke_color_t = */
std::get<0>(binders->get<CircleStrokeColor>()->interpolationFactor(zoom)),
/* .stroke_width_t = */
std::get<0>(binders->get<CircleStrokeWidth>()->interpolationFactor(zoom)),
/* .stroke_opacity_t = */
std::get<0>(binders->get<CircleStrokeOpacity>()->interpolationFactor(zoom)),
/* .padding = */ 0};
drawableUniforms.createOrUpdate(idCircleInterpolateUBO, &interpolateUBO, context);
});
}

Expand Down
26 changes: 3 additions & 23 deletions src/mbgl/renderer/layers/render_circle_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
continue;
}

const auto& bucket = static_cast<const CircleBucket&>(*renderData->bucket);
auto& bucket = static_cast<CircleBucket&>(*renderData->bucket);
const auto vertexCount = bucket.vertices.elements();
auto& paintPropertyBinders = bucket.paintPropertyBinders.at(getID());

Expand All @@ -338,37 +338,18 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
}
setRenderTileBucketID(tileID, bucket.getID());

const float zoom = static_cast<float>(state.getZoom());
const CircleInterpolateUBO interpolateUBO = {
/* .color_t = */ std::get<0>(paintPropertyBinders.get<CircleColor>()->interpolationFactor(zoom)),
/* .radius_t = */ std::get<0>(paintPropertyBinders.get<CircleRadius>()->interpolationFactor(zoom)),
/* .blur_t = */ std::get<0>(paintPropertyBinders.get<CircleBlur>()->interpolationFactor(zoom)),
/* .opacity_t = */ std::get<0>(paintPropertyBinders.get<CircleOpacity>()->interpolationFactor(zoom)),
/* .stroke_color_t = */
std::get<0>(paintPropertyBinders.get<CircleStrokeColor>()->interpolationFactor(zoom)),
/* .stroke_width_t = */
std::get<0>(paintPropertyBinders.get<CircleStrokeWidth>()->interpolationFactor(zoom)),
/* .stroke_opacity_t = */
std::get<0>(paintPropertyBinders.get<CircleStrokeOpacity>()->interpolationFactor(zoom)),
/* .padding = */ 0};

// If there are already drawables for this tile, update their UBOs and move on to the next tile.
auto updateExisting = [&](gfx::Drawable& drawable) {
if (drawable.getLayerTweaker() != layerTweaker) {
// This drawable was produced on a previous style/bucket, and should not be updated.
return false;
}

auto& drawableUniforms = drawable.mutableUniformBuffers();
drawableUniforms.createOrUpdate(idCircleInterpolateUBO, &interpolateUBO, context);
return true;
};
if (updateTile(renderPass, tileID, std::move(updateExisting))) {
continue;
}

const auto interpBuffer = context.createUniformBuffer(&interpolateUBO, sizeof(interpolateUBO));

propertiesAsUniforms.first.clear();
propertiesAsUniforms.second.clear();

Expand Down Expand Up @@ -413,9 +394,8 @@ void RenderCircleLayer::update(gfx::ShaderRegistry& shaders,
for (auto& drawable : circleBuilder->clearDrawables()) {
drawable->setTileID(tileID);
drawable->setLayerTweaker(layerTweaker);

auto& drawableUniforms = drawable->mutableUniformBuffers();
drawableUniforms.set(idCircleInterpolateUBO, interpBuffer);
drawable->setBinders(renderData->bucket, &paintPropertyBinders);
drawable->setRenderTile(renderTilesOwner, &tile);

tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
++stats.drawablesAdded;
Expand Down

0 comments on commit 7ee001b

Please sign in to comment.