diff --git a/src/mbgl/renderer/paint_parameters.hpp b/src/mbgl/renderer/paint_parameters.hpp index 4f4be3b2c..9a0c94c67 100644 --- a/src/mbgl/renderer/paint_parameters.hpp +++ b/src/mbgl/renderer/paint_parameters.hpp @@ -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; diff --git a/src/mbgl/shaders/vulkan/shader_program.cpp b/src/mbgl/shaders/vulkan/shader_program.cpp index 15207646f..04d99d6e5 100644 --- a/src/mbgl/shaders/vulkan/shader_program.cpp +++ b/src/mbgl/shaders/vulkan/shader_program.cpp @@ -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(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(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 { diff --git a/test/fixtures/map/layer_depth_distribution/line/expected.png b/test/fixtures/map/layer_depth_distribution/line/expected.png new file mode 100644 index 000000000..b599bb565 Binary files /dev/null and b/test/fixtures/map/layer_depth_distribution/line/expected.png differ diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 342f4fb94..a44273b13 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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("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 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_" + 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" + 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); +}