Change parameters.currentLayer to index instead of layerIndex (#2956)
This commit is contained in:
@@ -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