summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2015-02-02 17:52:44 -0800
committerAnsis Brammanis <brammanis@gmail.com>2015-02-02 17:57:12 -0800
commit6f5c6b58b48e762ed7aced6c4486f1060d0e34f1 (patch)
tree50c3f8921542d6596292cc1f22b2c76c442412e3 /src
parent322f46a5db6d44633ffc7a45140e163f03365371 (diff)
downloadqtlocation-mapboxgl-6f5c6b58b48e762ed7aced6c4486f1060d0e34f1.tar.gz
use faded pattern functions for dasharrays
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/renderer/painter_line.cpp39
-rw-r--r--src/mbgl/style/fadedfunction_properties.cpp1
-rw-r--r--src/mbgl/style/fadedfunction_properties.hpp4
-rw-r--r--src/mbgl/style/property_value.hpp2
-rw-r--r--src/mbgl/style/style_parser.cpp20
-rw-r--r--src/mbgl/style/style_properties.hpp2
6 files changed, 31 insertions, 37 deletions
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index b26f1cfa55..149683cbcd 100644
--- a/src/mbgl/renderer/painter_line.cpp
+++ b/src/mbgl/renderer/painter_line.cpp
@@ -70,11 +70,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
bucket.drawPoints(*linejoinShader);
}
- float duration = 300 * 1_millisecond;
- const float fraction = std::fmod(float(state.getZoom()), 1.0f);
- float t = std::min((util::now() - lastIntegerZoomTime) / duration, 1.0f);
-
- if (properties.dash_array.size()) {
+ if (properties.dash_array.low.size()) {
useProgram(linesdfShader->program);
@@ -85,30 +81,23 @@ void Painter::renderLine(LineBucket& bucket, util::ptr<StyleLayer> layer_desc, c
linesdfShader->u_blur = blur;
linesdfShader->u_color = color;
- LinePatternPos pos = lineAtlas.getDashPosition(properties.dash_array, bucket.properties.cap == CapType::Round);
+ LinePatternPos posA = lineAtlas.getDashPosition(properties.dash_array.low, bucket.properties.cap == CapType::Round);
+ LinePatternPos posB = lineAtlas.getDashPosition(properties.dash_array.high, bucket.properties.cap == CapType::Round);
lineAtlas.bind();
float patternratio = std::pow(2.0, std::floor(std::log2(state.getScale())) - id.z) / 8.0;
- float scaleX = patternratio / pos.width / properties.dash_line_width;
- float scaleY = -pos.height / 2.0;
-
- float mix;
- if (state.getZoom() > lastIntegerZoom) {
- // zooming in
- mix = fraction + (1.0f - fraction) * t;
- scaleX /= 2.0;
- } else {
- // zooming out
- mix = fraction - fraction * t;
- }
-
- linesdfShader->u_patternscale_a = {{ scaleX, scaleY }};
- linesdfShader->u_tex_y_a = pos.y;
- linesdfShader->u_patternscale_b = {{ scaleX * 2.0f, scaleY }};
- linesdfShader->u_tex_y_b = pos.y;
+ float scaleXA = patternratio / posA.width / properties.dash_line_width / properties.dash_array.lowScale;
+ float scaleYA = -posA.height / 2.0;
+ float scaleXB = patternratio / posB.width / properties.dash_line_width / properties.dash_array.highScale;
+ float scaleYB = -posB.height / 2.0;
+
+ linesdfShader->u_patternscale_a = {{ scaleXA, scaleYA }};
+ linesdfShader->u_tex_y_a = posA.y;
+ linesdfShader->u_patternscale_b = {{ scaleXB, scaleYB }};
+ linesdfShader->u_tex_y_b = posB.y;
linesdfShader->u_image = 0;
- linesdfShader->u_sdfgamma = lineAtlas.width / (properties.dash_line_width * pos.width * 256.0 * state.getPixelRatio()) / 2;
- linesdfShader->u_mix = mix;
+ linesdfShader->u_sdfgamma = lineAtlas.width / (properties.dash_line_width * std::min(posA.width, posB.width) * 256.0 * state.getPixelRatio()) / 2;
+ linesdfShader->u_mix = properties.dash_array.t;
bucket.drawLineSDF(*linesdfShader);
diff --git a/src/mbgl/style/fadedfunction_properties.cpp b/src/mbgl/style/fadedfunction_properties.cpp
index 485bffd26c..8ac4f3be42 100644
--- a/src/mbgl/style/fadedfunction_properties.cpp
+++ b/src/mbgl/style/fadedfunction_properties.cpp
@@ -47,5 +47,6 @@ T FadedStopsFunction<T>::evaluate(float z, const ZoomHistory &zh) const {
}
template Faded<std::string> FadedStopsFunction<Faded<std::string>>::evaluate(float z, const ZoomHistory &zoomHistory) const;
+template Faded<std::vector<float>> FadedStopsFunction<Faded<std::vector<float>>>::evaluate(float z, const ZoomHistory &zoomHistory) const;
}
diff --git a/src/mbgl/style/fadedfunction_properties.hpp b/src/mbgl/style/fadedfunction_properties.hpp
index 4d49dafb46..23b4411369 100644
--- a/src/mbgl/style/fadedfunction_properties.hpp
+++ b/src/mbgl/style/fadedfunction_properties.hpp
@@ -10,8 +10,8 @@ namespace mbgl {
template <typename T>
struct FadedStopsFunction {
inline FadedStopsFunction(const std::vector<std::pair<float, T>> &values_, timestamp duration_) : values(values_), duration(duration_) {}
- inline FadedStopsFunction(T &value) : values({{ 0, value }}), duration(0.0f) {}
- inline FadedStopsFunction() : values(), duration(0.0f) {}
+ inline FadedStopsFunction(T &value) : values({{ 0, value }}), duration(300_milliseconds) {}
+ inline FadedStopsFunction() : values(), duration(300_milliseconds) {}
T evaluate(float z, const ZoomHistory &zoomHistory) const;
private:
diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp
index 7b6c38e754..8dcb8d7371 100644
--- a/src/mbgl/style/property_value.hpp
+++ b/src/mbgl/style/property_value.hpp
@@ -17,7 +17,7 @@ typedef mapbox::util::variant<
Function<bool>,
Function<float>,
Function<Color>,
- Function<std::vector<float>>,
+ FadedStopsFunction<Faded<std::vector<float>>>,
FadedStopsFunction<Faded<std::string>>
> PropertyValue;
diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp
index 5dcf3b114c..454e786573 100644
--- a/src/mbgl/style/style_parser.cpp
+++ b/src/mbgl/style/style_parser.cpp
@@ -258,9 +258,11 @@ Color StyleParser::parseFunctionArgument(JSVal value) {
}
template <>
-std::vector<float> StyleParser::parseFunctionArgument(JSVal value) {
+Faded<std::vector<float>> StyleParser::parseFunctionArgument(JSVal value) {
+ Faded<std::vector<float>> parsed;
JSVal rvalue = replaceConstant(value);
- return std::get<1>(parseFloatArray(rvalue));
+ parsed.low = std::get<1>(parseFloatArray(rvalue));
+ return parsed;
}
template <>
@@ -469,15 +471,17 @@ template<> std::tuple<bool, Function<Color>> StyleParser::parseProperty(JSVal va
}
}
-template<> std::tuple<bool, Function<std::vector<float>>> StyleParser::parseProperty(JSVal value, const char *property_name) {
+template<> std::tuple<bool, FadedStopsFunction<Faded<std::vector<float>>>> StyleParser::parseProperty(JSVal value, const char *property_name) {
if (value.IsObject()) {
- return parseFunction<std::vector<float>>(value);
+ return parseFadedStopsFunction<Faded<std::vector<float>>>(value);
} else if (value.IsArray()) {
- std::tuple<bool, std::vector<float>> parsed = parseFloatArray(value);
- return std::tuple<bool, Function<std::vector<float>>> { std::get<0>(parsed), ConstantFunction<std::vector<float>>(std::get<1>(parsed)) };
+ Faded<std::vector<float>> parsed;
+ std::tuple<bool, std::vector<float>> floatarray = parseFloatArray(value);
+ parsed.low = std::get<1>(floatarray);
+ return std::tuple<bool, FadedStopsFunction<Faded<std::vector<float>>>> { std::get<0>(floatarray), parsed };
} else {
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers, or a number array function", property_name);
- return std::tuple<bool, Function<std::vector<float>>> { false, ConstantFunction<std::vector<float>>(std::vector<float>()) };
+ return std::tuple<bool, FadedStopsFunction<Faded<std::vector<float>>>> { false, {} };
}
}
@@ -652,7 +656,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) {
parseOptionalProperty<PropertyTransition>("line-gap-width-transition", Key::LineGapWidth, klass, value);
parseOptionalProperty<Function<float>>("line-blur", Key::LineBlur, klass, value);
parseOptionalProperty<PropertyTransition>("line-blur-transition", Key::LineBlur, klass, value);
- parseOptionalProperty<Function<std::vector<float>>>("line-dasharray", Key::LineDashArray, klass, value);
+ parseOptionalProperty<FadedStopsFunction<Faded<std::vector<float>>>>("line-dasharray", Key::LineDashArray, klass, value);
parseOptionalProperty<FadedStopsFunction<Faded<std::string>>>("line-image", Key::LineImage, klass, value);
parseOptionalProperty<Function<float>>("icon-opacity", Key::IconOpacity, klass, value);
diff --git a/src/mbgl/style/style_properties.hpp b/src/mbgl/style/style_properties.hpp
index 1784210102..fd55cb0bb2 100644
--- a/src/mbgl/style/style_properties.hpp
+++ b/src/mbgl/style/style_properties.hpp
@@ -37,7 +37,7 @@ struct LineProperties {
float width = 1;
float gap_width = 0;
float blur = 0;
- std::vector<float> dash_array;
+ Faded<std::vector<float>> dash_array;
float dash_line_width = 1;
Faded<std::string> image;