Change parameters.currentLayer to index instead of layerIndex (#2956)
This commit is contained in:
@@ -151,9 +151,6 @@ public:
|
||||
/// Set sub-layer index
|
||||
virtual void setSubLayerIndex(int32_t value) { subLayerIndex = value; }
|
||||
|
||||
void setLayerIndex(int32_t value) { layerIndex = value; }
|
||||
int32_t getLayerIndex() const { return layerIndex; }
|
||||
|
||||
/// Depth writability for 2D drawables
|
||||
DepthMaskType getDepthType() const { return depthType; }
|
||||
|
||||
@@ -293,7 +290,6 @@ protected:
|
||||
DrawPriority drawPriority = 0;
|
||||
int32_t lineWidth = 1;
|
||||
int32_t subLayerIndex = 0;
|
||||
int32_t layerIndex = 0;
|
||||
DepthMaskType depthType; // = DepthMaskType::ReadOnly;
|
||||
UniqueDrawableData drawableData{};
|
||||
gfx::VertexAttributeArrayPtr vertexAttributes;
|
||||
|
||||
@@ -169,12 +169,7 @@ public:
|
||||
|
||||
void setStencilTiles(RenderTiles);
|
||||
|
||||
void updateLayerIndex(int32_t value) override {
|
||||
layerIndex = value;
|
||||
for (auto* drawable : sortedDrawables) {
|
||||
drawable->setLayerIndex(value);
|
||||
}
|
||||
}
|
||||
void updateLayerIndex(int32_t value) override { layerIndex = value; }
|
||||
|
||||
protected:
|
||||
// When stencil clipping is enabled for the layer, this is the set
|
||||
@@ -245,12 +240,7 @@ public:
|
||||
|
||||
std::size_t clearDrawables() override;
|
||||
|
||||
void updateLayerIndex(int32_t value) override {
|
||||
layerIndex = value;
|
||||
for (auto& drawable : drawables) {
|
||||
drawable->setLayerIndex(value);
|
||||
}
|
||||
}
|
||||
void updateLayerIndex(int32_t value) override { layerIndex = value; }
|
||||
|
||||
protected:
|
||||
using DrawableCollection = std::set<gfx::UniqueDrawable, gfx::DrawableLessByPriority>;
|
||||
|
||||
@@ -62,6 +62,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute the given function for each contained layer group in reversed order
|
||||
template <typename Func /* void(LayerGroupBase&) */>
|
||||
void visitLayerGroupsReversed(Func f) {
|
||||
for (auto rit = layerGroupsByLayerIndex.rbegin(); rit != layerGroupsByLayerIndex.rend(); ++rit) {
|
||||
if (rit->second) {
|
||||
f(*rit->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Upload the layer groups
|
||||
void upload(gfx::UploadPass& uploadPass);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
namespace mbgl {
|
||||
|
||||
void LayerGroupBase::addDrawable(gfx::UniqueDrawable& drawable) {
|
||||
drawable->setLayerIndex(layerIndex);
|
||||
// init their tweakers
|
||||
for (const auto& tweaker : drawable->getTweakers()) {
|
||||
tweaker->init(*drawable);
|
||||
|
||||
@@ -64,7 +64,7 @@ void LayerTweaker::multiplyWithProjectionMatrix(/*in-out*/ mat4& matrix,
|
||||
if (!drawable.getIs3D() && drawable.getEnableDepth()) {
|
||||
// copy and adjust the projection matrix
|
||||
mat4 projMatrix = projMatrixRef;
|
||||
projMatrix[14] -= ((1 + drawable.getLayerIndex()) * PaintParameters::numSublayers -
|
||||
projMatrix[14] -= ((1 + parameters.currentLayer) * PaintParameters::numSublayers -
|
||||
drawable.getSubLayerIndex()) *
|
||||
PaintParameters::depthEpsilon;
|
||||
// multiply with the copy
|
||||
|
||||
@@ -959,16 +959,6 @@ size_t RenderOrchestrator::numLayerGroups() const noexcept {
|
||||
return layerGroupsByLayerIndex.size();
|
||||
}
|
||||
|
||||
int32_t RenderOrchestrator::maxLayerIndex() const {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
if (!layerGroupsByLayerIndex.empty()) {
|
||||
assert(layerGroupsByLayerIndex.crbegin()->first == layerGroupsByLayerIndex.crbegin()->second->getLayerIndex());
|
||||
return layerGroupsByLayerIndex.crbegin()->first;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void RenderOrchestrator::updateLayers(gfx::ShaderRegistry& shaders,
|
||||
gfx::Context& context,
|
||||
const TransformState& state,
|
||||
|
||||
@@ -106,7 +106,6 @@ public:
|
||||
bool addLayerGroup(LayerGroupBasePtr);
|
||||
bool removeLayerGroup(const LayerGroupBasePtr&);
|
||||
size_t numLayerGroups() const noexcept;
|
||||
int32_t maxLayerIndex() const;
|
||||
void updateLayerIndex(LayerGroupBasePtr, int32_t newIndex);
|
||||
|
||||
template <typename Func /* void(LayerGroupBase&) */>
|
||||
@@ -118,6 +117,15 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Func /* void(LayerGroupBase&) */>
|
||||
void visitLayerGroupsReversed(Func f) {
|
||||
for (auto rit = layerGroupsByLayerIndex.rbegin(); rit != layerGroupsByLayerIndex.rend(); ++rit) {
|
||||
if (rit->second) {
|
||||
f(*rit->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateLayers(gfx::ShaderRegistry&,
|
||||
gfx::Context&,
|
||||
const TransformState&,
|
||||
|
||||
@@ -69,28 +69,32 @@ void RenderTarget::render(RenderOrchestrator& orchestrator, const RenderTree& re
|
||||
"render target", {*offscreenTexture, Color{0.0f, 0.0f, 0.0f, 1.0f}, {}, {}});
|
||||
|
||||
// Run layer tweakers to update any dynamic elements
|
||||
visitLayerGroups([&](LayerGroupBase& layerGroup) { layerGroup.runTweakers(renderTree, parameters); });
|
||||
parameters.currentLayer = 0;
|
||||
visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
layerGroup.runTweakers(renderTree, parameters);
|
||||
parameters.currentLayer++;
|
||||
});
|
||||
|
||||
// draw layer groups, opaque pass
|
||||
parameters.pass = RenderPass::Opaque;
|
||||
parameters.currentLayer = 0;
|
||||
parameters.depthRangeSize = 1 -
|
||||
(numLayerGroups() + 2) * PaintParameters::numSublayers * PaintParameters::depthEpsilon;
|
||||
|
||||
visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
parameters.currentLayer = 0;
|
||||
visitLayerGroupsReversed([&](LayerGroupBase& layerGroup) {
|
||||
layerGroup.render(orchestrator, parameters);
|
||||
parameters.currentLayer++;
|
||||
});
|
||||
|
||||
// draw layer groups, translucent pass
|
||||
parameters.pass = RenderPass::Translucent;
|
||||
parameters.currentLayer = static_cast<int32_t>(numLayerGroups()) - 1;
|
||||
parameters.depthRangeSize = 1 -
|
||||
(numLayerGroups() + 2) * PaintParameters::numSublayers * PaintParameters::depthEpsilon;
|
||||
|
||||
parameters.currentLayer = static_cast<uint32_t>(numLayerGroups()) - 1;
|
||||
visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
layerGroup.render(orchestrator, parameters);
|
||||
if (parameters.currentLayer != 0) {
|
||||
if (parameters.currentLayer > 0) {
|
||||
parameters.currentLayer--;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -252,8 +252,11 @@ void Renderer::Impl::render(const RenderTree& renderTree,
|
||||
#endif
|
||||
|
||||
// Tweakers are run in the upload pass so they can set up uniforms.
|
||||
orchestrator.visitLayerGroups(
|
||||
[&](LayerGroupBase& layerGroup) { layerGroup.runTweakers(renderTree, parameters); });
|
||||
parameters.currentLayer = 0;
|
||||
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
layerGroup.runTweakers(renderTree, parameters);
|
||||
parameters.currentLayer++;
|
||||
});
|
||||
orchestrator.visitDebugLayerGroups(
|
||||
[&](LayerGroupBase& layerGroup) { layerGroup.runTweakers(renderTree, parameters); });
|
||||
|
||||
@@ -315,10 +318,12 @@ void Renderer::Impl::render(const RenderTree& renderTree,
|
||||
assert(parameters.pass == RenderPass::Pass3D);
|
||||
|
||||
// draw layer groups, 3D pass
|
||||
const auto maxLayerIndex = orchestrator.maxLayerIndex();
|
||||
parameters.currentLayer = static_cast<uint32_t>(orchestrator.numLayerGroups()) - 1;
|
||||
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
layerGroup.render(orchestrator, parameters);
|
||||
parameters.currentLayer = maxLayerIndex - layerGroup.getLayerIndex();
|
||||
if (parameters.currentLayer > 0) {
|
||||
parameters.currentLayer--;
|
||||
}
|
||||
});
|
||||
};
|
||||
#endif // MLN_DRAWABLE_RENDERER
|
||||
@@ -368,30 +373,31 @@ void Renderer::Impl::render(const RenderTree& renderTree,
|
||||
// Drawables
|
||||
const auto drawableOpaquePass = [&] {
|
||||
const auto debugGroup(parameters.renderPass->createDebugGroup("drawables-opaque"));
|
||||
const auto maxLayerIndex = orchestrator.maxLayerIndex();
|
||||
parameters.pass = RenderPass::Opaque;
|
||||
parameters.currentLayer = 0;
|
||||
parameters.depthRangeSize = 1 -
|
||||
(maxLayerIndex + 3) * PaintParameters::numSublayers * PaintParameters::depthEpsilon;
|
||||
parameters.depthRangeSize = 1 - (orchestrator.numLayerGroups() + 2) * PaintParameters::numSublayers *
|
||||
PaintParameters::depthEpsilon;
|
||||
|
||||
// draw layer groups, opaque pass
|
||||
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
parameters.currentLayer = layerGroup.getLayerIndex();
|
||||
parameters.currentLayer = 0;
|
||||
orchestrator.visitLayerGroupsReversed([&](LayerGroupBase& layerGroup) {
|
||||
layerGroup.render(orchestrator, parameters);
|
||||
parameters.currentLayer++;
|
||||
});
|
||||
};
|
||||
|
||||
const auto drawableTranslucentPass = [&] {
|
||||
const auto debugGroup(parameters.renderPass->createDebugGroup("drawables-translucent"));
|
||||
const auto maxLayerIndex = orchestrator.maxLayerIndex();
|
||||
parameters.pass = RenderPass::Translucent;
|
||||
parameters.depthRangeSize = 1 -
|
||||
(maxLayerIndex + 3) * PaintParameters::numSublayers * PaintParameters::depthEpsilon;
|
||||
parameters.depthRangeSize = 1 - (orchestrator.numLayerGroups() + 2) * PaintParameters::numSublayers *
|
||||
PaintParameters::depthEpsilon;
|
||||
|
||||
// draw layer groups, translucent pass
|
||||
parameters.currentLayer = static_cast<uint32_t>(orchestrator.numLayerGroups()) - 1;
|
||||
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
parameters.currentLayer = maxLayerIndex - layerGroup.getLayerIndex();
|
||||
layerGroup.render(orchestrator, parameters);
|
||||
if (parameters.currentLayer > 0) {
|
||||
parameters.currentLayer--;
|
||||
}
|
||||
});
|
||||
|
||||
// Finally, render any legacy layers which have not been converted to drawables.
|
||||
|
||||
Reference in New Issue
Block a user