Drawable PR1 - Foundation (#1355)
Co-authored-by: Stefan Karschti <stefan.karschti@gmail.com> Co-authored-by: Bart Louwers <bart.louwers@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -21,7 +21,7 @@ void TileLayerGroupGL::upload(gfx::UploadPass& uploadPass) {
|
||||
return;
|
||||
}
|
||||
|
||||
observeDrawables([&](gfx::Drawable& drawable) {
|
||||
visitDrawables([&](gfx::Drawable& drawable) {
|
||||
if (!drawable.getEnabled()) {
|
||||
return;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters)
|
||||
|
||||
// Collect the tile IDs relevant to stenciling and update the stencil buffer, if necessary.
|
||||
std::set<UnwrappedTileID> tileIDs;
|
||||
observeDrawables([&](const gfx::Drawable& drawable) {
|
||||
visitDrawables([&](const gfx::Drawable& drawable) {
|
||||
if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) {
|
||||
return;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters)
|
||||
const auto debugGroupRender = parameters.encoder->createDebugGroup(label_render.c_str());
|
||||
#endif
|
||||
|
||||
observeDrawables([&](gfx::Drawable& drawable) {
|
||||
visitDrawables([&](gfx::Drawable& drawable) {
|
||||
if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) {
|
||||
return;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ void LayerGroupGL::upload(gfx::UploadPass& uploadPass) {
|
||||
return;
|
||||
}
|
||||
|
||||
observeDrawables([&](gfx::Drawable& drawable) {
|
||||
visitDrawables([&](gfx::Drawable& drawable) {
|
||||
if (!drawable.getEnabled()) {
|
||||
return;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ void LayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) {
|
||||
return;
|
||||
}
|
||||
|
||||
observeDrawables([&](gfx::Drawable& drawable) {
|
||||
visitDrawables([&](gfx::Drawable& drawable) {
|
||||
if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ RenderTargetGL::~RenderTargetGL() {
|
||||
}
|
||||
|
||||
void RenderTargetGL::upload(gfx::UploadPass& uploadPass) {
|
||||
observeLayerGroups(([&](LayerGroupBase& layerGroup) { layerGroup.upload(uploadPass); }));
|
||||
visitLayerGroups(([&](LayerGroupBase& layerGroup) { layerGroup.upload(uploadPass); }));
|
||||
}
|
||||
|
||||
void RenderTargetGL::render(RenderOrchestrator& orchestrator,
|
||||
@@ -52,7 +52,7 @@ void RenderTargetGL::render(RenderOrchestrator& orchestrator,
|
||||
glContext.clear(Color{0.0f, 0.0f, 0.0f, 1.0f}, {}, {});
|
||||
|
||||
// Run layer tweakers to update any dynamic elements
|
||||
observeLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
if (layerGroup.getLayerTweaker()) {
|
||||
layerGroup.getLayerTweaker()->execute(layerGroup, renderTree, parameters);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ void RenderTargetGL::render(RenderOrchestrator& orchestrator,
|
||||
parameters.currentLayer = 0;
|
||||
parameters.depthRangeSize = 1 - (numLayerGroups() + 2) * parameters.numSublayers * PaintParameters::depthEpsilon;
|
||||
|
||||
observeLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
layerGroup.render(orchestrator, parameters);
|
||||
parameters.currentLayer++;
|
||||
});
|
||||
@@ -73,7 +73,7 @@ void RenderTargetGL::render(RenderOrchestrator& orchestrator,
|
||||
parameters.currentLayer = static_cast<int32_t>(numLayerGroups()) - 1;
|
||||
parameters.depthRangeSize = 1 - (numLayerGroups() + 2) * parameters.numSublayers * PaintParameters::depthEpsilon;
|
||||
|
||||
observeLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
visitLayerGroups([&](LayerGroupBase& layerGroup) {
|
||||
layerGroup.render(orchestrator, parameters);
|
||||
if (parameters.currentLayer != 0) {
|
||||
parameters.currentLayer--;
|
||||
|
||||
@@ -36,7 +36,7 @@ void LayerGroup::addDrawable(gfx::UniqueDrawable&& drawable) {
|
||||
impl->drawables.emplace(std::move(drawable));
|
||||
}
|
||||
|
||||
std::size_t LayerGroup::observeDrawables(const std::function<void(gfx::Drawable&)>&& f) {
|
||||
std::size_t LayerGroup::visitDrawables(const std::function<void(gfx::Drawable&)>&& f) {
|
||||
for (const auto& item : impl->drawables) {
|
||||
if (item) {
|
||||
f(*item);
|
||||
@@ -45,7 +45,7 @@ std::size_t LayerGroup::observeDrawables(const std::function<void(gfx::Drawable&
|
||||
return impl->drawables.size();
|
||||
}
|
||||
|
||||
std::size_t LayerGroup::observeDrawables(const std::function<void(const gfx::Drawable&)>&& f) const {
|
||||
std::size_t LayerGroup::visitDrawables(const std::function<void(const gfx::Drawable&)>&& f) const {
|
||||
for (const auto& item : impl->drawables) {
|
||||
if (item) {
|
||||
f(*item);
|
||||
@@ -54,13 +54,13 @@ std::size_t LayerGroup::observeDrawables(const std::function<void(const gfx::Dra
|
||||
return impl->drawables.size();
|
||||
}
|
||||
|
||||
std::size_t LayerGroup::observeDrawablesRemove(const std::function<bool(gfx::Drawable&)>&& f) {
|
||||
std::size_t LayerGroup::removeDrawablesIf(const std::function<bool(gfx::Drawable&)>&& f) {
|
||||
decltype(impl->drawables) newSet;
|
||||
const auto oldSize = impl->drawables.size();
|
||||
while (!impl->drawables.empty()) {
|
||||
// set members are immutable, since changes could affect its position, so extract each item
|
||||
gfx::UniqueDrawable drawable = std::move(impl->drawables.extract(impl->drawables.begin()).value());
|
||||
if (f(*drawable)) {
|
||||
if (!f(*drawable)) {
|
||||
// Not removed, keep it, but in a new set so that if the key value
|
||||
// has increased, we don't see it again during this iteration.
|
||||
newSet.emplace_hint(newSet.end(), std::move(drawable));
|
||||
|
||||
@@ -44,7 +44,7 @@ const LayerGroupBasePtr& RenderTarget::getLayerGroup(const int32_t layerIndex) c
|
||||
return (hit == layerGroupsByLayerIndex.end()) ? no_group : hit->second;
|
||||
}
|
||||
|
||||
void RenderTarget::observeLayerGroups(std::function<void(LayerGroupBase&)> f) {
|
||||
void RenderTarget::visitLayerGroups(std::function<void(LayerGroupBase&)> f) {
|
||||
for (auto& pair : layerGroupsByLayerIndex) {
|
||||
if (pair.second) {
|
||||
f(*pair.second);
|
||||
@@ -52,7 +52,7 @@ void RenderTarget::observeLayerGroups(std::function<void(LayerGroupBase&)> f) {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTarget::observeLayerGroups(std::function<void(const LayerGroupBase&)> f) const {
|
||||
void RenderTarget::visitLayerGroups(std::function<void(const LayerGroupBase&)> f) const {
|
||||
for (const auto& pair : layerGroupsByLayerIndex) {
|
||||
if (pair.second) {
|
||||
f(*pair.second);
|
||||
|
||||
@@ -84,7 +84,7 @@ void TileLayerGroup::addDrawable(mbgl::RenderPass pass, const OverscaledTileID&
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t TileLayerGroup::observeDrawables(const std::function<void(gfx::Drawable&)>&& f) {
|
||||
std::size_t TileLayerGroup::visitDrawables(const std::function<void(gfx::Drawable&)>&& f) {
|
||||
assert(impl->drawablesByTile.size() == impl->sortedDrawables.size());
|
||||
for (auto* drawable : impl->sortedDrawables) {
|
||||
f(*drawable);
|
||||
@@ -92,7 +92,7 @@ std::size_t TileLayerGroup::observeDrawables(const std::function<void(gfx::Drawa
|
||||
return impl->sortedDrawables.size();
|
||||
}
|
||||
|
||||
std::size_t TileLayerGroup::observeDrawables(const std::function<void(const gfx::Drawable&)>&& f) const {
|
||||
std::size_t TileLayerGroup::visitDrawables(const std::function<void(const gfx::Drawable&)>&& f) const {
|
||||
assert(impl->drawablesByTile.size() == impl->sortedDrawables.size());
|
||||
for (const auto* drawable : impl->sortedDrawables) {
|
||||
f(*drawable);
|
||||
@@ -100,11 +100,11 @@ std::size_t TileLayerGroup::observeDrawables(const std::function<void(const gfx:
|
||||
return impl->sortedDrawables.size();
|
||||
}
|
||||
|
||||
std::size_t TileLayerGroup::observeDrawablesRemove(const std::function<bool(gfx::Drawable&)>&& f) {
|
||||
std::size_t TileLayerGroup::removeDrawablesIf(const std::function<bool(gfx::Drawable&)>&& f) {
|
||||
const auto oldSize = impl->drawablesByTile.size();
|
||||
for (auto i = impl->drawablesByTile.begin(); i != impl->drawablesByTile.end();) {
|
||||
auto& drawable = i->second;
|
||||
if (f(*drawable)) {
|
||||
if (!f(*drawable)) {
|
||||
// Not removed, keep going
|
||||
++i;
|
||||
} else {
|
||||
@@ -117,18 +117,18 @@ std::size_t TileLayerGroup::observeDrawablesRemove(const std::function<bool(gfx:
|
||||
return (oldSize - impl->drawablesByTile.size());
|
||||
}
|
||||
|
||||
std::size_t TileLayerGroup::observeDrawables(mbgl::RenderPass pass,
|
||||
const OverscaledTileID& tileID,
|
||||
const std::function<void(gfx::Drawable&)>&& f) {
|
||||
std::size_t TileLayerGroup::visitDrawables(mbgl::RenderPass pass,
|
||||
const OverscaledTileID& tileID,
|
||||
const std::function<void(gfx::Drawable&)>&& f) {
|
||||
assert(impl->drawablesByTile.size() == impl->sortedDrawables.size());
|
||||
const auto range = impl->drawablesByTile.equal_range({pass, tileID});
|
||||
std::for_each(range.first, range.second, [&f](const auto& pair) { f(*pair.second); });
|
||||
return std::distance(range.first, range.second);
|
||||
}
|
||||
|
||||
std::size_t TileLayerGroup::observeDrawables(mbgl::RenderPass pass,
|
||||
const OverscaledTileID& tileID,
|
||||
const std::function<void(const gfx::Drawable&)>&& f) const {
|
||||
std::size_t TileLayerGroup::visitDrawables(mbgl::RenderPass pass,
|
||||
const OverscaledTileID& tileID,
|
||||
const std::function<void(const gfx::Drawable&)>&& f) const {
|
||||
assert(impl->drawablesByTile.size() == impl->sortedDrawables.size());
|
||||
const auto range = impl->drawablesByTile.equal_range({pass, tileID});
|
||||
std::for_each(range.first, range.second, [&f](const auto& pair) { f(*pair.second); });
|
||||
|
||||
Reference in New Issue
Block a user