diff options
author | Lauren Budorick <lauren@mapbox.com> | 2017-06-19 14:27:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 14:27:43 -0700 |
commit | 87a70c47930d79017816b8ac7ae1bb06eb6446c9 (patch) | |
tree | 721d9c995573d1f7ce755a75f64aa088eb43a3c2 /src | |
parent | a33cad98557f2d15bfb578e4795b130d25a2def2 (diff) | |
download | qtlocation-mapboxgl-87a70c47930d79017816b8ac7ae1bb06eb6446c9.tar.gz |
[core] Enable property functions for line-width (#9250)
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/programs/attributes.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/programs/line_program.cpp | 14 | ||||
-rw-r--r-- | src/mbgl/programs/line_program.hpp | 19 | ||||
-rw-r--r-- | src/mbgl/programs/uniforms.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/buckets/line_bucket.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/data_driven_property_evaluator.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_line_layer.cpp | 15 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_line_layer.hpp | 14 | ||||
-rw-r--r-- | src/mbgl/renderer/paint_property_binder.hpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/painter.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/painters/painter_line.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/possibly_evaluated_property_value.hpp | 12 | ||||
-rw-r--r-- | src/mbgl/renderer/property_evaluation_parameters.hpp | 10 | ||||
-rw-r--r-- | src/mbgl/shaders/line.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/shaders/line_pattern.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/shaders/line_sdf.cpp | 59 | ||||
-rw-r--r-- | src/mbgl/style/layers/line_layer.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/style/layers/line_layer_properties.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/properties.hpp | 13 |
19 files changed, 171 insertions, 59 deletions
diff --git a/src/mbgl/programs/attributes.hpp b/src/mbgl/programs/attributes.hpp index a0b2b93e16..8f2751080f 100644 --- a/src/mbgl/programs/attributes.hpp +++ b/src/mbgl/programs/attributes.hpp @@ -96,6 +96,11 @@ struct a_width { using Type = gl::Attribute<float, 1>; }; +struct a_floorwidth { + static auto name() { return "a_floorwidth"; } + using Type = gl::Attribute<float, 1>; +}; + struct a_height { static auto name() { return "a_height"; } using Type = gl::Attribute<float, 1>; diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp index 86645588ca..db5c916d32 100644 --- a/src/mbgl/programs/line_program.cpp +++ b/src/mbgl/programs/line_program.cpp @@ -13,7 +13,7 @@ using namespace style; static_assert(sizeof(LineLayoutVertex) == 8, "expected LineLayoutVertex size"); template <class Values, class...Args> -Values makeValues(const LinePaintProperties::PossiblyEvaluated& properties, +Values makeValues(const RenderLinePaintProperties::PossiblyEvaluated& properties, const RenderTile& tile, const TransformState& state, const std::array<float, 2>& pixelsToGLUnits, @@ -25,7 +25,6 @@ Values makeValues(const LinePaintProperties::PossiblyEvaluated& properties, properties.get<LineTranslateAnchor>(), state) }, - uniforms::u_width::Value{ properties.get<LineWidth>() }, uniforms::u_ratio::Value{ 1.0f / tile.id.pixelsToTileUnits(1.0, state.getZoom()) }, uniforms::u_gl_units_to_pixels::Value{{{ 1.0f / pixelsToGLUnits[0], 1.0f / pixelsToGLUnits[1] }}}, std::forward<Args>(args)... @@ -33,7 +32,7 @@ Values makeValues(const LinePaintProperties::PossiblyEvaluated& properties, } LineProgram::UniformValues -LineProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties, +LineProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties, const RenderTile& tile, const TransformState& state, const std::array<float, 2>& pixelsToGLUnits) { @@ -46,17 +45,16 @@ LineProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& propert } LineSDFProgram::UniformValues -LineSDFProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties, +LineSDFProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties, float pixelRatio, const RenderTile& tile, const TransformState& state, const std::array<float, 2>& pixelsToGLUnits, const LinePatternPos& posA, const LinePatternPos& posB, - float dashLineWidth, float atlasWidth) { - const float widthA = posA.width * properties.get<LineDasharray>().fromScale * dashLineWidth; - const float widthB = posB.width * properties.get<LineDasharray>().toScale * dashLineWidth; + const float widthA = posA.width * properties.get<LineDasharray>().fromScale; + const float widthB = posB.width * properties.get<LineDasharray>().toScale; std::array<float, 2> scaleA {{ 1.0f / tile.id.pixelsToTileUnits(widthA, state.getIntegerZoom()), @@ -84,7 +82,7 @@ LineSDFProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& prop } LinePatternProgram::UniformValues -LinePatternProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties, +LinePatternProgram::uniformValues(const RenderLinePaintProperties::PossiblyEvaluated& properties, const RenderTile& tile, const TransformState& state, const std::array<float, 2>& pixelsToGLUnits, diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index fadd351026..ed4a09bf10 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -7,7 +7,7 @@ #include <mbgl/shaders/line_pattern.hpp> #include <mbgl/shaders/line_sdf.hpp> #include <mbgl/util/geometry.hpp> -#include <mbgl/style/layers/line_layer_properties.hpp> +#include <mbgl/renderer/layers/render_line_layer.hpp> #include <cmath> @@ -20,7 +20,6 @@ class ImagePosition; namespace uniforms { MBGL_DEFINE_UNIFORM_SCALAR(float, u_ratio); -MBGL_DEFINE_UNIFORM_SCALAR(float, u_width); MBGL_DEFINE_UNIFORM_SCALAR(float, u_tex_y_a); MBGL_DEFINE_UNIFORM_SCALAR(float, u_tex_y_b); MBGL_DEFINE_UNIFORM_SCALAR(float, u_sdfgamma); @@ -41,10 +40,9 @@ class LineProgram : public Program< LineLayoutAttributes, gl::Uniforms< uniforms::u_matrix, - uniforms::u_width, uniforms::u_ratio, uniforms::u_gl_units_to_pixels>, - style::LinePaintProperties> + RenderLinePaintProperties> { public: using Program::Program; @@ -91,7 +89,7 @@ public: */ static const int8_t extrudeScale = 63; - static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&, + static UniformValues uniformValues(const RenderLinePaintProperties::PossiblyEvaluated&, const RenderTile&, const TransformState&, const std::array<float, 2>& pixelsToGLUnits); @@ -103,7 +101,6 @@ class LinePatternProgram : public Program< LineLayoutAttributes, gl::Uniforms< uniforms::u_matrix, - uniforms::u_width, uniforms::u_ratio, uniforms::u_gl_units_to_pixels, uniforms::u_pattern_tl_a, @@ -115,12 +112,12 @@ class LinePatternProgram : public Program< uniforms::u_texsize, uniforms::u_fade, uniforms::u_image>, - style::LinePaintProperties> + RenderLinePaintProperties> { public: using Program::Program; - static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&, + static UniformValues uniformValues(const RenderLinePaintProperties::PossiblyEvaluated&, const RenderTile&, const TransformState&, const std::array<float, 2>& pixelsToGLUnits, @@ -135,7 +132,6 @@ class LineSDFProgram : public Program< LineLayoutAttributes, gl::Uniforms< uniforms::u_matrix, - uniforms::u_width, uniforms::u_ratio, uniforms::u_gl_units_to_pixels, uniforms::u_patternscale_a, @@ -145,19 +141,18 @@ class LineSDFProgram : public Program< uniforms::u_mix, uniforms::u_sdfgamma, uniforms::u_image>, - style::LinePaintProperties> + RenderLinePaintProperties> { public: using Program::Program; - static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&, + static UniformValues uniformValues(const RenderLinePaintProperties::PossiblyEvaluated&, float pixelRatio, const RenderTile&, const TransformState&, const std::array<float, 2>& pixelsToGLUnits, const LinePatternPos& posA, const LinePatternPos& posB, - float dashLineWidth, float atlasWidth); }; diff --git a/src/mbgl/programs/uniforms.hpp b/src/mbgl/programs/uniforms.hpp index bec8fbe9fb..f1b2c2fb54 100644 --- a/src/mbgl/programs/uniforms.hpp +++ b/src/mbgl/programs/uniforms.hpp @@ -27,6 +27,8 @@ MBGL_DEFINE_UNIFORM_SCALAR(float, u_halo_blur); MBGL_DEFINE_UNIFORM_SCALAR(Color, u_outline_color); MBGL_DEFINE_UNIFORM_SCALAR(float, u_height); MBGL_DEFINE_UNIFORM_SCALAR(float, u_base); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_width); +MBGL_DEFINE_UNIFORM_SCALAR(float, u_floorwidth); MBGL_DEFINE_UNIFORM_SCALAR(float, u_gapwidth); MBGL_DEFINE_UNIFORM_SCALAR(float, u_offset); MBGL_DEFINE_UNIFORM_SCALAR(Size, u_world); diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index ab9cfe9376..3af3cd63d3 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -480,7 +480,7 @@ static float get(const RenderLineLayer& layer, const std::map<std::string, LineP } float LineBucket::getLineWidth(const RenderLineLayer& layer) const { - float lineWidth = layer.evaluated.get<LineWidth>(); + float lineWidth = get<LineWidth>(layer, paintPropertyBinders); float gapWidth = get<LineGapWidth>(layer, paintPropertyBinders); if (gapWidth) { diff --git a/src/mbgl/renderer/data_driven_property_evaluator.hpp b/src/mbgl/renderer/data_driven_property_evaluator.hpp index 6406b3478b..79ecd0d495 100644 --- a/src/mbgl/renderer/data_driven_property_evaluator.hpp +++ b/src/mbgl/renderer/data_driven_property_evaluator.hpp @@ -24,12 +24,18 @@ public: } ResultType operator()(const style::CameraFunction<T>& function) const { - return ResultType(function.evaluate(parameters.z)); + if (!parameters.useIntegerZoom) { + return ResultType(function.evaluate(parameters.z)); + } else { + return ResultType(function.evaluate(floor(parameters.z))); + } } template <class Function> ResultType operator()(const Function& function) const { - return ResultType(function); + auto returnFunction = function; + returnFunction.useIntegerZoom = parameters.useIntegerZoom; + return ResultType(returnFunction); } private: diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index 076ee77aff..5998c1f2fb 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -24,16 +24,18 @@ void RenderLineLayer::transition(const TransitionParameters& parameters) { } void RenderLineLayer::evaluate(const PropertyEvaluationParameters& parameters) { - // for scaling dasharrays + style::Properties<LineFloorwidth>::Unevaluated extra; + extra.get<LineFloorwidth>() = unevaluated.get<style::LineWidth>(); + auto dashArrayParams = parameters; - dashArrayParams.z = std::floor(dashArrayParams.z); - dashLineWidth = unevaluated.evaluate<style::LineWidth>(dashArrayParams); + dashArrayParams.useIntegerZoom = true; - evaluated = unevaluated.evaluate(parameters); + evaluated = RenderLinePaintProperties::PossiblyEvaluated( + unevaluated.evaluate(parameters).concat(extra.evaluate(dashArrayParams))); passes = (evaluated.get<style::LineOpacity>().constantOr(1.0) > 0 && evaluated.get<style::LineColor>().constantOr(Color::black()).a > 0 - && evaluated.get<style::LineWidth>() > 0) + && evaluated.get<style::LineWidth>().constantOr(1.0) > 0) ? RenderPass::Translucent : RenderPass::None; } @@ -102,7 +104,8 @@ bool RenderLineLayer::queryIntersectsFeature( } float RenderLineLayer::getLineWidth(const GeometryTileFeature& feature, const float zoom) const { - float lineWidth = evaluated.get<style::LineWidth>(); + float lineWidth = evaluated.get<style::LineWidth>() + .evaluate(feature, zoom, style::LineWidth::defaultValue()); float gapWidth = evaluated.get<style::LineGapWidth>() .evaluate(feature, zoom, style::LineGapWidth::defaultValue()); if (gapWidth) { diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp index 04ba745533..77551b6b7c 100644 --- a/src/mbgl/renderer/layers/render_line_layer.hpp +++ b/src/mbgl/renderer/layers/render_line_layer.hpp @@ -3,9 +3,18 @@ #include <mbgl/renderer/render_layer.hpp> #include <mbgl/style/layers/line_layer_impl.hpp> #include <mbgl/style/layers/line_layer_properties.hpp> +#include <mbgl/programs/uniforms.hpp> namespace mbgl { +struct LineFloorwidth : style::DataDrivenPaintProperty<float, attributes::a_floorwidth, uniforms::u_floorwidth> { + static float defaultValue() { return 1; } +}; + +class RenderLinePaintProperties : public style::ConcatenateProperties< + style::LinePaintProperties::PropertyTypes, + TypeList<LineFloorwidth>>::Type {}; + class RenderLineLayer: public RenderLayer { public: RenderLineLayer(Immutable<style::LineLayer::Impl>); @@ -26,13 +35,10 @@ public: // Paint properties style::LinePaintProperties::Unevaluated unevaluated; - style::LinePaintProperties::PossiblyEvaluated evaluated; + RenderLinePaintProperties::PossiblyEvaluated evaluated; const style::LineLayer::Impl& impl() const; - // Special case - float dashLineWidth = 1; - private: float getLineWidth(const GeometryTileFeature&, const float) const; }; diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 8ac6ce8cf1..f78147fc87 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -217,7 +217,11 @@ public: } float interpolationFactor(float currentZoom) const override { - return util::interpolationFactor(1.0f, { rangeOfCoveringRanges.min.zoom, rangeOfCoveringRanges.max.zoom }, currentZoom); + if (function.useIntegerZoom) { + return util::interpolationFactor(1.0f, { rangeOfCoveringRanges.min.zoom, rangeOfCoveringRanges.max.zoom }, std::floor(currentZoom)); + } else { + return util::interpolationFactor(1.0f, { rangeOfCoveringRanges.min.zoom, rangeOfCoveringRanges.max.zoom }, currentZoom); + } } T uniformValue(const PossiblyEvaluatedPropertyValue<T>& currentValue) const override { diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index edec98047d..5a70243a54 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -328,7 +328,7 @@ void Painter::renderPass(PaintParameters& parameters, mat4 viewportMat; matrix::ortho(viewportMat, 0, size.width, size.height, 0, 0, 1); - const Properties<>::PossiblyEvaluated properties{}; + const Properties<>::PossiblyEvaluated properties; parameters.programs.extrusionTexture.draw( context, gl::Triangles(), gl::DepthMode::disabled(), gl::StencilMode::disabled(), diff --git a/src/mbgl/renderer/painters/painter_line.cpp b/src/mbgl/renderer/painters/painter_line.cpp index 49fee36925..58f4131d96 100644 --- a/src/mbgl/renderer/painters/painter_line.cpp +++ b/src/mbgl/renderer/painters/painter_line.cpp @@ -21,7 +21,7 @@ void Painter::renderLine(PaintParameters& parameters, return; } - const LinePaintProperties::PossiblyEvaluated& properties = layer.evaluated; + const RenderLinePaintProperties::PossiblyEvaluated& properties = layer.evaluated; auto draw = [&] (auto& program, auto&& uniformValues) { program.get(properties).draw( @@ -57,7 +57,6 @@ void Painter::renderLine(PaintParameters& parameters, pixelsToGLUnits, posA, posB, - layer.dashLineWidth, lineAtlas->getSize().width)); } else if (!properties.get<LinePattern>().from.empty()) { diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp index a0bcec2bf1..8a5dfbe4ea 100644 --- a/src/mbgl/renderer/possibly_evaluated_property_value.hpp +++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp @@ -19,7 +19,9 @@ private: public: PossiblyEvaluatedPropertyValue() = default; - PossiblyEvaluatedPropertyValue(Value v) : value(std::move(v)) {} + PossiblyEvaluatedPropertyValue(Value v, bool useIntegerZoom_ = false) + : value(std::move(v)), + useIntegerZoom(useIntegerZoom_) {} bool isConstant() const { return value.template is<T>(); @@ -48,10 +50,16 @@ public: return function.evaluate(feature, defaultValue); }, [&] (const style::CompositeFunction<T>& function) { - return function.evaluate(zoom, feature, defaultValue); + if (useIntegerZoom) { + return function.evaluate(floor(zoom), feature, defaultValue); + } else { + return function.evaluate(zoom, feature, defaultValue); + } } ); } + + bool useIntegerZoom; }; namespace util { diff --git a/src/mbgl/renderer/property_evaluation_parameters.hpp b/src/mbgl/renderer/property_evaluation_parameters.hpp index 39b663bdb9..da6a4a0892 100644 --- a/src/mbgl/renderer/property_evaluation_parameters.hpp +++ b/src/mbgl/renderer/property_evaluation_parameters.hpp @@ -11,20 +11,24 @@ public: : z(z_), now(Clock::time_point::max()), zoomHistory(), - defaultFadeDuration(0) {} + defaultFadeDuration(0), + useIntegerZoom(false) {} PropertyEvaluationParameters(ZoomHistory zoomHistory_, TimePoint now_, - Duration defaultFadeDuration_) + Duration defaultFadeDuration_, + bool useIntegerZoom_ = false) : z(zoomHistory_.lastZoom), now(std::move(now_)), zoomHistory(std::move(zoomHistory_)), - defaultFadeDuration(std::move(defaultFadeDuration_)) {} + defaultFadeDuration(std::move(defaultFadeDuration_)), + useIntegerZoom(useIntegerZoom_) {} float z; TimePoint now; ZoomHistory zoomHistory; Duration defaultFadeDuration; + bool useIntegerZoom; }; } // namespace mbgl diff --git a/src/mbgl/shaders/line.cpp b/src/mbgl/shaders/line.cpp index dce6046257..1eb92c4b71 100644 --- a/src/mbgl/shaders/line.cpp +++ b/src/mbgl/shaders/line.cpp @@ -26,7 +26,6 @@ attribute vec4 a_data; uniform mat4 u_matrix; uniform mediump float u_ratio; -uniform mediump float u_width; uniform vec2 u_gl_units_to_pixels; varying vec2 v_normal; @@ -72,6 +71,13 @@ attribute lowp vec2 a_offset; uniform lowp float u_offset; #endif +#ifndef HAS_UNIFORM_u_width +uniform lowp float a_width_t; +attribute mediump vec2 a_width; +#else +uniform mediump float u_width; +#endif + void main() { #ifndef HAS_UNIFORM_u_color @@ -104,6 +110,12 @@ void main() { lowp float offset = u_offset; #endif +#ifndef HAS_UNIFORM_u_width + mediump float width = unpack_mix_vec2(a_width, a_width_t); +#else + mediump float width = u_width; +#endif + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; @@ -119,11 +131,11 @@ void main() { // these transformations used to be applied in the JS and native code bases. // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; - float width = u_width / 2.0; + float halfwidth = width / 2.0; offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); - float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; + float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. diff --git a/src/mbgl/shaders/line_pattern.cpp b/src/mbgl/shaders/line_pattern.cpp index ded4c76825..222042a13c 100644 --- a/src/mbgl/shaders/line_pattern.cpp +++ b/src/mbgl/shaders/line_pattern.cpp @@ -28,7 +28,6 @@ attribute vec4 a_data; uniform mat4 u_matrix; uniform mediump float u_ratio; -uniform mediump float u_width; uniform vec2 u_gl_units_to_pixels; varying vec2 v_normal; @@ -67,6 +66,13 @@ attribute mediump vec2 a_gapwidth; uniform mediump float u_gapwidth; #endif +#ifndef HAS_UNIFORM_u_width +uniform lowp float a_width_t; +attribute mediump vec2 a_width; +#else +uniform mediump float u_width; +#endif + void main() { #ifndef HAS_UNIFORM_u_blur @@ -93,6 +99,12 @@ void main() { mediump float gapwidth = u_gapwidth; #endif +#ifndef HAS_UNIFORM_u_width + mediump float width = unpack_mix_vec2(a_width, a_width_t); +#else + mediump float width = u_width; +#endif + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; @@ -108,11 +120,11 @@ void main() { // these transformations used to be applied in the JS and native code bases. // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; - float width = u_width / 2.0; + float halfwidth = width / 2.0; offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); - float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; + float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. diff --git a/src/mbgl/shaders/line_sdf.cpp b/src/mbgl/shaders/line_sdf.cpp index b37bf688d4..168f4ca98d 100644 --- a/src/mbgl/shaders/line_sdf.cpp +++ b/src/mbgl/shaders/line_sdf.cpp @@ -33,7 +33,6 @@ uniform float u_tex_y_a; uniform vec2 u_patternscale_b; uniform float u_tex_y_b; uniform vec2 u_gl_units_to_pixels; -uniform mediump float u_width; varying vec2 v_normal; varying vec2 v_width2; @@ -80,6 +79,22 @@ attribute lowp vec2 a_offset; uniform lowp float u_offset; #endif +#ifndef HAS_UNIFORM_u_width +uniform lowp float a_width_t; +attribute mediump vec2 a_width; +varying mediump float width; +#else +uniform mediump float u_width; +#endif + +#ifndef HAS_UNIFORM_u_floorwidth +uniform lowp float a_floorwidth_t; +attribute lowp vec2 a_floorwidth; +varying lowp float floorwidth; +#else +uniform lowp float u_floorwidth; +#endif + void main() { #ifndef HAS_UNIFORM_u_color @@ -112,6 +127,18 @@ void main() { lowp float offset = u_offset; #endif +#ifndef HAS_UNIFORM_u_width + width = unpack_mix_vec2(a_width, a_width_t); +#else + mediump float width = u_width; +#endif + +#ifndef HAS_UNIFORM_u_floorwidth + floorwidth = unpack_mix_vec2(a_floorwidth, a_floorwidth_t); +#else + lowp float floorwidth = u_floorwidth; +#endif + vec2 a_extrude = a_data.xy - 128.0; float a_direction = mod(a_data.z, 4.0) - 1.0; float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE; @@ -127,11 +154,11 @@ void main() { // these transformations used to be applied in the JS and native code bases. // moved them into the shader for clarity and simplicity. gapwidth = gapwidth / 2.0; - float width = u_width / 2.0; + float halfwidth = width / 2.0; offset = -1.0 * offset; float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0); - float outset = gapwidth + width * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; + float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + ANTIALIASING; // Scale the extrusion vector down to a normal and then up by the line width // of this vertex. @@ -156,8 +183,8 @@ void main() { float extrude_length_with_perspective = length(projected_extrude.xy / gl_Position.w * u_gl_units_to_pixels); v_gamma_scale = extrude_length_without_perspective / extrude_length_with_perspective; - v_tex_a = vec2(a_linesofar * u_patternscale_a.x, normal.y * u_patternscale_a.y + u_tex_y_a); - v_tex_b = vec2(a_linesofar * u_patternscale_b.x, normal.y * u_patternscale_b.y + u_tex_y_b); + v_tex_a = vec2(a_linesofar * u_patternscale_a.x / floorwidth, normal.y * u_patternscale_a.y + u_tex_y_a); + v_tex_b = vec2(a_linesofar * u_patternscale_b.x / floorwidth, normal.y * u_patternscale_b.y + u_tex_y_b); v_width2 = vec2(outset, inset); } @@ -194,6 +221,18 @@ varying lowp float opacity; uniform lowp float u_opacity; #endif +#ifndef HAS_UNIFORM_u_width +varying mediump float width; +#else +uniform mediump float u_width; +#endif + +#ifndef HAS_UNIFORM_u_floorwidth +varying lowp float floorwidth; +#else +uniform lowp float u_floorwidth; +#endif + void main() { #ifdef HAS_UNIFORM_u_color @@ -208,6 +247,14 @@ void main() { lowp float opacity = u_opacity; #endif +#ifdef HAS_UNIFORM_u_width + mediump float width = u_width; +#endif + +#ifdef HAS_UNIFORM_u_floorwidth + lowp float floorwidth = u_floorwidth; +#endif + // Calculate the distance of the pixel from the line in pixels. float dist = length(v_normal) * v_width2.s; @@ -220,7 +267,7 @@ void main() { float sdfdist_a = texture2D(u_image, v_tex_a).a; float sdfdist_b = texture2D(u_image, v_tex_b).a; float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix); - alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist); + alpha *= smoothstep(0.5 - u_sdfgamma / floorwidth, 0.5 + u_sdfgamma / floorwidth, sdfdist); gl_FragColor = color * (alpha * opacity); diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index cf3f81f613..6fbdf19568 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -267,15 +267,15 @@ TransitionOptions LineLayer::getLineTranslateAnchorTransition() const { return impl().paint.template get<LineTranslateAnchor>().options; } -PropertyValue<float> LineLayer::getDefaultLineWidth() { +DataDrivenPropertyValue<float> LineLayer::getDefaultLineWidth() { return { 1 }; } -PropertyValue<float> LineLayer::getLineWidth() const { +DataDrivenPropertyValue<float> LineLayer::getLineWidth() const { return impl().paint.template get<LineWidth>().value; } -void LineLayer::setLineWidth(PropertyValue<float> value) { +void LineLayer::setLineWidth(DataDrivenPropertyValue<float> value) { if (value == getLineWidth()) return; auto impl_ = mutableImpl(); diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp index 7930ed113b..b2c7f3199c 100644 --- a/src/mbgl/style/layers/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -48,7 +48,7 @@ struct LineTranslateAnchor : PaintProperty<TranslateAnchorType> { static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; } }; -struct LineWidth : PaintProperty<float> { +struct LineWidth : DataDrivenPaintProperty<float, attributes::a_width, uniforms::u_width> { static float defaultValue() { return 1; } }; diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp index 24ac030541..e42beac97a 100644 --- a/src/mbgl/style/properties.hpp +++ b/src/mbgl/style/properties.hpp @@ -130,7 +130,10 @@ public: class PossiblyEvaluated : public Tuple<PossiblyEvaluatedTypes> { public: - using Tuple<PossiblyEvaluatedTypes>::Tuple; + template <class... Us> + PossiblyEvaluated(Us&&... us) + : Tuple<PossiblyEvaluatedTypes>(std::forward<Us>(us)...) { + } template <class T> static T evaluate(float, const GeometryTileFeature&, const T& t, const T&) { @@ -214,5 +217,13 @@ public: }; }; +template <class...> +struct ConcatenateProperties; + +template <class... As, class... Bs> +struct ConcatenateProperties<TypeList<As...>, TypeList<Bs...>> { + using Type = Properties<As..., Bs...>; +}; + } // namespace style } // namespace mbgl |