Further stencil optimizations (#1750)

Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Tim Sylvester
2023-10-11 16:25:02 -07:00
committed by GitHub
parent ce0096aab0
commit 6a8be9a221
10 changed files with 292 additions and 213 deletions

View File

@@ -21,6 +21,7 @@
#include <mbgl/style/image.hpp>
#include <mbgl/style/image_impl.hpp>
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/sources/custom_geometry_source.hpp>
@@ -1600,3 +1601,40 @@ TEST(Map, ObserveShaderRegistration) {
test.frontend.render(test.map);
EXPECT_EQ(observedRegistry, false);
}
TEST(Map, StencilOverflow) {
MapTest<> test;
const auto& backend = test.frontend.getBackend();
gfx::BackendScope scope{*backend};
auto& style = test.map.getStyle();
style.loadJSON("{}");
// Create a tile source with small tiles that produces enough tiles to
// exceed the stencil ID limit and causes a clearing of the stencil buffer.
CustomGeometrySource::Options options;
options.tileOptions.tileSize = util::tileSize_I / 32;
options.fetchTileFunction = [&](const CanonicalTileID& tileID) {
if (auto* customSrc = static_cast<CustomGeometrySource*>(style.getSource("custom"))) {
customSrc->setTileData(tileID, {});
}
};
style.addSource(std::make_unique<CustomGeometrySource>("custom", std::move(options)));
style.addLayer(std::make_unique<style::FillLayer>("fill", "custom"));
test.map.jumpTo(CameraOptions().withZoom(5));
test.frontend.render(test.map);
// In drawable builds, no drawables are built because no bucket/tiledata is available.
#if !MLN_DRAWABLE_RENDERER
// TODO: Collect stats on Metal context
#if MLN_RENDER_BACKEND_OPENGL
const auto& context = static_cast<const gl::Context&>(backend->getContext());
ASSERT_LT(0, context.renderingStats().stencilClears);
#endif // MLN_RENDER_BACKEND_OPENGL
#endif // !MLN_DRAWABLE_RENDERER
// TODO: confirm that the stencil masking actually worked
}