Tweak layer depth distribution (#3738)

This commit is contained in:
Adrian Cojocaru
2025-08-28 17:42:34 +03:00
committed by GitHub
parent 426e519665
commit 2a2bce8d4d
4 changed files with 58 additions and 5 deletions

View File

@@ -130,7 +130,7 @@ public:
#if MLN_RENDER_BACKEND_OPENGL
static constexpr float depthEpsilon = 1.0f / (1 << 16);
#else
static constexpr float depthEpsilon = 1.0f / (1 << 12);
static constexpr float depthEpsilon = 1.0f / (1 << 11);
#endif
static constexpr int maxStencilValue = 255;

View File

@@ -49,7 +49,7 @@ ShaderProgram::ShaderProgram(shaders::BuiltIn shaderID,
defineStr += "#define USE_SURFACE_TRANSFORM";
}
observer.onPreCompileShader(shaderID, gfx::Backend::Type::Metal, defineStr);
observer.onPreCompileShader(shaderID, gfx::Backend::Type::Vulkan, defineStr);
constexpr auto targetClientVersion = glslang::EShTargetVulkan_1_0;
constexpr auto targetLanguageVersion = glslang::EShTargetSpv_1_0;
@@ -61,8 +61,9 @@ ShaderProgram::ShaderProgram(shaders::BuiltIn shaderID,
glslang::TShader glslShader(language);
const auto preamble = defineStr + "\n" + prelude;
const char* shaderData = data.data();
const int shaderDataSize = static_cast<int>(data.size());
const std::string shaderStr = std::string("#version ") + std::to_string(defaultVersion) + "\n" + data.data();
const char* shaderData = shaderStr.data();
const int shaderDataSize = static_cast<int>(shaderStr.size());
glslShader.setPreamble(preamble.c_str());
glslShader.setStringsWithLengths(&shaderData, &shaderDataSize, 1);
@@ -115,7 +116,7 @@ ShaderProgram::ShaderProgram(shaders::BuiltIn shaderID,
backend.setDebugName(vertexShader.get(), shaderName + ".vert");
backend.setDebugName(fragmentShader.get(), shaderName + ".frag");
observer.onPostCompileShader(shaderID, gfx::Backend::Type::Metal, defineStr);
observer.onPostCompileShader(shaderID, gfx::Backend::Type::Vulkan, defineStr);
}
ShaderProgram::~ShaderProgram() noexcept {

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -25,6 +25,7 @@
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/sources/custom_geometry_source.hpp>
@@ -1968,3 +1969,54 @@ TEST(BackgroundLayer, StyleUpdateZoomDependency) {
0.0006,
0.1);
}
TEST(Map, LineLayerDepthDistribution) {
MapTest<> test;
test.map.getStyle().loadJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.jumpTo(CameraOptions().withZoom(0.0).withPitch(45.0));
auto backgroundLayer = std::make_unique<BackgroundLayer>("Background");
backgroundLayer->setBackgroundColor(Color(1.0f, 1.0f, 0.0f, 1.0f));
test.map.getStyle().addLayer(std::move(backgroundLayer));
constexpr uint32_t layerCount = 1 << 11;
const std::vector<Color> colors = {Color::red(), Color::green(), Color::blue()};
const auto& bounds = test.map.latLngBoundsForCamera(test.map.getCameraOptions());
const auto getSource = [&](uint32_t index) {
FeatureCollection features;
mapbox::geojson::line_string geo;
double y = (bounds.north() - bounds.south()) * 0.95 / layerCount * (index + 1) / 2.0;
double x = (bounds.east() - bounds.west()) * 0.95 / layerCount * (index + 1) / 2.0;
geo.emplace_back(-x, y);
geo.emplace_back(x, y);
geo.emplace_back(x, -y);
geo.emplace_back(-x, -y);
geo.emplace_back(-x, y);
features.emplace_back(geo);
auto source = std::make_unique<GeoJSONSource>("GeoJSONSource_" + std::to_string(index));
source->setGeoJSON(features);
return source;
};
for (uint32_t i = 0; i < layerCount; ++i) {
// add one source per layer
test.map.getStyle().addSource(getSource(i));
auto layer = std::make_unique<LineLayer>("LineLayer" + std::to_string(i), "GeoJSONSource_" + std::to_string(i));
layer->setLineColor(colors[i % colors.size()]);
test.map.getStyle().addLayer(std::move(layer));
}
test::checkImage(
"test/fixtures/map/layer_depth_distribution/line", test.frontend.render(test.map).image, 0.0006, 0.1);
}