Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change parameters.currentLayer to index instead of layerIndex #2956

Merged
4 changes: 0 additions & 4 deletions include/mbgl/gfx/drawable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ class Drawable {
/// 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; }

Expand Down Expand Up @@ -293,7 +290,6 @@ class Drawable {
DrawPriority drawPriority = 0;
int32_t lineWidth = 1;
int32_t subLayerIndex = 0;
int32_t layerIndex = 0;
DepthMaskType depthType; // = DepthMaskType::ReadOnly;
UniqueDrawableData drawableData{};
gfx::VertexAttributeArrayPtr vertexAttributes;
Expand Down
14 changes: 2 additions & 12 deletions include/mbgl/renderer/layer_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,7 @@ class TileLayerGroup : public LayerGroupBase {

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
Expand Down Expand Up @@ -245,12 +240,7 @@ class LayerGroup : public LayerGroupBase {

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>;
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/layer_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/layer_tweaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions src/mbgl/renderer/render_orchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/renderer/render_orchestrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class RenderOrchestrator final : public GlyphManagerObserver, public ImageManage
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&) */>
Expand Down
30 changes: 16 additions & 14 deletions src/mbgl/renderer/renderer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
int32_t i = static_cast<int32_t>(orchestrator.numLayerGroups()) - 1;
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
parameters.currentLayer = i++;
layerGroup.runTweakers(renderTree, parameters);
});
orchestrator.visitDebugLayerGroups(
[&](LayerGroupBase& layerGroup) { layerGroup.runTweakers(renderTree, parameters); });

Expand Down Expand Up @@ -315,10 +318,10 @@ void Renderer::Impl::render(const RenderTree& renderTree,
assert(parameters.pass == RenderPass::Pass3D);

// draw layer groups, 3D pass
const auto maxLayerIndex = orchestrator.maxLayerIndex();
int32_t i = static_cast<int32_t>(orchestrator.numLayerGroups()) - 1;
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
parameters.currentLayer = i++;
layerGroup.render(orchestrator, parameters);
parameters.currentLayer = maxLayerIndex - layerGroup.getLayerIndex();
});
};
#endif // MLN_DRAWABLE_RENDERER
Expand Down Expand Up @@ -368,37 +371,36 @@ 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
int32_t i = static_cast<int32_t>(orchestrator.numLayerGroups()) - 1;
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
parameters.currentLayer = layerGroup.getLayerIndex();
parameters.currentLayer = i--;
TimSylvester marked this conversation as resolved.
Show resolved Hide resolved
layerGroup.render(orchestrator, parameters);
});
};

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
int32_t i = static_cast<int32_t>(orchestrator.numLayerGroups()) - 1;
louwers marked this conversation as resolved.
Show resolved Hide resolved
orchestrator.visitLayerGroups([&](LayerGroupBase& layerGroup) {
parameters.currentLayer = maxLayerIndex - layerGroup.getLayerIndex();
parameters.currentLayer = i--;
layerGroup.render(orchestrator, parameters);
});

// Finally, render any legacy layers which have not been converted to drawables.
// Note that they may be out of order, this is just a temporary fix for `RenderLocationIndicatorLayer` (#2216)
parameters.depthRangeSize = 1 - (layerRenderItems.size() + 2) * PaintParameters::numSublayers *
PaintParameters::depthEpsilon;
int32_t i = static_cast<int32_t>(layerRenderItems.size()) - 1;
i = static_cast<int32_t>(layerRenderItems.size()) - 1;
for (auto it = layerRenderItems.begin(); it != layerRenderItems.end() && i >= 0; ++it, --i) {
parameters.currentLayer = i;
const RenderItem& item = *it;
Expand Down
Loading