Setting up UBO for fill drawables (#1175)
This commit is contained in:
committed by
Bart Louwers
parent
ad4a598975
commit
b823f036fe
@@ -14,13 +14,40 @@ using namespace style;
|
||||
|
||||
struct alignas(16) FillDrawableUBO {
|
||||
std::array<float, 4 * 4> matrix;
|
||||
/* 64 */ std::array<float, 4> scale;
|
||||
std::array<float, 2> world;
|
||||
std::array<float, 2> padding;
|
||||
/* 88 */ std::array<float, 2> pixel_coord_upper;
|
||||
/* 96 */ std::array<float, 2> pixel_coord_lower;
|
||||
/* 104 */ std::array<float, 2> texsize;
|
||||
/* 112 */ float fade;
|
||||
|
||||
// Attribute interpolations (used without HAS_UNIFORM_u_*)
|
||||
/* 116 */ float color_t;
|
||||
/* 120 */ float opacity_t;
|
||||
/* 124 */ float outline_color_t;
|
||||
/* 128 */ float pattern_from_t;
|
||||
/* 132 */ float pattern_to_t;
|
||||
|
||||
// Uniform alternates for attributes (used with HAS_UNIFORM_u_*)
|
||||
/* 136 */ std::array<float, 2> color;
|
||||
/* 144 */ std::array<float, 2> opacity;
|
||||
/* 152 */ std::array<float, 2> outline_color_pad;
|
||||
/* 160 */ std::array<float, 4> outline_color;
|
||||
/* 176 */ std::array<float, 4> pattern_from;
|
||||
/* 208 */ std::array<float, 4> pattern_to;
|
||||
|
||||
// Pattern texture
|
||||
/* ? */ // Drawable::TextureAttachment? image;
|
||||
|
||||
/* */ // std::array<float, 3> padding;
|
||||
/* 208 */
|
||||
};
|
||||
static_assert(sizeof(FillDrawableUBO) % 16 == 0);
|
||||
static_assert(sizeof(FillDrawableUBO) == 208);
|
||||
|
||||
void FillLayerTweaker::execute(LayerGroup& layerGroup, const PaintParameters& parameters) {
|
||||
// const auto& evaluated = static_cast<const FillLayerProperties&>(*evaluatedProperties).evaluated;
|
||||
const auto& props = static_cast<const FillLayerProperties&>(*evaluatedProperties);
|
||||
// const auto& evaluated = props.evaluated;
|
||||
const auto& crossfade = props.crossfade;
|
||||
|
||||
layerGroup.observeDrawables([&](gfx::Drawable& drawable) {
|
||||
if (!drawable.getTileID()) {
|
||||
@@ -48,11 +75,43 @@ void FillLayerTweaker::execute(LayerGroup& layerGroup, const PaintParameters& pa
|
||||
matrix::multiply(matrix, drawable.getMatrix(), tileMat);
|
||||
matrix = tileMat;
|
||||
|
||||
const auto renderableSize = parameters.backend.getDefaultRenderable().getSize();
|
||||
// matrix = tile.translatedMatrix(evaluated.get<FillTranslate>(), evaluated.get<FillTranslateAnchor>(),
|
||||
// parameters.state),
|
||||
|
||||
// from FillPatternProgram::layoutUniformValues
|
||||
const auto renderableSize = parameters.backend.getDefaultRenderable().getSize();
|
||||
const auto intZoom = parameters.state.getIntegerZoom();
|
||||
const auto tileRatio = 1 / tileID.pixelsToTileUnits(1, intZoom);
|
||||
const int32_t tileSizeAtNearestZoom = static_cast<int32_t>(
|
||||
util::tileSize_D * parameters.state.zoomScale(intZoom - tileID.canonical.z));
|
||||
const int32_t pixelX = static_cast<int32_t>(
|
||||
tileSizeAtNearestZoom *
|
||||
(tileID.canonical.x + tileID.wrap * parameters.state.zoomScale(tileID.canonical.z)));
|
||||
const int32_t pixelY = tileSizeAtNearestZoom * tileID.canonical.y;
|
||||
const auto pixelRatio = parameters.pixelRatio;
|
||||
|
||||
const FillDrawableUBO drawableUBO = {
|
||||
/*.matrix=*/util::cast<float>(matrix),
|
||||
/*.scale=*/{pixelRatio, tileRatio, crossfade.fromScale, crossfade.toScale},
|
||||
/*.world=*/{(float)renderableSize.width, (float)renderableSize.height},
|
||||
/*.pixel_coord_upper=*/{static_cast<float>(pixelX >> 16), static_cast<float>(pixelY >> 16)},
|
||||
/*.pixel_coord_lower=*/{static_cast<float>(pixelX & 0xFFFF), static_cast<float>(pixelY & 0xFFFF)},
|
||||
/*.texsize=*/{0.0f, 0.0f}, // tile.getIconAtlasTexture().size
|
||||
/*.fade=*/crossfade.t,
|
||||
/*.color_t=*/0.0f,
|
||||
/*.opacity_t=*/0.0f,
|
||||
/*.outline_color_t=*/0.0f,
|
||||
/*.pattern_from_t=*/0.0f,
|
||||
/*.pattern_to_t=*/0.0f,
|
||||
/*.color=*/{0.0f},
|
||||
/*.opacity=*/{0.0f},
|
||||
/*.outline_color_pad=*/{0.0f},
|
||||
/*.outline_color=*/{0.0f},
|
||||
/*.pattern_from=*/{0.0f},
|
||||
/*.pattern_to=*/{0.0f},
|
||||
/*.image=*/ // TextureAttachment(tile.getIconAtlasTexture().getResource(), Linear)
|
||||
};
|
||||
|
||||
FillDrawableUBO drawableUBO;
|
||||
drawableUBO.matrix = util::cast<float>(matrix);
|
||||
drawableUBO.world = {(float)renderableSize.width, (float)renderableSize.height};
|
||||
auto drawableUniformBuffer = parameters.context.createUniformBuffer(&drawableUBO, sizeof(drawableUBO));
|
||||
drawable.mutableUniformBuffers().addOrReplace("FillDrawableUBO", drawableUniformBuffer);
|
||||
});
|
||||
|
||||
@@ -340,6 +340,16 @@ void RenderFillLayer::update(const int32_t layerIndex,
|
||||
gfx::VertexAttributeArray fillVertexAttrs;
|
||||
gfx::VertexAttributeArray outlineVertexAttrs;
|
||||
|
||||
const auto finish = [&](gfx::DrawableBuilder& builder, RenderPass pass, const OverscaledTileID& tileID) {
|
||||
builder.flush();
|
||||
|
||||
for (auto& drawable : builder.clearDrawables()) {
|
||||
drawable->setTileID(tileID);
|
||||
tileLayerGroup->addDrawable(pass, tileID, std::move(drawable));
|
||||
++stats.tileDrawablesAdded;
|
||||
}
|
||||
};
|
||||
|
||||
for (const auto renderPass : {RenderPass::Opaque, RenderPass::Translucent}) {
|
||||
if (!(mbgl::underlying_type(renderPass) & evaluatedProperties->renderPasses)) {
|
||||
continue;
|
||||
@@ -370,6 +380,7 @@ void RenderFillLayer::update(const int32_t layerIndex,
|
||||
|
||||
auto& bucket = static_cast<FillBucket&>(*renderData->bucket);
|
||||
const auto& evaluated = getEvaluated<FillLayerProperties>(renderData->layerProperties);
|
||||
const auto& crossfade = getCrossfade<FillLayerProperties>(renderData->layerProperties);
|
||||
|
||||
std::vector<std::array<int16_t, 2>> rawVerts;
|
||||
const auto buildVertices = [&]() {
|
||||
@@ -512,14 +523,7 @@ void RenderFillLayer::update(const int32_t layerIndex,
|
||||
fillBuilder->addTriangles(bucket.triangles.vector(), seg.indexOffset, seg.indexLength);
|
||||
}
|
||||
|
||||
fillBuilder->flush();
|
||||
|
||||
for (auto& drawable : fillBuilder->clearDrawables()) {
|
||||
drawable->setTileID(tileID);
|
||||
|
||||
tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
|
||||
++stats.tileDrawablesAdded;
|
||||
}
|
||||
finish(*fillBuilder, renderPass, tileID);
|
||||
}
|
||||
if (outlineBuilder) {
|
||||
buildVertices();
|
||||
@@ -529,21 +533,13 @@ void RenderFillLayer::update(const int32_t layerIndex,
|
||||
outlineBuilder->addLines(bucket.lines.vector(), seg.indexOffset, seg.indexLength);
|
||||
}
|
||||
|
||||
outlineBuilder->flush();
|
||||
|
||||
for (auto& drawable : outlineBuilder->clearDrawables()) {
|
||||
drawable->setTileID(tileID);
|
||||
|
||||
tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
|
||||
++stats.tileDrawablesAdded;
|
||||
}
|
||||
finish(*outlineBuilder, renderPass, tileID);
|
||||
}
|
||||
} else { // FillPattern is defined
|
||||
if (renderPass != RenderPass::Translucent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& crossfade = getCrossfade<FillLayerProperties>(renderData->layerProperties);
|
||||
const auto doOutline = evaluated.get<FillAntialias>() &&
|
||||
unevaluated.get<FillOutlineColor>().isUndefined();
|
||||
const auto& fillPatternValue = evaluated.get<FillPattern>().constantOr(
|
||||
@@ -560,7 +556,7 @@ void RenderFillLayer::update(const int32_t layerIndex,
|
||||
patternBuilder->setDepthType(gfx::DepthMaskType::ReadWrite);
|
||||
patternBuilder->setCullFaceMode(gfx::CullFaceMode::disabled());
|
||||
patternBuilder->setLayerIndex(layerIndex);
|
||||
outlinePatternBuilder->setSubLayerIndex(1);
|
||||
patternBuilder->setSubLayerIndex(1);
|
||||
}
|
||||
if (doOutline && !outlinePatternBuilder && outlinePatternShader) {
|
||||
outlinePatternBuilder = context.createDrawableBuilder("fill-outline-pattern");
|
||||
@@ -595,14 +591,7 @@ void RenderFillLayer::update(const int32_t layerIndex,
|
||||
patternBuilder->addTriangles(bucket.triangles.vector(), seg.indexOffset, seg.indexLength);
|
||||
}
|
||||
|
||||
patternBuilder->flush();
|
||||
|
||||
for (auto& drawable : patternBuilder->clearDrawables()) {
|
||||
drawable->setTileID(tileID);
|
||||
|
||||
// tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
|
||||
++stats.tileDrawablesAdded;
|
||||
}
|
||||
finish(*patternBuilder, renderPass, tileID);
|
||||
}
|
||||
if (outlinePatternBuilder) {
|
||||
buildVertices();
|
||||
@@ -612,14 +601,8 @@ void RenderFillLayer::update(const int32_t layerIndex,
|
||||
outlinePatternBuilder->addLines(bucket.lines.vector(), seg.indexOffset, seg.indexLength);
|
||||
}
|
||||
|
||||
finish(*outlinePatternBuilder, renderPass, tileID);
|
||||
outlinePatternBuilder->flush();
|
||||
|
||||
for (auto& drawable : outlinePatternBuilder->clearDrawables()) {
|
||||
drawable->setTileID(tileID);
|
||||
|
||||
// tileLayerGroup->addDrawable(renderPass, tileID, std::move(drawable));
|
||||
++stats.tileDrawablesAdded;
|
||||
}
|
||||
}
|
||||
|
||||
// auto draw = [&](auto& programInstance,
|
||||
|
||||
Reference in New Issue
Block a user