From d532824aec25e20efccb80860b990db0b85780ac Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 14:46:48 -0800 Subject: implement functions for patterns It introduces a new function type, FadedStopsFunction, that transitions between the stops values instead of interpolating between them. --- src/mbgl/renderer/painter.cpp | 6 +- src/mbgl/renderer/painter_fill.cpp | 42 +++++---- src/mbgl/shader/pattern.fragment.glsl | 17 ++-- src/mbgl/shader/pattern.vertex.glsl | 9 +- src/mbgl/shader/pattern_shader.hpp | 9 +- src/mbgl/style/fadedfunction_properties.cpp | 51 +++++++++++ src/mbgl/style/fadedfunction_properties.hpp | 24 +++++ src/mbgl/style/property_value.hpp | 4 +- src/mbgl/style/style.cpp | 4 +- src/mbgl/style/style.hpp | 2 + src/mbgl/style/style_layer.cpp | 135 ++++++++++++++-------------- src/mbgl/style/style_layer.hpp | 9 +- src/mbgl/style/style_layer_group.cpp | 4 +- src/mbgl/style/style_layer_group.hpp | 2 +- src/mbgl/style/style_parser.cpp | 120 +++++++++++++++++++------ src/mbgl/style/style_parser.hpp | 4 + src/mbgl/style/style_properties.hpp | 4 +- src/mbgl/style/types.hpp | 10 +++ src/mbgl/style/zoom_history.hpp | 39 ++++++++ 19 files changed, 353 insertions(+), 142 deletions(-) create mode 100644 src/mbgl/style/fadedfunction_properties.cpp create mode 100644 src/mbgl/style/fadedfunction_properties.hpp create mode 100644 src/mbgl/style/zoom_history.hpp (limited to 'src') diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 0fb99826c6..448b380743 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -385,8 +385,8 @@ void Painter::renderBackground(util::ptr layer_desc) { useProgram(patternShader->program); patternShader->u_matrix = identityMatrix; - patternShader->u_pattern_tl = imagePos.tl; - patternShader->u_pattern_br = imagePos.br; + patternShader->u_pattern_tl_a = imagePos.tl; + patternShader->u_pattern_br_a = imagePos.br; patternShader->u_mix = zoomFraction; patternShader->u_opacity = properties.opacity; @@ -408,7 +408,7 @@ void Painter::renderBackground(util::ptr layer_desc) { matrix::scale(matrix, matrix, scale * state.getWidth() / 2, -scale * state.getHeight() / 2); - patternShader->u_patternmatrix = matrix; + patternShader->u_patternmatrix_a = matrix; backgroundBuffer.bind(); patternShader->bind(0); diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 5e8f46d340..10d4aa3320 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -33,7 +33,7 @@ void Painter::renderFill(FillBucket& bucket, util::ptr layer_desc, c stroke_color[3] *= properties.opacity; } - const bool pattern = properties.image.size(); + const bool pattern = properties.image.low.size(); bool outline = properties.antialias && !pattern && properties.stroke_color != properties.fill_color; bool fringeline = properties.antialias && !pattern && properties.stroke_color == properties.fill_color; @@ -59,34 +59,32 @@ void Painter::renderFill(FillBucket& bucket, util::ptr layer_desc, c if (pattern) { // Image fill. if (pass == RenderPass::Translucent) { - const SpriteAtlasPosition pos = spriteAtlas.getPosition(properties.image, true); + const SpriteAtlasPosition posA = spriteAtlas.getPosition(properties.image.low, true); + const SpriteAtlasPosition posB = spriteAtlas.getPosition(properties.image.high, true); float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z); - float mix; - 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 (state.getZoom() > lastIntegerZoom) { - // zooming in - mix = fraction + (1.0f - fraction) * t; - factor *= 2.0; - } else { - // zooming out - mix = fraction - fraction * t; - } - - mat3 patternMatrix; - matrix::identity(patternMatrix); - matrix::scale(patternMatrix, patternMatrix, 1.0f / (pos.size[0] * factor), 1.0f / (pos.size[1] * factor)); + mat3 patternMatrixA; + matrix::identity(patternMatrixA); + matrix::scale(patternMatrixA, patternMatrixA, + 1.0f / (posA.size[0] * factor * properties.image.lowScale), + 1.0f / (posA.size[1] * factor * properties.image.lowScale)); + mat3 patternMatrixB; + matrix::identity(patternMatrixB); + matrix::scale(patternMatrixB, patternMatrixB, + 1.0f / (posB.size[0] * factor * properties.image.highScale), + 1.0f / (posB.size[1] * factor * properties.image.highScale)); useProgram(patternShader->program); patternShader->u_matrix = vtxMatrix; - patternShader->u_pattern_tl = pos.tl; - patternShader->u_pattern_br = pos.br; + patternShader->u_pattern_tl_a = posA.tl; + patternShader->u_pattern_br_a = posA.br; + patternShader->u_pattern_tl_b = posB.tl; + patternShader->u_pattern_br_b = posB.br; patternShader->u_opacity = properties.opacity; patternShader->u_image = 0; - patternShader->u_mix = mix; - patternShader->u_patternmatrix = patternMatrix; + patternShader->u_mix = properties.image.t; + patternShader->u_patternmatrix_a = patternMatrixA; + patternShader->u_patternmatrix_b = patternMatrixB; MBGL_CHECK_ERROR(glActiveTexture(GL_TEXTURE0)); spriteAtlas.bind(true); diff --git a/src/mbgl/shader/pattern.fragment.glsl b/src/mbgl/shader/pattern.fragment.glsl index ba6aed3023..a28a52ce36 100644 --- a/src/mbgl/shader/pattern.fragment.glsl +++ b/src/mbgl/shader/pattern.fragment.glsl @@ -1,20 +1,23 @@ uniform float u_opacity; -uniform vec2 u_pattern_tl; -uniform vec2 u_pattern_br; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; uniform float u_mix; uniform sampler2D u_image; -varying vec2 v_pos; +varying vec2 v_pos_a; +varying vec2 v_pos_b; void main() { - vec2 imagecoord = mod(v_pos, 1.0); - vec2 pos = mix(u_pattern_tl, u_pattern_br, imagecoord); + vec2 imagecoord = mod(v_pos_a, 1.0); + vec2 pos = mix(u_pattern_tl_a, u_pattern_br_a, imagecoord); vec4 color1 = texture2D(u_image, pos); - vec2 imagecoord2 = mod(imagecoord * 2.0, 1.0); - vec2 pos2 = mix(u_pattern_tl, u_pattern_br, imagecoord2); + vec2 imagecoord_b = mod(v_pos_b, 1.0); + vec2 pos2 = mix(u_pattern_tl_b, u_pattern_br_b, imagecoord_b); vec4 color2 = texture2D(u_image, pos2); gl_FragColor = mix(color1, color2, u_mix) * u_opacity; diff --git a/src/mbgl/shader/pattern.vertex.glsl b/src/mbgl/shader/pattern.vertex.glsl index f2de884ead..dff4469d2b 100644 --- a/src/mbgl/shader/pattern.vertex.glsl +++ b/src/mbgl/shader/pattern.vertex.glsl @@ -1,11 +1,14 @@ uniform mat4 u_matrix; -uniform mat3 u_patternmatrix; +uniform mat3 u_patternmatrix_a; +uniform mat3 u_patternmatrix_b; attribute vec2 a_pos; -varying vec2 v_pos; +varying vec2 v_pos_a; +varying vec2 v_pos_b; void main() { gl_Position = u_matrix * vec4(a_pos, 0, 1); - v_pos = (u_patternmatrix * vec3(a_pos, 1)).xy; + v_pos_a = (u_patternmatrix_a * vec3(a_pos, 1)).xy; + v_pos_b = (u_patternmatrix_b * vec3(a_pos, 1)).xy; } diff --git a/src/mbgl/shader/pattern_shader.hpp b/src/mbgl/shader/pattern_shader.hpp index 9fabd8e18a..9fc8dcfa01 100644 --- a/src/mbgl/shader/pattern_shader.hpp +++ b/src/mbgl/shader/pattern_shader.hpp @@ -13,12 +13,15 @@ public: void bind(char *offset); UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform> u_pattern_tl = {"u_pattern_tl", *this}; - Uniform> u_pattern_br = {"u_pattern_br", *this}; + Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; + Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; + Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; + Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; Uniform u_opacity = {"u_opacity", *this}; Uniform u_mix = {"u_mix", *this}; Uniform u_image = {"u_image", *this}; - UniformMatrix<3> u_patternmatrix = {"u_patternmatrix", *this}; + UniformMatrix<3> u_patternmatrix_a = {"u_patternmatrix_a", *this}; + UniformMatrix<3> u_patternmatrix_b = {"u_patternmatrix_b", *this}; private: int32_t a_pos = -1; diff --git a/src/mbgl/style/fadedfunction_properties.cpp b/src/mbgl/style/fadedfunction_properties.cpp new file mode 100644 index 0000000000..485bffd26c --- /dev/null +++ b/src/mbgl/style/fadedfunction_properties.cpp @@ -0,0 +1,51 @@ +#include +#include + +#include + +namespace mbgl { + +template +uint32_t getBiggestStopLessThan(std::vector> stops, float z) { + for (uint32_t i = 0; i < stops.size(); i++) { + if (stops[i].first > z) { + return i == 0 ? i : i - 1; + } + } + return stops.size() - 1; +} + +template +T FadedStopsFunction::evaluate(float z, const ZoomHistory &zh) const { + T result; + + float fraction = std::fmod(z, 1.0f); + float tDiff = (util::now() - zh.lastIntegerZoomTime) / 1_millisecond; + float fDuration = duration / 1_millisecond; + float t = std::min(tDiff / fDuration, 1.0f); + float scale = 1.0f; + uint32_t low, high; + + if (z > zh.lastIntegerZoom) { + result.t = fraction + (1.0f - fraction) * t; + scale *= 2.0f; + low = getBiggestStopLessThan(values, z - 1.0f); + high = getBiggestStopLessThan(values, z); + + } else { + result.t = fraction - fraction * t; + low = getBiggestStopLessThan(values, z); + high = getBiggestStopLessThan(values, z + 1.0f); + } + + + result.low = values[low].second.low; + result.high = values[high].second.low; + result.lowScale = scale; + result.highScale = scale / 2; + return result; +} + +template Faded FadedStopsFunction>::evaluate(float z, const ZoomHistory &zoomHistory) const; + +} diff --git a/src/mbgl/style/fadedfunction_properties.hpp b/src/mbgl/style/fadedfunction_properties.hpp new file mode 100644 index 0000000000..4d49dafb46 --- /dev/null +++ b/src/mbgl/style/fadedfunction_properties.hpp @@ -0,0 +1,24 @@ +#ifndef MBGL_STYLE_FADEDFUNCTION_PROPERTIES +#define MBGL_STYLE_FADEDFUNCTION_PROPERTIES + +#include + +#include + +namespace mbgl { + +template +struct FadedStopsFunction { + inline FadedStopsFunction(const std::vector> &values_, timestamp duration_) : values(values_), duration(duration_) {} + inline FadedStopsFunction(T &value) : values({{ 0, value }}), duration(0.0f) {} + inline FadedStopsFunction() : values(), duration(0.0f) {} + T evaluate(float z, const ZoomHistory &zoomHistory) const; + +private: + const std::vector> values; + const timestamp duration; +}; + +} + +#endif diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp index e017981dee..7b6c38e754 100644 --- a/src/mbgl/style/property_value.hpp +++ b/src/mbgl/style/property_value.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -16,7 +17,8 @@ typedef mapbox::util::variant< Function, Function, Function, - Function> + Function>, + FadedStopsFunction> > PropertyValue; } diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index ecff6fb5ff..dc764106ce 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -29,8 +29,10 @@ Style::~Style() {} void Style::updateProperties(float z, timestamp now) { uv::writelock lock(mtx); + zoomHistory.update(z, now); + if (layers) { - layers->updateProperties(z, now); + layers->updateProperties(z, now, zoomHistory); } // Apply transitions after the first time. diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index e9205712ef..434b394217 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -49,6 +50,7 @@ private: PropertyTransition defaultTransition; bool initial_render_complete = false; std::unique_ptr mtx; + ZoomHistory zoomHistory; }; } diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/style/style_layer.cpp index 262ca23af8..bb9688e574 100644 --- a/src/mbgl/style/style_layer.cpp +++ b/src/mbgl/style/style_layer.cpp @@ -94,7 +94,7 @@ void StyleLayer::applyClassProperties(const ClassID class_id, template struct PropertyEvaluator { typedef T result_type; - PropertyEvaluator(float z_) : z(z_) {} + PropertyEvaluator(float z_, const ZoomHistory &zoomHistory_) : z(z_), zoomHistory(zoomHistory_) {} template ::value, int>::type = 0> T operator()(const P &value) const { @@ -105,6 +105,10 @@ struct PropertyEvaluator { return mapbox::util::apply_visitor(FunctionEvaluator(z), value); } + T operator()(const FadedStopsFunction &value) const { + return value.evaluate(z, zoomHistory); + } + template ::value, int>::type = 0> T operator()(const P &) const { return T(); @@ -112,15 +116,16 @@ struct PropertyEvaluator { private: const float z; + const ZoomHistory &zoomHistory; }; template -void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const timestamp now) { +void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, const timestamp now, const ZoomHistory &zoomHistory) { auto it = appliedStyle.find(key); if (it != appliedStyle.end()) { AppliedClassProperties &applied = it->second; // Iterate through all properties that we need to apply in order. - const PropertyEvaluator evaluator(z); + const PropertyEvaluator evaluator(z, zoomHistory); for (AppliedClassProperty &property : applied.properties) { if (now >= property.begin) { // We overwrite the current property with the new value. @@ -133,12 +138,12 @@ void StyleLayer::applyStyleProperty(PropertyKey key, T &target, const float z, c } template -void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, const float z, const timestamp now) { +void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, const float z, const timestamp now, const ZoomHistory &zoomHistory) { auto it = appliedStyle.find(key); if (it != appliedStyle.end()) { AppliedClassProperties &applied = it->second; // Iterate through all properties that we need to apply in order. - const PropertyEvaluator evaluator(z); + const PropertyEvaluator evaluator(z, zoomHistory); for (AppliedClassProperty &property : applied.properties) { if (now >= property.end) { // We overwrite the current property with the new value. @@ -155,95 +160,95 @@ void StyleLayer::applyTransitionedStyleProperty(PropertyKey key, T &target, cons } template <> -void StyleLayer::applyStyleProperties(const float z, const timestamp now) { +void StyleLayer::applyStyleProperties(const float z, const timestamp now, const ZoomHistory &zoomHistory) { properties.set(); FillProperties &fill = properties.get(); - applyStyleProperty(PropertyKey::FillAntialias, fill.antialias, z, now); - applyTransitionedStyleProperty(PropertyKey::FillOpacity, fill.opacity, z, now); - applyTransitionedStyleProperty(PropertyKey::FillColor, fill.fill_color, z, now); - applyTransitionedStyleProperty(PropertyKey::FillOutlineColor, fill.stroke_color, z, now); - applyTransitionedStyleProperty(PropertyKey::FillTranslateX, fill.translate[0], z, now); - applyTransitionedStyleProperty(PropertyKey::FillTranslateY, fill.translate[1], z, now); - applyStyleProperty(PropertyKey::FillTranslateAnchor, fill.translateAnchor, z, now); - applyStyleProperty(PropertyKey::FillImage, fill.image, z, now); + applyStyleProperty(PropertyKey::FillAntialias, fill.antialias, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::FillOpacity, fill.opacity, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::FillColor, fill.fill_color, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::FillOutlineColor, fill.stroke_color, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::FillTranslateX, fill.translate[0], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::FillTranslateY, fill.translate[1], z, now, zoomHistory); + applyStyleProperty(PropertyKey::FillTranslateAnchor, fill.translateAnchor, z, now, zoomHistory); + applyStyleProperty(PropertyKey::FillImage, fill.image, z, now, zoomHistory); } template <> -void StyleLayer::applyStyleProperties(const float z, const timestamp now) { +void StyleLayer::applyStyleProperties(const float z, const timestamp now, const ZoomHistory &zoomHistory) { properties.set(); LineProperties &line = properties.get(); - applyTransitionedStyleProperty(PropertyKey::LineOpacity, line.opacity, z, now); - applyTransitionedStyleProperty(PropertyKey::LineColor, line.color, z, now); - applyTransitionedStyleProperty(PropertyKey::LineTranslateX, line.translate[0], z, now); - applyTransitionedStyleProperty(PropertyKey::LineTranslateY, line.translate[1], z, now); - applyStyleProperty(PropertyKey::LineTranslateAnchor, line.translateAnchor, z, now); - applyTransitionedStyleProperty(PropertyKey::LineWidth, line.width, z, now); - applyTransitionedStyleProperty(PropertyKey::LineGapWidth, line.gap_width, z, now); - applyTransitionedStyleProperty(PropertyKey::LineBlur, line.blur, z, now); - applyStyleProperty(PropertyKey::LineDashArray, line.dash_array, z, now); - applyStyleProperty(PropertyKey::LineImage, line.image, z, now); + applyTransitionedStyleProperty(PropertyKey::LineOpacity, line.opacity, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::LineColor, line.color, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::LineTranslateX, line.translate[0], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::LineTranslateY, line.translate[1], z, now, zoomHistory); + applyStyleProperty(PropertyKey::LineTranslateAnchor, line.translateAnchor, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::LineWidth, line.width, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::LineGapWidth, line.gap_width, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::LineBlur, line.blur, z, now, zoomHistory); + applyStyleProperty(PropertyKey::LineDashArray, line.dash_array, z, now, zoomHistory); + applyStyleProperty(PropertyKey::LineImage, line.image, z, now, zoomHistory); // for scaling dasharrays - applyStyleProperty(PropertyKey::LineWidth, line.dash_line_width, std::floor(z), now + 10000); + applyStyleProperty(PropertyKey::LineWidth, line.dash_line_width, std::floor(z), now + 10000, zoomHistory); } template <> -void StyleLayer::applyStyleProperties(const float z, const timestamp now) { +void StyleLayer::applyStyleProperties(const float z, const timestamp now, const ZoomHistory &zoomHistory) { properties.set(); SymbolProperties &symbol = properties.get(); - applyTransitionedStyleProperty(PropertyKey::IconOpacity, symbol.icon.opacity, z, now); - applyTransitionedStyleProperty(PropertyKey::IconRotate, symbol.icon.rotate, z, now); - applyTransitionedStyleProperty(PropertyKey::IconSize, symbol.icon.size, z, now); - applyTransitionedStyleProperty(PropertyKey::IconColor, symbol.icon.color, z, now); - applyTransitionedStyleProperty(PropertyKey::IconHaloColor, symbol.icon.halo_color, z, now); - applyTransitionedStyleProperty(PropertyKey::IconHaloWidth, symbol.icon.halo_width, z, now); - applyTransitionedStyleProperty(PropertyKey::IconHaloBlur, symbol.icon.halo_blur, z, now); - applyTransitionedStyleProperty(PropertyKey::IconTranslateX, symbol.icon.translate[0], z, now); - applyTransitionedStyleProperty(PropertyKey::IconTranslateY, symbol.icon.translate[1], z, now); - applyStyleProperty(PropertyKey::IconTranslateAnchor, symbol.icon.translate_anchor, z, now); - - applyTransitionedStyleProperty(PropertyKey::TextOpacity, symbol.text.opacity, z, now); - applyTransitionedStyleProperty(PropertyKey::TextSize, symbol.text.size, z, now); - applyTransitionedStyleProperty(PropertyKey::TextColor, symbol.text.color, z, now); - applyTransitionedStyleProperty(PropertyKey::TextHaloColor, symbol.text.halo_color, z, now); - applyTransitionedStyleProperty(PropertyKey::TextHaloWidth, symbol.text.halo_width, z, now); - applyTransitionedStyleProperty(PropertyKey::TextHaloBlur, symbol.text.halo_blur, z, now); - applyTransitionedStyleProperty(PropertyKey::TextTranslateX, symbol.text.translate[0], z, now); - applyTransitionedStyleProperty(PropertyKey::TextTranslateY, symbol.text.translate[1], z, now); - applyStyleProperty(PropertyKey::TextTranslateAnchor, symbol.text.translate_anchor, z, now); + applyTransitionedStyleProperty(PropertyKey::IconOpacity, symbol.icon.opacity, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconRotate, symbol.icon.rotate, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconSize, symbol.icon.size, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconColor, symbol.icon.color, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconHaloColor, symbol.icon.halo_color, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconHaloWidth, symbol.icon.halo_width, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconHaloBlur, symbol.icon.halo_blur, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconTranslateX, symbol.icon.translate[0], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconTranslateY, symbol.icon.translate[1], z, now, zoomHistory); + applyStyleProperty(PropertyKey::IconTranslateAnchor, symbol.icon.translate_anchor, z, now, zoomHistory); + + applyTransitionedStyleProperty(PropertyKey::TextOpacity, symbol.text.opacity, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::TextSize, symbol.text.size, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::TextColor, symbol.text.color, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::TextHaloColor, symbol.text.halo_color, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::TextHaloWidth, symbol.text.halo_width, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::TextHaloBlur, symbol.text.halo_blur, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::TextTranslateX, symbol.text.translate[0], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::TextTranslateY, symbol.text.translate[1], z, now, zoomHistory); + applyStyleProperty(PropertyKey::TextTranslateAnchor, symbol.text.translate_anchor, z, now, zoomHistory); } template <> -void StyleLayer::applyStyleProperties(const float z, const timestamp now) { +void StyleLayer::applyStyleProperties(const float z, const timestamp now, const ZoomHistory &zoomHistory) { properties.set(); RasterProperties &raster = properties.get(); - applyTransitionedStyleProperty(PropertyKey::RasterOpacity, raster.opacity, z, now); - applyTransitionedStyleProperty(PropertyKey::RasterHueRotate, raster.hue_rotate, z, now); - applyTransitionedStyleProperty(PropertyKey::RasterBrightnessLow, raster.brightness[0], z, now); - applyTransitionedStyleProperty(PropertyKey::RasterBrightnessHigh, raster.brightness[1], z, now); - applyTransitionedStyleProperty(PropertyKey::RasterSaturation, raster.saturation, z, now); - applyTransitionedStyleProperty(PropertyKey::RasterContrast, raster.contrast, z, now); - applyTransitionedStyleProperty(PropertyKey::RasterFade, raster.fade, z, now); + applyTransitionedStyleProperty(PropertyKey::RasterOpacity, raster.opacity, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::RasterHueRotate, raster.hue_rotate, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::RasterBrightnessLow, raster.brightness[0], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::RasterBrightnessHigh, raster.brightness[1], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::RasterSaturation, raster.saturation, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::RasterContrast, raster.contrast, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::RasterFade, raster.fade, z, now, zoomHistory); } template <> -void StyleLayer::applyStyleProperties(const float z, const timestamp now) { +void StyleLayer::applyStyleProperties(const float z, const timestamp now, const ZoomHistory &zoomHistory) { properties.set(); BackgroundProperties &background = properties.get(); - applyTransitionedStyleProperty(PropertyKey::BackgroundOpacity, background.opacity, z, now); - applyTransitionedStyleProperty(PropertyKey::BackgroundColor, background.color, z, now); - applyStyleProperty(PropertyKey::BackgroundImage, background.image, z, now); + applyTransitionedStyleProperty(PropertyKey::BackgroundOpacity, background.opacity, z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::BackgroundColor, background.color, z, now, zoomHistory); + applyStyleProperty(PropertyKey::BackgroundImage, background.image, z, now, zoomHistory); } -void StyleLayer::updateProperties(float z, const timestamp now) { +void StyleLayer::updateProperties(float z, const timestamp now, ZoomHistory &zoomHistory) { cleanupAppliedStyleProperties(now); switch (type) { - case StyleLayerType::Fill: applyStyleProperties(z, now); break; - case StyleLayerType::Line: applyStyleProperties(z, now); break; - case StyleLayerType::Symbol: applyStyleProperties(z, now); break; - case StyleLayerType::Raster: applyStyleProperties(z, now); break; - case StyleLayerType::Background: applyStyleProperties(z, now); break; + case StyleLayerType::Fill: applyStyleProperties(z, now, zoomHistory); break; + case StyleLayerType::Line: applyStyleProperties(z, now, zoomHistory); break; + case StyleLayerType::Symbol: applyStyleProperties(z, now, zoomHistory); break; + case StyleLayerType::Raster: applyStyleProperties(z, now, zoomHistory); break; + case StyleLayerType::Background: applyStyleProperties(z, now, zoomHistory); break; default: properties.set(); break; } } diff --git a/src/mbgl/style/style_layer.hpp b/src/mbgl/style/style_layer.hpp index 7cf661ca33..8531ad3a05 100644 --- a/src/mbgl/style/style_layer.hpp +++ b/src/mbgl/style/style_layer.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -35,7 +36,7 @@ public: // Updates the StyleProperties information in this layer by evaluating all // pending transitions and applied classes in order. - void updateProperties(float z, timestamp now); + void updateProperties(float z, timestamp now, ZoomHistory &zoomHistory); // Sets the list of classes and creates transitions to the currently applied values. void setClasses(const std::vector &class_names, timestamp now, @@ -50,9 +51,9 @@ private: // Sets the properties of this object by evaluating all pending transitions and // aplied classes in order. - template void applyStyleProperties(float z, timestamp now); - template void applyStyleProperty(PropertyKey key, T &, float z, timestamp now); - template void applyTransitionedStyleProperty(PropertyKey key, T &, float z, timestamp now); + template void applyStyleProperties(float z, timestamp now, const ZoomHistory &zoomHistory); + template void applyStyleProperty(PropertyKey key, T &, float z, timestamp now, const ZoomHistory &zoomHistory); + template void applyTransitionedStyleProperty(PropertyKey key, T &, float z, timestamp now, const ZoomHistory &zoomHistory); // Removes all expired style transitions. void cleanupAppliedStyleProperties(timestamp now); diff --git a/src/mbgl/style/style_layer_group.cpp b/src/mbgl/style/style_layer_group.cpp index 0ca0fa0cce..5ca020ee74 100644 --- a/src/mbgl/style/style_layer_group.cpp +++ b/src/mbgl/style/style_layer_group.cpp @@ -11,10 +11,10 @@ void StyleLayerGroup::setClasses(const std::vector &class_names, ti } } -void StyleLayerGroup::updateProperties(float z, timestamp t) { +void StyleLayerGroup::updateProperties(float z, timestamp t, ZoomHistory &zoomHistory) { for (const util::ptr &layer: layers) { if (layer) { - layer->updateProperties(z, t); + layer->updateProperties(z, t, zoomHistory); } } } diff --git a/src/mbgl/style/style_layer_group.hpp b/src/mbgl/style/style_layer_group.hpp index 1af6e23bd7..85cfcc6dd6 100644 --- a/src/mbgl/style/style_layer_group.hpp +++ b/src/mbgl/style/style_layer_group.hpp @@ -11,7 +11,7 @@ class StyleLayerGroup { public: void setClasses(const std::vector &class_names, timestamp now, const PropertyTransition &defaultTransition); - void updateProperties(float z, timestamp t); + void updateProperties(float z, timestamp t, ZoomHistory &zoomHistory); bool hasTransitions() const; public: diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index f048b24bd4..3f1fc64dab 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -263,6 +263,52 @@ std::vector StyleParser::parseFunctionArgument(JSVal value) { return std::get<1>(parseFloatArray(rvalue)); } +template <> +Faded StyleParser::parseFunctionArgument(JSVal value) { + JSVal rvalue = replaceConstant(value); + if (rvalue.IsString()) { + Faded parsed; + parsed.low = { value.GetString(), value.GetStringLength() }; + return parsed; + } else { + Log::Warning(Event::ParseStyle, "function argument must be a string"); + return {}; + } +} + +template +std::tuple>> StyleParser::parseStops(JSVal value_stops) { + + if (!value_stops.IsArray()) { + Log::Warning(Event::ParseStyle, "stops function must specify a stops array"); + return std::tuple>> { false, {}}; + } + + std::vector> stops; + + for (rapidjson::SizeType i = 0; i < value_stops.Size(); ++i) { + JSVal stop = value_stops[i]; + if (stop.IsArray()) { + if (stop.Size() != 2) { + Log::Warning(Event::ParseStyle, "stop must have zoom level and value specification"); + return std::tuple>> { false, {}}; + } + + JSVal z = stop[rapidjson::SizeType(0)]; + if (!z.IsNumber()) { + Log::Warning(Event::ParseStyle, "zoom level in stop must be a number"); + return std::tuple>> { false, {}}; + } + + stops.emplace_back(z.GetDouble(), parseFunctionArgument(stop[rapidjson::SizeType(1)])); + } else { + Log::Warning(Event::ParseStyle, "function argument must be a numeric value"); + return std::tuple>> { false, {}}; + } + } + return { true, stops }; +} + template inline float defaultBaseValue() { return 1.75; } template <> inline float defaultBaseValue() { return 1.0; } @@ -284,47 +330,52 @@ std::tuple> StyleParser::parseFunction(JSVal value) { } } - JSVal value_stops = value["stops"]; - if (!value_stops.IsArray()) { - Log::Warning(Event::ParseStyle, "stops function must specify a stops array"); + auto stops = parseStops(value["stops"]); + + if (!std::get<0>(stops)) { return std::tuple> { false, ConstantFunction(T()) }; } - std::vector> stops; - for (rapidjson::SizeType i = 0; i < value_stops.Size(); ++i) { - JSVal stop = value_stops[i]; - if (stop.IsArray()) { - if (stop.Size() != 2) { - Log::Warning(Event::ParseStyle, "stop must have zoom level and value specification"); - return std::tuple> { false, ConstantFunction(T()) }; - } + return std::tuple> { true, StopsFunction(std::get<1>(stops), base) }; +} - JSVal z = stop[rapidjson::SizeType(0)]; - if (!z.IsNumber()) { - Log::Warning(Event::ParseStyle, "zoom level in stop must be a number"); - return std::tuple> { false, ConstantFunction(T()) }; - } +template inline timestamp defaultDurationValue() { return 300_milliseconds; } - stops.emplace_back(z.GetDouble(), parseFunctionArgument(stop[rapidjson::SizeType(1)])); +template +std::tuple> StyleParser::parseFadedStopsFunction(JSVal value) { + if (!value.HasMember("stops")) { + Log::Warning(Event::ParseStyle, "function must specify a function type"); + return std::tuple> { false, {} }; + } + + timestamp duration = defaultDurationValue(); + + if (value.HasMember("duration")) { + JSVal value_duration = value["duration"]; + if (value_duration.IsNumber()) { + float duration_ = value_duration.GetDouble(); + duration = 1_millisecond * duration_; } else { - Log::Warning(Event::ParseStyle, "function argument must be a numeric value"); - return std::tuple> { false, ConstantFunction(T()) }; + Log::Warning(Event::ParseStyle, "duration must be numeric"); } } - return std::tuple> { true, StopsFunction(stops, base) }; -} + auto stops = parseStops(value["stops"]); + + if (!std::get<0>(stops)) { + return std::tuple> { false, {} }; + } + return std::tuple> { true, { std::get<1>(stops), duration } }; +} template bool StyleParser::setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass) { - bool parsed; - T result; - std::tie(parsed, result) = parseProperty(value, property_name); - if (parsed) { - klass.set(key, result); + auto res = parseProperty(value, property_name); + if (std::get<0>(res)) { + klass.set(key, std::get<1>(res)); } - return parsed; + return std::get<0>(res); } template @@ -430,6 +481,19 @@ template<> std::tuple>> StyleParser::parseProp } } +template<> std::tuple>> StyleParser::parseProperty(JSVal value, const char *property_name) { + if (value.IsObject()) { + return parseFadedStopsFunction>(value); + } else if (value.IsString()) { + Faded parsed; + parsed.low = { value.GetString(), value.GetStringLength() }; + return std::tuple>> { true, parsed }; + } else { + Log::Warning(Event::ParseStyle, "value of '%s' must be string or a string function", property_name); + return std::tuple>> { false, {} }; + } +} + template bool StyleParser::parseOptionalProperty(const char *property_name, const std::vector &keys, ClassProperties &klass, JSVal value) { if (value.HasMember(property_name)) { @@ -573,7 +637,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty>("fill-translate", { Key::FillTranslateX, Key::FillTranslateY }, klass, value); parseOptionalProperty("fill-translate-transition", Key::FillTranslate, klass, value); parseOptionalProperty("fill-translate-anchor", Key::FillTranslateAnchor, klass, value); - parseOptionalProperty("fill-image", Key::FillImage, klass, value); + parseOptionalProperty>>("fill-image", Key::FillImage, klass, value); parseOptionalProperty>("line-opacity", Key::LineOpacity, klass, value); parseOptionalProperty("line-opacity-transition", Key::LineOpacity, klass, value); diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 42e22f9458..482fa0a00b 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -77,7 +77,11 @@ private: template std::tuple> parseFunction(JSVal value); template + std::tuple> parseFadedStopsFunction(JSVal value); + template T parseFunctionArgument(JSVal value); + template + std::tuple>> parseStops(JSVal value); FilterExpression parseFilter(JSVal); diff --git a/src/mbgl/style/style_properties.hpp b/src/mbgl/style/style_properties.hpp index c5149b2d1c..db9e4c34c9 100644 --- a/src/mbgl/style/style_properties.hpp +++ b/src/mbgl/style/style_properties.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -21,7 +21,7 @@ struct FillProperties { Color stroke_color = {{ 0, 0, 0, -1 }}; std::array translate = {{ 0, 0 }}; TranslateAnchorType translateAnchor = TranslateAnchorType::Map; - std::string image; + Faded image; inline bool isVisible() const { return opacity > 0 && (fill_color[3] > 0 || stroke_color[3] > 0); diff --git a/src/mbgl/style/types.hpp b/src/mbgl/style/types.hpp index c0b873dcd9..cd9c29d30a 100644 --- a/src/mbgl/style/types.hpp +++ b/src/mbgl/style/types.hpp @@ -11,6 +11,16 @@ namespace mbgl { // Stores a premultiplied color, with all four channels ranging from 0..1 typedef std::array Color; + +template +struct Faded { + T low; + float lowScale; + T high; + float highScale; + float t; +}; + // ------------------------------------------------------------------------------------------------- enum class StyleLayerType : uint8_t { diff --git a/src/mbgl/style/zoom_history.hpp b/src/mbgl/style/zoom_history.hpp new file mode 100644 index 0000000000..7031068624 --- /dev/null +++ b/src/mbgl/style/zoom_history.hpp @@ -0,0 +1,39 @@ +#ifndef MBGL_STYLE_ZOOM_HISTORY +#define MBGL_STYLE_ZOOM_HISTORY + +#include + +#include + +namespace mbgl { + +struct ZoomHistory { + float lastZoom; + float lastIntegerZoom; + timestamp lastIntegerZoomTime; + bool first = true; + + void update(float z, timestamp now) { + if (first) { + first = false; + + lastIntegerZoom = std::floor(z); + lastIntegerZoomTime = 0; + lastZoom = z; + } + + if (std::floor(lastZoom) < std::floor(z)) { + lastIntegerZoom = std::floor(z); + lastIntegerZoomTime = now; + + } else if (std::floor(lastZoom) > std::floor(z)) { + lastIntegerZoom = std::floor(z + 1); + lastIntegerZoomTime = now; + } + + lastZoom = z; + } +}; +} + +#endif -- cgit v1.2.1 From b3ca6fcca6e3a1c383a0235aea3110bc940c0656 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 16:23:10 -0800 Subject: implement functions for background-image --- src/mbgl/renderer/painter.cpp | 50 +++++++++++++++++++++++++------------ src/mbgl/style/style_parser.cpp | 2 +- src/mbgl/style/style_properties.hpp | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 448b380743..f8347123c0 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -376,39 +376,57 @@ void Painter::renderTileLayer(const Tile& tile, util::ptr layer_desc void Painter::renderBackground(util::ptr layer_desc) { const BackgroundProperties& properties = layer_desc->getProperties(); - if (properties.image.size()) { + if (properties.image.low.size()) { if ((properties.opacity >= 1.0f) != (pass == RenderPass::Opaque)) return; - SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image, true); + SpriteAtlasPosition imagePosA = spriteAtlas.getPosition(properties.image.low, true); + SpriteAtlasPosition imagePosB = spriteAtlas.getPosition(properties.image.high, true); float zoomFraction = state.getZoomFraction(); useProgram(patternShader->program); patternShader->u_matrix = identityMatrix; - patternShader->u_pattern_tl_a = imagePos.tl; - patternShader->u_pattern_br_a = imagePos.br; + patternShader->u_pattern_tl_a = imagePosA.tl; + patternShader->u_pattern_br_a = imagePosA.br; + patternShader->u_pattern_tl_b = imagePosB.tl; + patternShader->u_pattern_br_b = imagePosB.br; patternShader->u_mix = zoomFraction; patternShader->u_opacity = properties.opacity; - std::array size = imagePos.size; double lon, lat; state.getLonLat(lon, lat); std::array center = state.locationCoordinate(lon, lat); float scale = 1 / std::pow(2, zoomFraction); - mat3 matrix; - matrix::identity(matrix); - matrix::scale(matrix, matrix, - 1.0f / size[0], - 1.0f / size[1]); - matrix::translate(matrix, matrix, - std::fmod(center[0] * 512, size[0]), - std::fmod(center[1] * 512, size[1])); - matrix::rotate(matrix, matrix, -state.getAngle()); - matrix::scale(matrix, matrix, + std::array sizeA = imagePosA.size; + mat3 matrixA; + matrix::identity(matrixA); + matrix::scale(matrixA, matrixA, + 1.0f / (sizeA[0] * properties.image.lowScale), + 1.0f / (sizeA[1] * properties.image.lowScale)); + matrix::translate(matrixA, matrixA, + std::fmod(center[0] * 512, sizeA[0] * properties.image.lowScale), + std::fmod(center[1] * 512, sizeA[1] * properties.image.lowScale)); + matrix::rotate(matrixA, matrixA, -state.getAngle()); + matrix::scale(matrixA, matrixA, scale * state.getWidth() / 2, -scale * state.getHeight() / 2); - patternShader->u_patternmatrix_a = matrix; + + std::array sizeB = imagePosB.size; + mat3 matrixB; + matrix::identity(matrixB); + matrix::scale(matrixB, matrixB, + 1.0f / (sizeB[0] * properties.image.highScale), + 1.0f / (sizeB[1] * properties.image.highScale)); + matrix::translate(matrixB, matrixB, + std::fmod(center[0] * 512, sizeB[0] * properties.image.highScale), + std::fmod(center[1] * 512, sizeB[1] * properties.image.highScale)); + matrix::rotate(matrixB, matrixB, -state.getAngle()); + matrix::scale(matrixB, matrixB, + scale * state.getWidth() / 2, + -scale * state.getHeight() / 2); + + patternShader->u_patternmatrix_a = matrixA; backgroundBuffer.bind(); patternShader->bind(0); diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 3f1fc64dab..1cf8d2e355 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -703,7 +703,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty>("background-opacity", Key::BackgroundOpacity, klass, value); parseOptionalProperty>("background-color", Key::BackgroundColor, klass, value); - parseOptionalProperty("background-image", Key::BackgroundImage, klass, value); + parseOptionalProperty>>("background-image", Key::BackgroundImage, klass, value); } void StyleParser::parseReference(JSVal value, util::ptr &layer) { diff --git a/src/mbgl/style/style_properties.hpp b/src/mbgl/style/style_properties.hpp index db9e4c34c9..d2c134e8d8 100644 --- a/src/mbgl/style/style_properties.hpp +++ b/src/mbgl/style/style_properties.hpp @@ -96,7 +96,7 @@ struct BackgroundProperties { inline BackgroundProperties() {} float opacity = 1.0f; Color color = {{ 0, 0, 0, 1 }}; - std::string image; + Faded image; }; typedef mapbox::util::variant< -- cgit v1.2.1 From 322f46a5db6d44633ffc7a45140e163f03365371 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 17:08:26 -0800 Subject: implement functions for line-image --- src/mbgl/renderer/painter.cpp | 1 + src/mbgl/renderer/painter_line.cpp | 25 ++++++++++--------------- src/mbgl/shader/linepattern.fragment.glsl | 22 +++++++++++++--------- src/mbgl/shader/linepattern_shader.hpp | 9 ++++++--- src/mbgl/style/style_parser.cpp | 2 +- src/mbgl/style/style_properties.hpp | 2 +- 6 files changed, 32 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index f8347123c0..84bd24c5e7 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -427,6 +427,7 @@ void Painter::renderBackground(util::ptr layer_desc) { -scale * state.getHeight() / 2); patternShader->u_patternmatrix_a = matrixA; + patternShader->u_patternmatrix_b = matrixB; backgroundBuffer.bind(); patternShader->bind(0); diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 3951f2e7c8..b26f1cfa55 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -112,19 +112,11 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c bucket.drawLineSDF(*linesdfShader); - } else if (properties.image.size()) { - SpriteAtlasPosition imagePos = spriteAtlas.getPosition(properties.image, true); + } else if (properties.image.low.size()) { + SpriteAtlasPosition imagePosA = spriteAtlas.getPosition(properties.image.low, true); + SpriteAtlasPosition imagePosB = spriteAtlas.getPosition(properties.image.high, true); float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z); - float fade; - if (state.getZoom() > lastIntegerZoom) { - // zooming in - fade = fraction + (1.0f - fraction) * t; - factor *= 2.0; - } else { - // zooming out - fade = fraction - fraction * t; - } useProgram(linepatternShader->program); @@ -134,10 +126,13 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c linepatternShader->u_ratio = ratio; linepatternShader->u_blur = blur; - linepatternShader->u_pattern_size = {{imagePos.size[0] * factor, imagePos.size[1]}}; - linepatternShader->u_pattern_tl = imagePos.tl; - linepatternShader->u_pattern_br = imagePos.br; - linepatternShader->u_fade = fade; + linepatternShader->u_pattern_size_a = {{imagePosA.size[0] * factor * properties.image.lowScale, imagePosA.size[1]}}; + linepatternShader->u_pattern_tl_a = imagePosA.tl; + linepatternShader->u_pattern_br_a = imagePosA.br; + linepatternShader->u_pattern_size_b = {{imagePosB.size[0] * factor * properties.image.highScale, imagePosB.size[1]}}; + linepatternShader->u_pattern_tl_b = imagePosB.tl; + linepatternShader->u_pattern_br_b = imagePosB.br; + linepatternShader->u_fade = properties.image.t; linepatternShader->u_opacity = properties.opacity; MBGL_CHECK_ERROR(glActiveTexture(GL_TEXTURE0)); diff --git a/src/mbgl/shader/linepattern.fragment.glsl b/src/mbgl/shader/linepattern.fragment.glsl index 45be7c8c2f..08feff4396 100644 --- a/src/mbgl/shader/linepattern.fragment.glsl +++ b/src/mbgl/shader/linepattern.fragment.glsl @@ -2,9 +2,12 @@ uniform vec2 u_linewidth; uniform float u_point; uniform float u_blur; -uniform vec2 u_pattern_size; -uniform vec2 u_pattern_tl; -uniform vec2 u_pattern_br; +uniform vec2 u_pattern_size_a; +uniform vec2 u_pattern_tl_a; +uniform vec2 u_pattern_br_a; +uniform vec2 u_pattern_size_b; +uniform vec2 u_pattern_tl_b; +uniform vec2 u_pattern_br_b; uniform float u_fade; uniform float u_opacity; @@ -24,13 +27,14 @@ void main() { // (v_linewidth.s) float alpha = clamp(min(dist - (u_linewidth.t - u_blur), u_linewidth.s - dist) / u_blur, 0.0, 1.0); - float x = mod(v_linesofar / u_pattern_size.x, 1.0); - float y = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size.y); - vec2 pos = mix(u_pattern_tl, u_pattern_br, vec2(x, y)); - float x2 = mod(x * 2.0, 1.0); - vec2 pos2 = mix(u_pattern_tl, u_pattern_br, vec2(x2, y)); + float x_a = mod(v_linesofar / u_pattern_size_a.x, 1.0); + float y_a = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_a.y); + vec2 pos_a = mix(u_pattern_tl_a, u_pattern_br_a, vec2(x_a, y_a)); + float x_b = mod(v_linesofar / u_pattern_size_b.x, 1.0); + float y_b = 0.5 + (v_normal.y * u_linewidth.s / u_pattern_size_b.y); + vec2 pos_b = mix(u_pattern_tl_b, u_pattern_br_b, vec2(x_b, y_b)); - vec4 color = texture2D(u_image, pos) * (1.0 - u_fade) + u_fade * texture2D(u_image, pos2); + vec4 color = mix(texture2D(u_image, pos_a), texture2D(u_image, pos_b), u_fade); alpha *= u_opacity; diff --git a/src/mbgl/shader/linepattern_shader.hpp b/src/mbgl/shader/linepattern_shader.hpp index 388cff17d2..16d9ff8be7 100644 --- a/src/mbgl/shader/linepattern_shader.hpp +++ b/src/mbgl/shader/linepattern_shader.hpp @@ -15,9 +15,12 @@ public: UniformMatrix<4> u_matrix = {"u_matrix", *this}; UniformMatrix<4> u_exmatrix = {"u_exmatrix", *this}; Uniform> u_linewidth = {"u_linewidth", *this}; - Uniform> u_pattern_size = {"u_pattern_size", *this}; - Uniform> u_pattern_tl = {"u_pattern_tl", *this}; - Uniform> u_pattern_br = {"u_pattern_br", *this}; + Uniform> u_pattern_size_a = {"u_pattern_size_a", *this}; + Uniform> u_pattern_tl_a = {"u_pattern_tl_a", *this}; + Uniform> u_pattern_br_a = {"u_pattern_br_a", *this}; + Uniform> u_pattern_size_b = {"u_pattern_size_b", *this}; + Uniform> u_pattern_tl_b = {"u_pattern_tl_b", *this}; + Uniform> u_pattern_br_b = {"u_pattern_br_b", *this}; Uniform u_ratio = {"u_ratio", *this}; Uniform u_point = {"u_point", *this}; Uniform u_blur = {"u_blur", *this}; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 1cf8d2e355..5dcf3b114c 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -653,7 +653,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty>("line-blur", Key::LineBlur, klass, value); parseOptionalProperty("line-blur-transition", Key::LineBlur, klass, value); parseOptionalProperty>>("line-dasharray", Key::LineDashArray, klass, value); - parseOptionalProperty("line-image", Key::LineImage, klass, value); + parseOptionalProperty>>("line-image", Key::LineImage, klass, value); parseOptionalProperty>("icon-opacity", Key::IconOpacity, klass, value); parseOptionalProperty("icon-opacity-transition", Key::IconOpacity, klass, value); diff --git a/src/mbgl/style/style_properties.hpp b/src/mbgl/style/style_properties.hpp index d2c134e8d8..1784210102 100644 --- a/src/mbgl/style/style_properties.hpp +++ b/src/mbgl/style/style_properties.hpp @@ -39,7 +39,7 @@ struct LineProperties { float blur = 0; std::vector dash_array; float dash_line_width = 1; - std::string image; + Faded image; inline bool isVisible() const { return opacity > 0 && color[3] > 0 && width > 0; -- cgit v1.2.1 From 6f5c6b58b48e762ed7aced6c4486f1060d0e34f1 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 17:52:44 -0800 Subject: use faded pattern functions for dasharrays --- src/mbgl/renderer/painter_line.cpp | 39 +++++++++++------------------ src/mbgl/style/fadedfunction_properties.cpp | 1 + src/mbgl/style/fadedfunction_properties.hpp | 4 +-- src/mbgl/style/property_value.hpp | 2 +- src/mbgl/style/style_parser.cpp | 20 +++++++++------ src/mbgl/style/style_properties.hpp | 2 +- 6 files changed, 31 insertions(+), 37 deletions(-) (limited to 'src') 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 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 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::evaluate(float z, const ZoomHistory &zh) const { } template Faded FadedStopsFunction>::evaluate(float z, const ZoomHistory &zoomHistory) const; +template Faded> FadedStopsFunction>>::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 struct FadedStopsFunction { inline FadedStopsFunction(const std::vector> &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, Function, Function, - Function>, + FadedStopsFunction>>, FadedStopsFunction> > 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 StyleParser::parseFunctionArgument(JSVal value) { +Faded> StyleParser::parseFunctionArgument(JSVal value) { + Faded> 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> StyleParser::parseProperty(JSVal va } } -template<> std::tuple>> StyleParser::parseProperty(JSVal value, const char *property_name) { +template<> std::tuple>>> StyleParser::parseProperty(JSVal value, const char *property_name) { if (value.IsObject()) { - return parseFunction>(value); + return parseFadedStopsFunction>>(value); } else if (value.IsArray()) { - std::tuple> parsed = parseFloatArray(value); - return std::tuple>> { std::get<0>(parsed), ConstantFunction>(std::get<1>(parsed)) }; + Faded> parsed; + std::tuple> floatarray = parseFloatArray(value); + parsed.low = std::get<1>(floatarray); + return std::tuple>>> { 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>> { false, ConstantFunction>(std::vector()) }; + return std::tuple>>> { false, {} }; } } @@ -652,7 +656,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("line-gap-width-transition", Key::LineGapWidth, klass, value); parseOptionalProperty>("line-blur", Key::LineBlur, klass, value); parseOptionalProperty("line-blur-transition", Key::LineBlur, klass, value); - parseOptionalProperty>>("line-dasharray", Key::LineDashArray, klass, value); + parseOptionalProperty>>>("line-dasharray", Key::LineDashArray, klass, value); parseOptionalProperty>>("line-image", Key::LineImage, klass, value); parseOptionalProperty>("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 dash_array; + Faded> dash_array; float dash_line_width = 1; Faded image; -- cgit v1.2.1 From c9f8de863dc93e4fd587290357c8a3b572a4f956 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 18:27:55 -0800 Subject: remove old version of zoomHistory --- src/mbgl/renderer/painter.cpp | 25 +------------------------ src/mbgl/renderer/painter.hpp | 5 ----- 2 files changed, 1 insertion(+), 29 deletions(-) (limited to 'src') diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 84bd24c5e7..02e263a1ca 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -232,7 +232,7 @@ void Painter::render(const Style& style, const std::set>& drawClippingMasks(sources); - recordZoom(time, state.getNormalizedZoom()); + frameHistory.record(time, state.getNormalizedZoom()); // Actually render the layers if (debug::renderTree) { std::cout << "{" << std::endl; indent++; } @@ -479,26 +479,3 @@ mat4 Painter::translatedMatrix(const mat4& matrix, const std::array &t return vtxMatrix; } } - -void Painter::recordZoom(const timestamp time, const float zoom) { - frameHistory.record(time, zoom); - - if (lastZoom < 0) { - // first frame ever - lastIntegerZoom = std::floor(zoom); - lastZoom = zoom; - } - - // check whether an integer zoom level was passed since the last frame - // and if yes, record it with the time. Used for transitioning patterns. - if (std::floor(lastZoom) < std::floor(zoom)) { - lastIntegerZoom = std::floor(zoom); - lastIntegerZoomTime = time; - - } else if (std::floor(lastZoom) > std::floor(zoom)) { - lastIntegerZoom = std::floor(zoom) + 1; - lastIntegerZoomTime = time; - } - - lastZoom = zoom; -} diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 5a42070200..4d4876a6f1 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -139,7 +139,6 @@ private: mat4 translatedMatrix(const mat4& matrix, const std::array &translation, const Tile::ID &id, TranslateAnchorType anchor); void prepareTile(const Tile& tile); - void recordZoom(const timestamp time, const float zoom); template void renderSDF(SymbolBucket &bucket, @@ -192,10 +191,6 @@ private: RenderPass pass = RenderPass::Opaque; const float strata_epsilon = 1.0f / (1 << 16); - int lastIntegerZoom; - timestamp lastIntegerZoomTime = 0; - float lastZoom = -1; - public: FrameHistory frameHistory; -- cgit v1.2.1 From 93b07c367577b097e3791d38690b8fc37054c5fb Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 11:36:31 -0800 Subject: rename FadedFunction to PiecewiseConstant function --- src/mbgl/style/fadedfunction_properties.cpp | 50 ------------------------- src/mbgl/style/fadedfunction_properties.hpp | 24 ------------ src/mbgl/style/piecewisefunction_properties.cpp | 50 +++++++++++++++++++++++++ src/mbgl/style/piecewisefunction_properties.hpp | 24 ++++++++++++ src/mbgl/style/property_value.hpp | 6 +-- src/mbgl/style/style_layer.cpp | 2 +- src/mbgl/style/style_parser.cpp | 32 ++++++++-------- src/mbgl/style/style_parser.hpp | 2 +- src/mbgl/style/style_properties.hpp | 2 +- 9 files changed, 96 insertions(+), 96 deletions(-) delete mode 100644 src/mbgl/style/fadedfunction_properties.cpp delete mode 100644 src/mbgl/style/fadedfunction_properties.hpp create mode 100644 src/mbgl/style/piecewisefunction_properties.cpp create mode 100644 src/mbgl/style/piecewisefunction_properties.hpp (limited to 'src') diff --git a/src/mbgl/style/fadedfunction_properties.cpp b/src/mbgl/style/fadedfunction_properties.cpp deleted file mode 100644 index 21c3267519..0000000000 --- a/src/mbgl/style/fadedfunction_properties.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -#include - -namespace mbgl { - -template -uint32_t getBiggestStopLessThan(std::vector> stops, float z) { - for (uint32_t i = 0; i < stops.size(); i++) { - if (stops[i].first > z) { - return i == 0 ? i : i - 1; - } - } - return stops.size() - 1; -} - -template -T FadedStopsFunction::evaluate(float z, const ZoomHistory &zh) const { - T result; - - float fraction = std::fmod(z, 1.0f); - float t = std::min((std::chrono::steady_clock::now() - zh.lastIntegerZoomTime) / duration, 1.0f); - float scale = 1.0f; - uint32_t low, high; - - if (z > zh.lastIntegerZoom) { - result.t = fraction + (1.0f - fraction) * t; - scale *= 2.0f; - low = getBiggestStopLessThan(values, z - 1.0f); - high = getBiggestStopLessThan(values, z); - - } else { - result.t = fraction - fraction * t; - low = getBiggestStopLessThan(values, z); - high = getBiggestStopLessThan(values, z + 1.0f); - } - - - result.low = values[low].second.low; - result.high = values[high].second.low; - result.lowScale = scale; - result.highScale = scale / 2; - return result; -} - -template Faded FadedStopsFunction>::evaluate(float z, const ZoomHistory &zoomHistory) const; -template Faded> FadedStopsFunction>>::evaluate(float z, const ZoomHistory &zoomHistory) const; - -} diff --git a/src/mbgl/style/fadedfunction_properties.hpp b/src/mbgl/style/fadedfunction_properties.hpp deleted file mode 100644 index 7313d32759..0000000000 --- a/src/mbgl/style/fadedfunction_properties.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef MBGL_STYLE_FADEDFUNCTION_PROPERTIES -#define MBGL_STYLE_FADEDFUNCTION_PROPERTIES - -#include - -#include - -namespace mbgl { - -template -struct FadedStopsFunction { - inline FadedStopsFunction(const std::vector> &values_, std::chrono::duration duration_) : values(values_), duration(duration_) {} - inline FadedStopsFunction(T &value) : values({{ 0, value }}), duration(300) {} - inline FadedStopsFunction() : values(), duration(300) {} - T evaluate(float z, const ZoomHistory &zoomHistory) const; - -private: - const std::vector> values; - const std::chrono::duration duration; -}; - -} - -#endif diff --git a/src/mbgl/style/piecewisefunction_properties.cpp b/src/mbgl/style/piecewisefunction_properties.cpp new file mode 100644 index 0000000000..e760ebdb13 --- /dev/null +++ b/src/mbgl/style/piecewisefunction_properties.cpp @@ -0,0 +1,50 @@ +#include +#include + +#include + +namespace mbgl { + +template +uint32_t getBiggestStopLessThan(std::vector> stops, float z) { + for (uint32_t i = 0; i < stops.size(); i++) { + if (stops[i].first > z) { + return i == 0 ? i : i - 1; + } + } + return stops.size() - 1; +} + +template +T PiecewiseConstantFunction::evaluate(float z, const ZoomHistory &zh) const { + T result; + + float fraction = std::fmod(z, 1.0f); + float t = std::min((std::chrono::steady_clock::now() - zh.lastIntegerZoomTime) / duration, 1.0f); + float scale = 1.0f; + uint32_t low, high; + + if (z > zh.lastIntegerZoom) { + result.t = fraction + (1.0f - fraction) * t; + scale *= 2.0f; + low = getBiggestStopLessThan(values, z - 1.0f); + high = getBiggestStopLessThan(values, z); + + } else { + result.t = fraction - fraction * t; + low = getBiggestStopLessThan(values, z); + high = getBiggestStopLessThan(values, z + 1.0f); + } + + + result.low = values[low].second.low; + result.high = values[high].second.low; + result.lowScale = scale; + result.highScale = scale / 2; + return result; +} + +template Faded PiecewiseConstantFunction>::evaluate(float z, const ZoomHistory &zoomHistory) const; +template Faded> PiecewiseConstantFunction>>::evaluate(float z, const ZoomHistory &zoomHistory) const; + +} diff --git a/src/mbgl/style/piecewisefunction_properties.hpp b/src/mbgl/style/piecewisefunction_properties.hpp new file mode 100644 index 0000000000..69ddc7cc2a --- /dev/null +++ b/src/mbgl/style/piecewisefunction_properties.hpp @@ -0,0 +1,24 @@ +#ifndef MBGL_STYLE_FADEDFUNCTION_PROPERTIES +#define MBGL_STYLE_FADEDFUNCTION_PROPERTIES + +#include + +#include + +namespace mbgl { + +template +struct PiecewiseConstantFunction { + inline PiecewiseConstantFunction(const std::vector> &values_, std::chrono::duration duration_) : values(values_), duration(duration_) {} + inline PiecewiseConstantFunction(T &value) : values({{ 0, value }}), duration(300) {} + inline PiecewiseConstantFunction() : values(), duration(300) {} + T evaluate(float z, const ZoomHistory &zoomHistory) const; + +private: + const std::vector> values; + const std::chrono::duration duration; +}; + +} + +#endif diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp index 49e837cf12..c7fe823025 100644 --- a/src/mbgl/style/property_value.hpp +++ b/src/mbgl/style/property_value.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include @@ -26,8 +26,8 @@ typedef mapbox::util::variant< Function, Function, Function, - FadedStopsFunction>>, - FadedStopsFunction> + PiecewiseConstantFunction>>, + PiecewiseConstantFunction> > PropertyValue; } diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/style/style_layer.cpp index 795c651b85..9a7066c497 100644 --- a/src/mbgl/style/style_layer.cpp +++ b/src/mbgl/style/style_layer.cpp @@ -105,7 +105,7 @@ struct PropertyEvaluator { return mapbox::util::apply_visitor(FunctionEvaluator(z), value); } - T operator()(const FadedStopsFunction &value) const { + T operator()(const PiecewiseConstantFunction &value) const { return value.evaluate(z, zoomHistory); } diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 1fc57e2f7e..4dd200aa29 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -344,10 +344,10 @@ std::tuple> StyleParser::parseFunction(JSVal value) { template inline std::chrono::duration defaultDurationValue() { return std::chrono::duration(300.0f); } template -std::tuple> StyleParser::parseFadedStopsFunction(JSVal value) { +std::tuple> StyleParser::parsePiecewiseConstantFunction(JSVal value) { if (!value.HasMember("stops")) { Log::Warning(Event::ParseStyle, "function must specify a function type"); - return std::tuple> { false, {} }; + return std::tuple> { false, {} }; } std::chrono::duration duration = defaultDurationValue(); @@ -364,10 +364,10 @@ std::tuple> StyleParser::parseFadedStopsFunction(JSV auto stops = parseStops(value["stops"]); if (!std::get<0>(stops)) { - return std::tuple> { false, {} }; + return std::tuple> { false, {} }; } - return std::tuple> { true, { std::get<1>(stops), duration } }; + return std::tuple> { true, { std::get<1>(stops), duration } }; } template @@ -554,30 +554,30 @@ template<> std::tuple> StyleParser::parseProperty(JSVal va } } -template<> std::tuple>>> StyleParser::parseProperty(JSVal value, const char *property_name) { +template<> std::tuple>>> StyleParser::parseProperty(JSVal value, const char *property_name) { if (value.IsObject()) { - return parseFadedStopsFunction>>(value); + return parsePiecewiseConstantFunction>>(value); } else if (value.IsArray()) { Faded> parsed; std::tuple> floatarray = parseFloatArray(value); parsed.low = std::get<1>(floatarray); - return std::tuple>>> { std::get<0>(floatarray), parsed }; + return std::tuple>>> { 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>>> { false, {} }; + return std::tuple>>> { false, {} }; } } -template<> std::tuple>> StyleParser::parseProperty(JSVal value, const char *property_name) { +template<> std::tuple>> StyleParser::parseProperty(JSVal value, const char *property_name) { if (value.IsObject()) { - return parseFadedStopsFunction>(value); + return parsePiecewiseConstantFunction>(value); } else if (value.IsString()) { Faded parsed; parsed.low = { value.GetString(), value.GetStringLength() }; - return std::tuple>> { true, parsed }; + return std::tuple>> { true, parsed }; } else { Log::Warning(Event::ParseStyle, "value of '%s' must be string or a string function", property_name); - return std::tuple>> { false, {} }; + return std::tuple>> { false, {} }; } } @@ -724,7 +724,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty>("fill-translate", { Key::FillTranslateX, Key::FillTranslateY }, klass, value); parseOptionalProperty("fill-translate-transition", Key::FillTranslate, klass, value); parseOptionalProperty("fill-translate-anchor", Key::FillTranslateAnchor, klass, value); - parseOptionalProperty>>("fill-image", Key::FillImage, klass, value); + parseOptionalProperty>>("fill-image", Key::FillImage, klass, value); parseOptionalProperty>("line-opacity", Key::LineOpacity, klass, value); parseOptionalProperty("line-opacity-transition", Key::LineOpacity, klass, value); @@ -739,8 +739,8 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("line-gap-width-transition", Key::LineGapWidth, klass, value); parseOptionalProperty>("line-blur", Key::LineBlur, klass, value); parseOptionalProperty("line-blur-transition", Key::LineBlur, klass, value); - parseOptionalProperty>>>("line-dasharray", Key::LineDashArray, klass, value); - parseOptionalProperty>>("line-image", Key::LineImage, klass, value); + parseOptionalProperty>>>("line-dasharray", Key::LineDashArray, klass, value); + parseOptionalProperty>>("line-image", Key::LineImage, klass, value); parseOptionalProperty>("icon-opacity", Key::IconOpacity, klass, value); parseOptionalProperty("icon-opacity-transition", Key::IconOpacity, klass, value); @@ -790,7 +790,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty>("background-opacity", Key::BackgroundOpacity, klass, value); parseOptionalProperty>("background-color", Key::BackgroundColor, klass, value); - parseOptionalProperty>>("background-image", Key::BackgroundImage, klass, value); + parseOptionalProperty>>("background-image", Key::BackgroundImage, klass, value); } void StyleParser::parseLayout(JSVal value, util::ptr &bucket) { diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 5b55d6116e..fd26dc8648 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -79,7 +79,7 @@ private: template std::tuple> parseFunction(JSVal value); template - std::tuple> parseFadedStopsFunction(JSVal value); + std::tuple> parsePiecewiseConstantFunction(JSVal value); template T parseFunctionArgument(JSVal value); template diff --git a/src/mbgl/style/style_properties.hpp b/src/mbgl/style/style_properties.hpp index fd55cb0bb2..f50722542d 100644 --- a/src/mbgl/style/style_properties.hpp +++ b/src/mbgl/style/style_properties.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include #include -- cgit v1.2.1 From 4ec00288562f16f93ea0d46f63291b8bea4d66ac Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 12:08:29 -0800 Subject: switch from low/high to from/to --- src/mbgl/renderer/painter.cpp | 22 ++++++++++----------- src/mbgl/renderer/painter_fill.cpp | 16 +++++++-------- src/mbgl/renderer/painter_line.cpp | 20 +++++++++---------- src/mbgl/style/piecewisefunction_properties.cpp | 26 +++++++++++++------------ src/mbgl/style/style_parser.cpp | 8 ++++---- src/mbgl/style/types.hpp | 8 ++++---- 6 files changed, 51 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 78b6c18e4a..ebb2f77cc5 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -375,12 +375,12 @@ void Painter::renderTileLayer(const Tile& tile, util::ptr layer_desc void Painter::renderBackground(util::ptr layer_desc) { const BackgroundProperties& properties = layer_desc->getProperties(); - if (properties.image.low.size()) { + if (properties.image.to.size()) { if ((properties.opacity >= 1.0f) != (pass == RenderPass::Opaque)) return; - SpriteAtlasPosition imagePosA = spriteAtlas.getPosition(properties.image.low, true); - SpriteAtlasPosition imagePosB = spriteAtlas.getPosition(properties.image.high, true); + SpriteAtlasPosition imagePosA = spriteAtlas.getPosition(properties.image.from, true); + SpriteAtlasPosition imagePosB = spriteAtlas.getPosition(properties.image.to, true); float zoomFraction = state.getZoomFraction(); useProgram(patternShader->program); @@ -401,11 +401,11 @@ void Painter::renderBackground(util::ptr layer_desc) { mat3 matrixA; matrix::identity(matrixA); matrix::scale(matrixA, matrixA, - 1.0f / (sizeA[0] * properties.image.lowScale), - 1.0f / (sizeA[1] * properties.image.lowScale)); + 1.0f / (sizeA[0] * properties.image.fromScale), + 1.0f / (sizeA[1] * properties.image.fromScale)); matrix::translate(matrixA, matrixA, - std::fmod(center[0] * 512, sizeA[0] * properties.image.lowScale), - std::fmod(center[1] * 512, sizeA[1] * properties.image.lowScale)); + std::fmod(center[0] * 512, sizeA[0] * properties.image.fromScale), + std::fmod(center[1] * 512, sizeA[1] * properties.image.fromScale)); matrix::rotate(matrixA, matrixA, -state.getAngle()); matrix::scale(matrixA, matrixA, scale * state.getWidth() / 2, @@ -415,11 +415,11 @@ void Painter::renderBackground(util::ptr layer_desc) { mat3 matrixB; matrix::identity(matrixB); matrix::scale(matrixB, matrixB, - 1.0f / (sizeB[0] * properties.image.highScale), - 1.0f / (sizeB[1] * properties.image.highScale)); + 1.0f / (sizeB[0] * properties.image.toScale), + 1.0f / (sizeB[1] * properties.image.toScale)); matrix::translate(matrixB, matrixB, - std::fmod(center[0] * 512, sizeB[0] * properties.image.highScale), - std::fmod(center[1] * 512, sizeB[1] * properties.image.highScale)); + std::fmod(center[0] * 512, sizeB[0] * properties.image.toScale), + std::fmod(center[1] * 512, sizeB[1] * properties.image.toScale)); matrix::rotate(matrixB, matrixB, -state.getAngle()); matrix::scale(matrixB, matrixB, scale * state.getWidth() / 2, diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 10d4aa3320..9cfe26222b 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -33,13 +33,13 @@ void Painter::renderFill(FillBucket& bucket, util::ptr layer_desc, c stroke_color[3] *= properties.opacity; } - const bool pattern = properties.image.low.size(); + const bool pattern = properties.image.from.size(); bool outline = properties.antialias && !pattern && properties.stroke_color != properties.fill_color; bool fringeline = properties.antialias && !pattern && properties.stroke_color == properties.fill_color; // Because we're drawing top-to-bottom, and we update the stencil mask - // below, we have to draw the outline first (!) + // befrom, we have to draw the outline first (!) if (outline && pass == RenderPass::Translucent) { useProgram(outlineShader->program); outlineShader->u_matrix = vtxMatrix; @@ -59,20 +59,20 @@ void Painter::renderFill(FillBucket& bucket, util::ptr layer_desc, c if (pattern) { // Image fill. if (pass == RenderPass::Translucent) { - const SpriteAtlasPosition posA = spriteAtlas.getPosition(properties.image.low, true); - const SpriteAtlasPosition posB = spriteAtlas.getPosition(properties.image.high, true); + const SpriteAtlasPosition posA = spriteAtlas.getPosition(properties.image.from, true); + const SpriteAtlasPosition posB = spriteAtlas.getPosition(properties.image.to, true); float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z); mat3 patternMatrixA; matrix::identity(patternMatrixA); matrix::scale(patternMatrixA, patternMatrixA, - 1.0f / (posA.size[0] * factor * properties.image.lowScale), - 1.0f / (posA.size[1] * factor * properties.image.lowScale)); + 1.0f / (posA.size[0] * factor * properties.image.fromScale), + 1.0f / (posA.size[1] * factor * properties.image.fromScale)); mat3 patternMatrixB; matrix::identity(patternMatrixB); matrix::scale(patternMatrixB, patternMatrixB, - 1.0f / (posB.size[0] * factor * properties.image.highScale), - 1.0f / (posB.size[1] * factor * properties.image.highScale)); + 1.0f / (posB.size[0] * factor * properties.image.toScale), + 1.0f / (posB.size[1] * factor * properties.image.toScale)); useProgram(patternShader->program); patternShader->u_matrix = vtxMatrix; diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 149683cbcd..a66da1fcd6 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -70,7 +70,7 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c bucket.drawPoints(*linejoinShader); } - if (properties.dash_array.low.size()) { + if (properties.dash_array.from.size()) { useProgram(linesdfShader->program); @@ -81,14 +81,14 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c linesdfShader->u_blur = blur; linesdfShader->u_color = color; - 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); + LinePatternPos posA = lineAtlas.getDashPosition(properties.dash_array.from, bucket.properties.cap == CapType::Round); + LinePatternPos posB = lineAtlas.getDashPosition(properties.dash_array.to, bucket.properties.cap == CapType::Round); lineAtlas.bind(); float patternratio = std::pow(2.0, std::floor(std::log2(state.getScale())) - id.z) / 8.0; - float scaleXA = patternratio / posA.width / properties.dash_line_width / properties.dash_array.lowScale; + float scaleXA = patternratio / posA.width / properties.dash_line_width / properties.dash_array.fromScale; float scaleYA = -posA.height / 2.0; - float scaleXB = patternratio / posB.width / properties.dash_line_width / properties.dash_array.highScale; + float scaleXB = patternratio / posB.width / properties.dash_line_width / properties.dash_array.toScale; float scaleYB = -posB.height / 2.0; linesdfShader->u_patternscale_a = {{ scaleXA, scaleYA }}; @@ -101,9 +101,9 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c bucket.drawLineSDF(*linesdfShader); - } else if (properties.image.low.size()) { - SpriteAtlasPosition imagePosA = spriteAtlas.getPosition(properties.image.low, true); - SpriteAtlasPosition imagePosB = spriteAtlas.getPosition(properties.image.high, true); + } else if (properties.image.from.size()) { + SpriteAtlasPosition imagePosA = spriteAtlas.getPosition(properties.image.from, true); + SpriteAtlasPosition imagePosB = spriteAtlas.getPosition(properties.image.to, true); float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z); @@ -115,10 +115,10 @@ void Painter::renderLine(LineBucket& bucket, util::ptr layer_desc, c linepatternShader->u_ratio = ratio; linepatternShader->u_blur = blur; - linepatternShader->u_pattern_size_a = {{imagePosA.size[0] * factor * properties.image.lowScale, imagePosA.size[1]}}; + linepatternShader->u_pattern_size_a = {{imagePosA.size[0] * factor * properties.image.fromScale, imagePosA.size[1]}}; linepatternShader->u_pattern_tl_a = imagePosA.tl; linepatternShader->u_pattern_br_a = imagePosA.br; - linepatternShader->u_pattern_size_b = {{imagePosB.size[0] * factor * properties.image.highScale, imagePosB.size[1]}}; + linepatternShader->u_pattern_size_b = {{imagePosB.size[0] * factor * properties.image.toScale, imagePosB.size[1]}}; linepatternShader->u_pattern_tl_b = imagePosB.tl; linepatternShader->u_pattern_br_b = imagePosB.br; linepatternShader->u_fade = properties.image.t; diff --git a/src/mbgl/style/piecewisefunction_properties.cpp b/src/mbgl/style/piecewisefunction_properties.cpp index e760ebdb13..86d02e7b12 100644 --- a/src/mbgl/style/piecewisefunction_properties.cpp +++ b/src/mbgl/style/piecewisefunction_properties.cpp @@ -21,26 +21,28 @@ T PiecewiseConstantFunction::evaluate(float z, const ZoomHistory &zh) const { float fraction = std::fmod(z, 1.0f); float t = std::min((std::chrono::steady_clock::now() - zh.lastIntegerZoomTime) / duration, 1.0f); - float scale = 1.0f; - uint32_t low, high; + float fromScale = 1.0f; + float toScale = 1.0f; + uint32_t from, to; if (z > zh.lastIntegerZoom) { result.t = fraction + (1.0f - fraction) * t; - scale *= 2.0f; - low = getBiggestStopLessThan(values, z - 1.0f); - high = getBiggestStopLessThan(values, z); + from = getBiggestStopLessThan(values, z - 1.0f); + to = getBiggestStopLessThan(values, z); + fromScale *= 2.0f; } else { - result.t = fraction - fraction * t; - low = getBiggestStopLessThan(values, z); - high = getBiggestStopLessThan(values, z + 1.0f); + result.t = 1 - (1 - t) * fraction; + to = getBiggestStopLessThan(values, z); + from = getBiggestStopLessThan(values, z + 1.0f); + fromScale /= 2.0f; } - result.low = values[low].second.low; - result.high = values[high].second.low; - result.lowScale = scale; - result.highScale = scale / 2; + result.from = values[from].second.to; + result.to = values[to].second.to; + result.fromScale = fromScale; + result.toScale = toScale; return result; } diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 4dd200aa29..c6d3c86664 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -261,7 +261,7 @@ template <> Faded> StyleParser::parseFunctionArgument(JSVal value) { Faded> parsed; JSVal rvalue = replaceConstant(value); - parsed.low = std::get<1>(parseFloatArray(rvalue)); + parsed.to = std::get<1>(parseFloatArray(rvalue)); return parsed; } @@ -270,7 +270,7 @@ Faded StyleParser::parseFunctionArgument(JSVal value) { JSVal rvalue = replaceConstant(value); if (rvalue.IsString()) { Faded parsed; - parsed.low = { value.GetString(), value.GetStringLength() }; + parsed.to = { value.GetString(), value.GetStringLength() }; return parsed; } else { Log::Warning(Event::ParseStyle, "function argument must be a string"); @@ -560,7 +560,7 @@ template<> std::tuple>> } else if (value.IsArray()) { Faded> parsed; std::tuple> floatarray = parseFloatArray(value); - parsed.low = std::get<1>(floatarray); + parsed.to = std::get<1>(floatarray); return std::tuple>>> { 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); @@ -573,7 +573,7 @@ template<> std::tuple>> Style return parsePiecewiseConstantFunction>(value); } else if (value.IsString()) { Faded parsed; - parsed.low = { value.GetString(), value.GetStringLength() }; + parsed.to = { value.GetString(), value.GetStringLength() }; return std::tuple>> { true, parsed }; } else { Log::Warning(Event::ParseStyle, "value of '%s' must be string or a string function", property_name); diff --git a/src/mbgl/style/types.hpp b/src/mbgl/style/types.hpp index b7d675857a..78938a2823 100644 --- a/src/mbgl/style/types.hpp +++ b/src/mbgl/style/types.hpp @@ -14,10 +14,10 @@ typedef std::array Color; template struct Faded { - T low; - float lowScale; - T high; - float highScale; + T from; + float fromScale; + T to; + float toScale; float t; }; -- cgit v1.2.1 From a49737e542dc518076add81fca7d02c0a9449ae7 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 13:51:52 -0800 Subject: fix durations by making them milliseconds --- src/mbgl/style/piecewisefunction_properties.hpp | 4 ++-- src/mbgl/style/style_parser.cpp | 4 ++-- src/mbgl/style/zoom_history.hpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/piecewisefunction_properties.hpp b/src/mbgl/style/piecewisefunction_properties.hpp index 69ddc7cc2a..769020002e 100644 --- a/src/mbgl/style/piecewisefunction_properties.hpp +++ b/src/mbgl/style/piecewisefunction_properties.hpp @@ -10,8 +10,8 @@ namespace mbgl { template struct PiecewiseConstantFunction { inline PiecewiseConstantFunction(const std::vector> &values_, std::chrono::duration duration_) : values(values_), duration(duration_) {} - inline PiecewiseConstantFunction(T &value) : values({{ 0, value }}), duration(300) {} - inline PiecewiseConstantFunction() : values(), duration(300) {} + inline PiecewiseConstantFunction(T &value) : values({{ 0, value }}), duration(std::chrono::milliseconds(300)) {} + inline PiecewiseConstantFunction() : values(), duration(std::chrono::milliseconds(300)) {} T evaluate(float z, const ZoomHistory &zoomHistory) const; private: diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index c6d3c86664..a334cecc05 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -341,7 +341,7 @@ std::tuple> StyleParser::parseFunction(JSVal value) { return std::tuple> { true, StopsFunction(std::get<1>(stops), base) }; } -template inline std::chrono::duration defaultDurationValue() { return std::chrono::duration(300.0f); } +template inline std::chrono::duration defaultDurationValue() { return std::chrono::milliseconds(300); } template std::tuple> StyleParser::parsePiecewiseConstantFunction(JSVal value) { @@ -355,7 +355,7 @@ std::tuple> StyleParser::parsePiecewiseConsta if (value.HasMember("duration")) { JSVal value_duration = value["duration"]; if (value_duration.IsNumber()) { - duration = static_cast>(value_duration.GetDouble()); + duration = std::chrono::milliseconds(value_duration.GetUint()); } else { Log::Warning(Event::ParseStyle, "duration must be numeric"); } diff --git a/src/mbgl/style/zoom_history.hpp b/src/mbgl/style/zoom_history.hpp index eee0d9b443..2488687108 100644 --- a/src/mbgl/style/zoom_history.hpp +++ b/src/mbgl/style/zoom_history.hpp @@ -17,7 +17,7 @@ struct ZoomHistory { first = false; lastIntegerZoom = std::floor(z); - lastIntegerZoomTime = std::chrono::steady_clock::time_point::min(); + lastIntegerZoomTime = std::chrono::steady_clock::time_point(std::chrono::steady_clock::duration(0)); lastZoom = z; } -- cgit v1.2.1 From f07de8dd23779319909f20f9da384eaf46aa4ca3 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 15:30:51 -0800 Subject: make pattern and dasharray properties use duration from "*-transition" properties --- src/mbgl/style/piecewisefunction_properties.cpp | 4 +- src/mbgl/style/piecewisefunction_properties.hpp | 2 +- src/mbgl/style/style_parser.cpp | 76 ++++++++++++++++--------- src/mbgl/style/style_parser.hpp | 8 ++- 4 files changed, 59 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/piecewisefunction_properties.cpp b/src/mbgl/style/piecewisefunction_properties.cpp index 86d02e7b12..72ed0b8f73 100644 --- a/src/mbgl/style/piecewisefunction_properties.cpp +++ b/src/mbgl/style/piecewisefunction_properties.cpp @@ -6,7 +6,7 @@ namespace mbgl { template -uint32_t getBiggestStopLessThan(std::vector> stops, float z) { +size_t getBiggestStopLessThan(std::vector> stops, float z) { for (uint32_t i = 0; i < stops.size(); i++) { if (stops[i].first > z) { return i == 0 ? i : i - 1; @@ -23,7 +23,7 @@ T PiecewiseConstantFunction::evaluate(float z, const ZoomHistory &zh) const { float t = std::min((std::chrono::steady_clock::now() - zh.lastIntegerZoomTime) / duration, 1.0f); float fromScale = 1.0f; float toScale = 1.0f; - uint32_t from, to; + size_t from, to; if (z > zh.lastIntegerZoom) { result.t = fraction + (1.0f - fraction) * t; diff --git a/src/mbgl/style/piecewisefunction_properties.hpp b/src/mbgl/style/piecewisefunction_properties.hpp index 769020002e..0440655ba5 100644 --- a/src/mbgl/style/piecewisefunction_properties.hpp +++ b/src/mbgl/style/piecewisefunction_properties.hpp @@ -10,7 +10,7 @@ namespace mbgl { template struct PiecewiseConstantFunction { inline PiecewiseConstantFunction(const std::vector> &values_, std::chrono::duration duration_) : values(values_), duration(duration_) {} - inline PiecewiseConstantFunction(T &value) : values({{ 0, value }}), duration(std::chrono::milliseconds(300)) {} + inline PiecewiseConstantFunction(T &value, std::chrono::duration duration_) : values({{ 0, value }}), duration(duration_) {} inline PiecewiseConstantFunction() : values(), duration(std::chrono::milliseconds(300)) {} T evaluate(float z, const ZoomHistory &zoomHistory) const; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index a334cecc05..89a266a18a 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -268,13 +268,13 @@ Faded> StyleParser::parseFunctionArgument(JSVal value) { template <> Faded StyleParser::parseFunctionArgument(JSVal value) { JSVal rvalue = replaceConstant(value); + Faded parsed; if (rvalue.IsString()) { - Faded parsed; parsed.to = { value.GetString(), value.GetStringLength() }; return parsed; } else { Log::Warning(Event::ParseStyle, "function argument must be a string"); - return {}; + return parsed; } } @@ -308,7 +308,7 @@ std::tuple>> StyleParser::parseStops(JSVal return std::tuple>> { false, {}}; } } - return { true, stops }; + return std::tuple>>(true, stops); } template inline float defaultBaseValue() { return 1.75; } @@ -341,26 +341,13 @@ std::tuple> StyleParser::parseFunction(JSVal value) { return std::tuple> { true, StopsFunction(std::get<1>(stops), base) }; } -template inline std::chrono::duration defaultDurationValue() { return std::chrono::milliseconds(300); } - template -std::tuple> StyleParser::parsePiecewiseConstantFunction(JSVal value) { +std::tuple> StyleParser::parsePiecewiseConstantFunction(JSVal value, std::chrono::steady_clock::duration duration) { if (!value.HasMember("stops")) { Log::Warning(Event::ParseStyle, "function must specify a function type"); return std::tuple> { false, {} }; } - std::chrono::duration duration = defaultDurationValue(); - - if (value.HasMember("duration")) { - JSVal value_duration = value["duration"]; - if (value_duration.IsNumber()) { - duration = std::chrono::milliseconds(value_duration.GetUint()); - } else { - Log::Warning(Event::ParseStyle, "duration must be numeric"); - } - } - auto stops = parseStops(value["stops"]); if (!std::get<0>(stops)) { @@ -379,6 +366,15 @@ bool StyleParser::setProperty(JSVal value, const char *property_name, PropertyKe return std::get<0>(res); } +template +bool StyleParser::setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass, JSVal transition) { + auto res = parseProperty(value, property_name, transition); + if (std::get<0>(res)) { + klass.set(key, std::get<1>(res)); + } + return std::get<0>(res); +} + template void StyleParser::parseVisibility(StyleBucket &bucket, JSVal value) { if (!value.HasMember("visibility")) { @@ -400,6 +396,21 @@ bool StyleParser::parseOptionalProperty(const char *property_name, PropertyKey k } } +template +bool StyleParser::parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value, const char *transition_name) { + if (!value.HasMember(property_name)) { + return false; + } else { + if (value.HasMember(transition_name)) { + return setProperty(replaceConstant(value[property_name]), property_name, key, klass, value[transition_name]); + } else { + JSVal val(rapidjson::kObjectType); + return setProperty(replaceConstant(value[property_name]), property_name, key, klass, val); + } + } +} + + template<> std::tuple StyleParser::parseProperty(JSVal value, const char *property_name) { if (!value.IsString()) { Log::Warning(Event::ParseStyle, "value of '%s' must be a string", property_name); @@ -554,27 +565,38 @@ template<> std::tuple> StyleParser::parseProperty(JSVal va } } -template<> std::tuple>>> StyleParser::parseProperty(JSVal value, const char *property_name) { +template<> std::tuple>>> StyleParser::parseProperty(JSVal value, const char *property_name, JSVal transition) { + std::chrono::steady_clock::duration duration = std::chrono::milliseconds(300); + if (transition.HasMember("duration")) { + duration = std::chrono::milliseconds(transition["duration"].GetUint()); + } + if (value.IsObject()) { - return parsePiecewiseConstantFunction>>(value); + return parsePiecewiseConstantFunction>>(value, duration); } else if (value.IsArray()) { Faded> parsed; std::tuple> floatarray = parseFloatArray(value); parsed.to = std::get<1>(floatarray); - return std::tuple>>> { std::get<0>(floatarray), parsed }; + return std::tuple>>> { std::get<0>(floatarray), { parsed, duration } }; } else { Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers, or a number array function", property_name); return std::tuple>>> { false, {} }; } } -template<> std::tuple>> StyleParser::parseProperty(JSVal value, const char *property_name) { +template<> std::tuple>> StyleParser::parseProperty(JSVal value, const char *property_name, JSVal transition) { + + std::chrono::steady_clock::duration duration = std::chrono::milliseconds(300); + if (transition.HasMember("duration")) { + duration = std::chrono::milliseconds(transition["duration"].GetUint()); + } + if (value.IsObject()) { - return parsePiecewiseConstantFunction>(value); + return parsePiecewiseConstantFunction>(value, duration); } else if (value.IsString()) { Faded parsed; parsed.to = { value.GetString(), value.GetStringLength() }; - return std::tuple>> { true, parsed }; + return std::tuple>> { true, { parsed, duration } }; } else { Log::Warning(Event::ParseStyle, "value of '%s' must be string or a string function", property_name); return std::tuple>> { false, {} }; @@ -724,7 +746,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty>("fill-translate", { Key::FillTranslateX, Key::FillTranslateY }, klass, value); parseOptionalProperty("fill-translate-transition", Key::FillTranslate, klass, value); parseOptionalProperty("fill-translate-anchor", Key::FillTranslateAnchor, klass, value); - parseOptionalProperty>>("fill-image", Key::FillImage, klass, value); + parseOptionalProperty>>("fill-image", Key::FillImage, klass, value, "fill-image-transition"); parseOptionalProperty>("line-opacity", Key::LineOpacity, klass, value); parseOptionalProperty("line-opacity-transition", Key::LineOpacity, klass, value); @@ -739,8 +761,8 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("line-gap-width-transition", Key::LineGapWidth, klass, value); parseOptionalProperty>("line-blur", Key::LineBlur, klass, value); parseOptionalProperty("line-blur-transition", Key::LineBlur, klass, value); - parseOptionalProperty>>>("line-dasharray", Key::LineDashArray, klass, value); - parseOptionalProperty>>("line-image", Key::LineImage, klass, value); + parseOptionalProperty>>>("line-dasharray", Key::LineDashArray, klass, value, "line-dasharray-transition"); + parseOptionalProperty>>("line-image", Key::LineImage, klass, value, "line-image-transition"); parseOptionalProperty>("icon-opacity", Key::IconOpacity, klass, value); parseOptionalProperty("icon-opacity-transition", Key::IconOpacity, klass, value); @@ -790,7 +812,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty>("background-opacity", Key::BackgroundOpacity, klass, value); parseOptionalProperty>("background-color", Key::BackgroundColor, klass, value); - parseOptionalProperty>>("background-image", Key::BackgroundImage, klass, value); + parseOptionalProperty>>("background-image", Key::BackgroundImage, klass, value, "background-image-transition"); } void StyleParser::parseLayout(JSVal value, util::ptr &bucket) { diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index fd26dc8648..d25c705792 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -69,17 +69,23 @@ private: template bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value); template + bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value, const char *transition_name); + template bool parseOptionalProperty(const char *property_name, const std::vector &keys, ClassProperties &klass, JSVal value); template bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass); + template + bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass, JSVal transition); template std::tuple parseProperty(JSVal value, const char *property_name); + template + std::tuple parseProperty(JSVal value, const char *property_name, JSVal transition); template std::tuple> parseFunction(JSVal value); template - std::tuple> parsePiecewiseConstantFunction(JSVal value); + std::tuple> parsePiecewiseConstantFunction(JSVal value, std::chrono::steady_clock::duration duration); template T parseFunctionArgument(JSVal value); template -- cgit v1.2.1 From 6e95c3b2e189e91a6244eef58ad1057258b2724b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 19:47:31 -0800 Subject: fix compilation on android --- src/mbgl/style/style_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 89a266a18a..4120ef470b 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -404,7 +404,7 @@ bool StyleParser::parseOptionalProperty(const char *property_name, PropertyKey k if (value.HasMember(transition_name)) { return setProperty(replaceConstant(value[property_name]), property_name, key, klass, value[transition_name]); } else { - JSVal val(rapidjson::kObjectType); + JSVal val = JSVal(rapidjson::kObjectType); return setProperty(replaceConstant(value[property_name]), property_name, key, klass, val); } } -- cgit v1.2.1 From 3a8aaad6a799fd4ab1feb47a47a7ffa0d05c1cc0 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 15:56:46 -0800 Subject: make everything a function --- src/mbgl/style/function_properties.cpp | 20 ++++ src/mbgl/style/property_value.hpp | 21 ++--- src/mbgl/style/style_parser.cpp | 162 +++++++++++++++++---------------- src/mbgl/style/style_parser.hpp | 4 +- src/mbgl/util/interpolate.hpp | 20 +++- 5 files changed, 133 insertions(+), 94 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/function_properties.cpp b/src/mbgl/style/function_properties.cpp index 81b1c85c72..2ea3682b8f 100644 --- a/src/mbgl/style/function_properties.cpp +++ b/src/mbgl/style/function_properties.cpp @@ -14,6 +14,16 @@ template <> inline float defaultStopsValue() { return 1.0f; } template <> inline Color defaultStopsValue() { return {{ 0, 0, 0, 1 }}; } template <> inline std::vector defaultStopsValue() { return {{ 1, 0 }}; } +template <> inline std:: string defaultStopsValue() { return {}; } +template <> inline TranslateAnchorType defaultStopsValue() { return {}; }; +template <> inline RotateAnchorType defaultStopsValue() { return {}; }; +template <> inline CapType defaultStopsValue() { return {}; }; +template <> inline JoinType defaultStopsValue() { return {}; }; +template <> inline PlacementType defaultStopsValue() { return {}; }; +template <> inline TextAnchorType defaultStopsValue() { return {}; }; +template <> inline TextJustifyType defaultStopsValue() { return {}; }; +template <> inline TextTransformType defaultStopsValue() { return {}; }; +template <> inline RotationAlignmentType defaultStopsValue() { return {}; }; template T StopsFunction::evaluate(float z) const { @@ -67,4 +77,14 @@ template float StopsFunction::evaluate(float z) const; template Color StopsFunction::evaluate(float z) const; template std::vector StopsFunction>::evaluate(float z) const; +template std::string StopsFunction::evaluate(float z) const; +template TranslateAnchorType StopsFunction::evaluate(float z) const; +template RotateAnchorType StopsFunction::evaluate(float z) const; +template CapType StopsFunction::evaluate(float z) const; +template JoinType StopsFunction::evaluate(float z) const; +template PlacementType StopsFunction::evaluate(float z) const; +template TextAnchorType StopsFunction::evaluate(float z) const; +template TextJustifyType StopsFunction::evaluate(float z) const; +template TextTransformType StopsFunction::evaluate(float z) const; +template RotationAlignmentType StopsFunction::evaluate(float z) const; } diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp index c7fe823025..00f72ea643 100644 --- a/src/mbgl/style/property_value.hpp +++ b/src/mbgl/style/property_value.hpp @@ -11,18 +11,17 @@ namespace mbgl { typedef mapbox::util::variant< - std::string, - TranslateAnchorType, - RotateAnchorType, - bool, - CapType, - JoinType, + Function, + Function, + Function, + Function, + Function, VisibilityType, - PlacementType, - RotationAlignmentType, - TextTransformType, - TextJustifyType, - TextAnchorType, + Function, + Function, + Function, + Function, + Function, Function, Function, Function, diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 4120ef470b..15a9f64aad 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -228,53 +228,40 @@ std::tuple> parseFloatArray(JSVal value) { } template <> -bool StyleParser::parseFunctionArgument(JSVal value) { - JSVal rvalue = replaceConstant(value); - if (rvalue.IsBool()) { - return rvalue.GetBool(); - } else if (rvalue.IsNumber()) { - return rvalue.GetDouble(); - } else { - Log::Warning(Event::ParseStyle, "function argument must be a boolean or numeric value"); - return false; - } -} - -template <> -float StyleParser::parseFunctionArgument(JSVal value) { +std::tuple StyleParser::parseProperty(JSVal value, const char*) { JSVal rvalue = replaceConstant(value); if (rvalue.IsNumber()) { - return rvalue.GetDouble(); + return { true, rvalue.GetDouble() }; } else { Log::Warning(Event::ParseStyle, "function argument must be a numeric value"); - return 0.0f; + return { false, 0.0f }; } } template <> -Color StyleParser::parseFunctionArgument(JSVal value) { +std::tuple StyleParser::parseProperty(JSVal value, const char*) { JSVal rvalue = replaceConstant(value); - return parseColor(rvalue); + return { true, parseColor(rvalue) }; } template <> -Faded> StyleParser::parseFunctionArgument(JSVal value) { +std::tuple>> StyleParser::parseProperty(JSVal value, const char*) { Faded> parsed; JSVal rvalue = replaceConstant(value); parsed.to = std::get<1>(parseFloatArray(rvalue)); - return parsed; + return { true, parsed }; } template <> -Faded StyleParser::parseFunctionArgument(JSVal value) { +std::tuple> StyleParser::parseProperty(JSVal value, const char*) { JSVal rvalue = replaceConstant(value); Faded parsed; if (rvalue.IsString()) { parsed.to = { value.GetString(), value.GetStringLength() }; - return parsed; + return { true, parsed }; } else { Log::Warning(Event::ParseStyle, "function argument must be a string"); - return parsed; + return { false, parsed }; } } @@ -302,7 +289,7 @@ std::tuple>> StyleParser::parseStops(JSVal return std::tuple>> { false, {}}; } - stops.emplace_back(z.GetDouble(), parseFunctionArgument(stop[rapidjson::SizeType(1)])); + stops.emplace_back(z.GetDouble(), std::get<1>(parseProperty(replaceConstant(stop[rapidjson::SizeType(1)]), ""))); } else { Log::Warning(Event::ParseStyle, "function argument must be a numeric value"); return std::tuple>> { false, {}}; @@ -315,7 +302,12 @@ template inline float defaultBaseValue() { return 1.75; } template <> inline float defaultBaseValue() { return 1.0; } template -std::tuple> StyleParser::parseFunction(JSVal value) { +std::tuple> StyleParser::parseFunction(JSVal value, const char *) { + + if (!value.IsObject()) { + return std::tuple> { true, ConstantFunction(std::get<1>(parseProperty(value, ""))) }; + } + if (!value.HasMember("stops")) { Log::Warning(Event::ParseStyle, "function must specify a function type"); return std::tuple> { false, ConstantFunction(T()) }; @@ -528,41 +520,57 @@ template<> std::tuple StyleParser::parseProperty(JSVal return std::tuple { true, std::move(transition) }; } +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + +template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction(value, property_name); +} + + template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { - if (value.IsObject()) { - return parseFunction(value); - } else if (value.IsNumber()) { - return std::tuple> { true, ConstantFunction(value.GetDouble()) }; - } else if (value.IsBool()) { - return std::tuple> { true, ConstantFunction(value.GetBool()) }; - } else { - Log::Warning(Event::ParseStyle, "value of '%s' must be convertible to boolean, or a boolean function", property_name); - return std::tuple> { false, ConstantFunction(false) }; - } + return parseFunction(value, property_name); } template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { - if (value.IsObject()) { - return parseFunction(value); - } else if (value.IsNumber()) { - return std::tuple> { true, ConstantFunction(value.GetDouble()) }; - } else if (value.IsBool()) { - return std::tuple> { true, ConstantFunction(value.GetBool()) }; - } else { - Log::Warning(Event::ParseStyle, "value of '%s' must be a number, or a number function", property_name); - return std::tuple> { false, ConstantFunction(0) }; - } + return parseFunction(value, property_name); } template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { - if (value.IsObject()) { - return parseFunction(value); - } else if (value.IsString()) { - return std::tuple> { true, ConstantFunction(parseColor(value)) }; - } else { - Log::Warning(Event::ParseStyle, "value of '%s' must be a color, or a color function", property_name); - return std::tuple> { false, ConstantFunction(Color {{ 0, 0, 0, 0 }}) }; - } + return parseFunction(value, property_name); } template<> std::tuple>>> StyleParser::parseProperty(JSVal value, const char *property_name, JSVal transition) { @@ -745,7 +753,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("fill-outline-color-transition", Key::FillOutlineColor, klass, value); parseOptionalProperty>("fill-translate", { Key::FillTranslateX, Key::FillTranslateY }, klass, value); parseOptionalProperty("fill-translate-transition", Key::FillTranslate, klass, value); - parseOptionalProperty("fill-translate-anchor", Key::FillTranslateAnchor, klass, value); + parseOptionalProperty>("fill-translate-anchor", Key::FillTranslateAnchor, klass, value); parseOptionalProperty>>("fill-image", Key::FillImage, klass, value, "fill-image-transition"); parseOptionalProperty>("line-opacity", Key::LineOpacity, klass, value); @@ -754,7 +762,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("line-color-transition", Key::LineColor, klass, value); parseOptionalProperty>("line-translate", { Key::LineTranslateX, Key::LineTranslateY }, klass, value); parseOptionalProperty("line-translate-transition", Key::LineTranslate, klass, value); - parseOptionalProperty("line-translate-anchor", Key::LineTranslateAnchor, klass, value); + parseOptionalProperty>("line-translate-anchor", Key::LineTranslateAnchor, klass, value); parseOptionalProperty>("line-width", Key::LineWidth, klass, value); parseOptionalProperty("line-width-transition", Key::LineWidth, klass, value); parseOptionalProperty>("line-gap-width", Key::LineGapWidth, klass, value); @@ -779,7 +787,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("icon-halo-blur-transition", Key::IconHaloBlur, klass, value); parseOptionalProperty>("icon-translate", { Key::IconTranslateX, Key::IconTranslateY }, klass, value); parseOptionalProperty("icon-translate-transition", Key::IconTranslate, klass, value); - parseOptionalProperty("icon-translate-anchor", Key::IconTranslateAnchor, klass, value); + parseOptionalProperty>("icon-translate-anchor", Key::IconTranslateAnchor, klass, value); parseOptionalProperty>("text-opacity", Key::TextOpacity, klass, value); parseOptionalProperty("text-opacity-transition", Key::TextOpacity, klass, value); @@ -795,7 +803,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("text-halo-blur-transition", Key::TextHaloBlur, klass, value); parseOptionalProperty>("text-translate", { Key::TextTranslateX, Key::TextTranslateY }, klass, value); parseOptionalProperty("text-translate-transition", Key::TextTranslate, klass, value); - parseOptionalProperty("text-translate-anchor", Key::TextTranslateAnchor, klass, value); + parseOptionalProperty>("text-translate-anchor", Key::TextTranslateAnchor, klass, value); parseOptionalProperty>("raster-opacity", Key::RasterOpacity, klass, value); parseOptionalProperty("raster-opacity-transition", Key::RasterOpacity, klass, value); @@ -820,42 +828,42 @@ void StyleParser::parseLayout(JSVal value, util::ptr &bucket) { parseVisibility(*bucket, value); - parseOptionalProperty("line-cap", Key::LineCap, bucket->layout, value); - parseOptionalProperty("line-join", Key::LineJoin, bucket->layout, value); + parseOptionalProperty>("line-cap", Key::LineCap, bucket->layout, value); + parseOptionalProperty>("line-join", Key::LineJoin, bucket->layout, value); parseOptionalProperty>("line-miter-limit", Key::LineMiterLimit, bucket->layout, value); parseOptionalProperty>("line-round-limit", Key::LineRoundLimit, bucket->layout, value); - parseOptionalProperty("symbol-placement", Key::SymbolPlacement, bucket->layout, value); + parseOptionalProperty>("symbol-placement", Key::SymbolPlacement, bucket->layout, value); parseOptionalProperty>("symbol-min-distance", Key::SymbolMinDistance, bucket->layout, value); - parseOptionalProperty("symbol-avoid-edges", Key::SymbolAvoidEdges, bucket->layout, value); - parseOptionalProperty("icon-allow-overlap", Key::IconAllowOverlap, bucket->layout, value); - parseOptionalProperty("icon-ignore-placement", Key::IconIgnorePlacement, bucket->layout, value); - parseOptionalProperty("icon-optional", Key::IconOptional, bucket->layout, value); - parseOptionalProperty("icon-rotation-alignment", Key::IconRotationAlignment, bucket->layout, value); + parseOptionalProperty>("symbol-avoid-edges", Key::SymbolAvoidEdges, bucket->layout, value); + parseOptionalProperty>("icon-allow-overlap", Key::IconAllowOverlap, bucket->layout, value); + parseOptionalProperty>("icon-ignore-placement", Key::IconIgnorePlacement, bucket->layout, value); + parseOptionalProperty>("icon-optional", Key::IconOptional, bucket->layout, value); + parseOptionalProperty>("icon-rotation-alignment", Key::IconRotationAlignment, bucket->layout, value); parseOptionalProperty>("icon-max-size", Key::IconMaxSize, bucket->layout, value); - parseOptionalProperty("icon-image", Key::IconImage, bucket->layout, value); + parseOptionalProperty>("icon-image", Key::IconImage, bucket->layout, value); parseOptionalProperty>("icon-rotate", Key::IconRotate, bucket->layout, value); parseOptionalProperty>("icon-padding", Key::IconPadding, bucket->layout, value); - parseOptionalProperty("icon-keep-upright", Key::IconKeepUpright, bucket->layout, value); + parseOptionalProperty>("icon-keep-upright", Key::IconKeepUpright, bucket->layout, value); parseOptionalProperty>("icon-offset", { Key::IconOffsetX, Key::IconOffsetY }, bucket->layout, value); - parseOptionalProperty("text-rotation-alignment", Key::TextRotationAlignment, bucket->layout, value); - parseOptionalProperty("text-field", Key::TextField, bucket->layout, value); - parseOptionalProperty("text-font", Key::TextFont, bucket->layout, value); + parseOptionalProperty>("text-rotation-alignment", Key::TextRotationAlignment, bucket->layout, value); + parseOptionalProperty>("text-field", Key::TextField, bucket->layout, value); + parseOptionalProperty>("text-font", Key::TextFont, bucket->layout, value); parseOptionalProperty>("text-max-size", Key::TextMaxSize, bucket->layout, value); parseOptionalProperty>("text-max-width", Key::TextMaxWidth, bucket->layout, value); parseOptionalProperty>("text-line-height", Key::TextLineHeight, bucket->layout, value); parseOptionalProperty>("text-letter-spacing", Key::TextLetterSpacing, bucket->layout, value); - parseOptionalProperty("text-justify", Key::TextJustify, bucket->layout, value); - parseOptionalProperty("text-anchor", Key::TextAnchor, bucket->layout, value); + parseOptionalProperty>("text-justify", Key::TextJustify, bucket->layout, value); + parseOptionalProperty>("text-anchor", Key::TextAnchor, bucket->layout, value); parseOptionalProperty>("text-max-angle", Key::TextMaxAngle, bucket->layout, value); parseOptionalProperty>("text-rotate", Key::TextRotate, bucket->layout, value); parseOptionalProperty>("text-padding", Key::TextPadding, bucket->layout, value); - parseOptionalProperty("text-keep-upright", Key::TextKeepUpright, bucket->layout, value); - parseOptionalProperty("text-transform", Key::TextTransform, bucket->layout, value); + parseOptionalProperty>("text-keep-upright", Key::TextKeepUpright, bucket->layout, value); + parseOptionalProperty>("text-transform", Key::TextTransform, bucket->layout, value); parseOptionalProperty>("text-offset", { Key::TextOffsetX, Key::TextOffsetY }, bucket->layout, value); - parseOptionalProperty("text-allow-overlap", Key::TextAllowOverlap, bucket->layout, value); - parseOptionalProperty("text-ignore-placement", Key::TextIgnorePlacement, bucket->layout, value); - parseOptionalProperty("text-optional", Key::TextOptional, bucket->layout, value); + parseOptionalProperty>("text-allow-overlap", Key::TextAllowOverlap, bucket->layout, value); + parseOptionalProperty>("text-ignore-placement", Key::TextIgnorePlacement, bucket->layout, value); + parseOptionalProperty>("text-optional", Key::TextOptional, bucket->layout, value); } diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index d25c705792..a32e6dd1d3 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -83,12 +83,10 @@ private: std::tuple parseProperty(JSVal value, const char *property_name, JSVal transition); template - std::tuple> parseFunction(JSVal value); + std::tuple> parseFunction(JSVal value, const char *); template std::tuple> parsePiecewiseConstantFunction(JSVal value, std::chrono::steady_clock::duration duration); template - T parseFunctionArgument(JSVal value); - template std::tuple>> parseStops(JSVal value); FilterExpression parseFilter(JSVal); diff --git a/src/mbgl/util/interpolate.hpp b/src/mbgl/util/interpolate.hpp index 952d7b9c10..a2998233b5 100644 --- a/src/mbgl/util/interpolate.hpp +++ b/src/mbgl/util/interpolate.hpp @@ -4,6 +4,8 @@ #include #include +#include + namespace mbgl { namespace util { @@ -22,9 +24,21 @@ inline std::array interpolate(const std::array& a, const std::array< }}; } -inline std::vector interpolate(const std::vector &a, const std::vector, const double) { - return a; -} +// fake interpolations that just return the first value +template<> inline bool interpolate(const bool a, const bool, const double) { return a; } +template<> inline std::vector interpolate(const std::vector a, const std::vector, const double) { return a; } +template<> inline std::string interpolate(const std::string a, const std::string, const double) { return a; } +template<> inline TranslateAnchorType interpolate(const TranslateAnchorType a, const TranslateAnchorType, const double) { return a; } +template<> inline RotateAnchorType interpolate(const RotateAnchorType a, const RotateAnchorType, const double) { return a; } +template<> inline CapType interpolate(const CapType a, const CapType, const double) { return a; } +template<> inline JoinType interpolate(const JoinType a, const JoinType, const double) { return a; } +template<> inline PlacementType interpolate(const PlacementType a, const PlacementType, const double) { return a; } +template<> inline TextAnchorType interpolate(const TextAnchorType a, const TextAnchorType, const double) { return a; } +template<> inline TextJustifyType interpolate(const TextJustifyType a, const TextJustifyType, const double) { return a; } +template<> inline TextTransformType interpolate(const TextTransformType a, const TextTransformType, const double) { return a; } +template<> inline RotationAlignmentType interpolate(const RotationAlignmentType a, const RotationAlignmentType, const double) { return a; } + + } } -- cgit v1.2.1 From f99bd1c6ec6ed9369fe84e474ff539398f962715 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 17:30:34 -0800 Subject: switch to functions of arrays (from arrays of fns) for properties like *-translate, *-offset https://github.com/mapbox/mapbox-gl-style-spec/issues/237 --- src/mbgl/map/tile_parser.cpp | 6 ++---- src/mbgl/style/function_properties.cpp | 2 ++ src/mbgl/style/property_fallback.cpp | 18 ++++++------------ src/mbgl/style/property_key.hpp | 18 ++++-------------- src/mbgl/style/property_value.hpp | 2 ++ src/mbgl/style/style_layer.cpp | 12 ++++-------- src/mbgl/style/style_parser.cpp | 31 +++++++++++++++++++++++++------ src/mbgl/util/interpolate.hpp | 8 ++++++++ 8 files changed, 53 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp index c3e7a8244b..6118d90a10 100644 --- a/src/mbgl/map/tile_parser.cpp +++ b/src/mbgl/map/tile_parser.cpp @@ -161,8 +161,7 @@ void TileParser::applyLayoutProperties(StyleBucket &bucket_des applyLayoutProperty(PropertyKey::IconPadding, bucket_desc.layout, symbol.icon.padding, z); applyLayoutProperty(PropertyKey::IconRotate, bucket_desc.layout, symbol.icon.rotate, z); applyLayoutProperty(PropertyKey::IconKeepUpright, bucket_desc.layout, symbol.icon.keep_upright, z); - applyLayoutProperty(PropertyKey::IconOffsetX, bucket_desc.layout, symbol.icon.offset[0], z); - applyLayoutProperty(PropertyKey::IconOffsetY, bucket_desc.layout, symbol.icon.offset[1], z); + applyLayoutProperty(PropertyKey::IconOffset, bucket_desc.layout, symbol.icon.offset, z); applyLayoutProperty(PropertyKey::TextRotationAlignment, bucket_desc.layout, symbol.text.rotation_alignment, z); applyLayoutProperty(PropertyKey::TextField, bucket_desc.layout, symbol.text.field, z); @@ -180,8 +179,7 @@ void TileParser::applyLayoutProperties(StyleBucket &bucket_des applyLayoutProperty(PropertyKey::TextAnchor, bucket_desc.layout, symbol.text.anchor, z); applyLayoutProperty(PropertyKey::TextKeepUpright, bucket_desc.layout, symbol.text.keep_upright, z); applyLayoutProperty(PropertyKey::TextTransform, bucket_desc.layout, symbol.text.transform, z); - applyLayoutProperty(PropertyKey::TextOffsetX, bucket_desc.layout, symbol.text.offset[0], z); - applyLayoutProperty(PropertyKey::TextOffsetY, bucket_desc.layout, symbol.text.offset[1], z); + applyLayoutProperty(PropertyKey::TextOffset, bucket_desc.layout, symbol.text.offset, z); applyLayoutProperty(PropertyKey::TextAllowOverlap, bucket_desc.layout, symbol.text.allow_overlap, z); } diff --git a/src/mbgl/style/function_properties.cpp b/src/mbgl/style/function_properties.cpp index 2ea3682b8f..1ac2863a7c 100644 --- a/src/mbgl/style/function_properties.cpp +++ b/src/mbgl/style/function_properties.cpp @@ -13,6 +13,7 @@ template <> inline bool defaultStopsValue() { return true; } template <> inline float defaultStopsValue() { return 1.0f; } template <> inline Color defaultStopsValue() { return {{ 0, 0, 0, 1 }}; } template <> inline std::vector defaultStopsValue() { return {{ 1, 0 }}; } +template <> inline std::array defaultStopsValue() { return {{ 0, 0 }}; } template <> inline std:: string defaultStopsValue() { return {}; } template <> inline TranslateAnchorType defaultStopsValue() { return {}; }; @@ -76,6 +77,7 @@ template bool StopsFunction::evaluate(float z) const; template float StopsFunction::evaluate(float z) const; template Color StopsFunction::evaluate(float z) const; template std::vector StopsFunction>::evaluate(float z) const; +template std::array StopsFunction>::evaluate(float z) const; template std::string StopsFunction::evaluate(float z) const; template TranslateAnchorType StopsFunction::evaluate(float z) const; diff --git a/src/mbgl/style/property_fallback.cpp b/src/mbgl/style/property_fallback.cpp index 5fc3ce1f04..2827fd6149 100644 --- a/src/mbgl/style/property_fallback.cpp +++ b/src/mbgl/style/property_fallback.cpp @@ -9,14 +9,12 @@ const std::map PropertyFallbackValue::properties = { { PropertyKey::FillOpacity, defaultStyleProperties().opacity }, { PropertyKey::FillColor, defaultStyleProperties().fill_color }, // no FillOutlineColor on purpose. - { PropertyKey::FillTranslateX, defaultStyleProperties().translate[0] }, - { PropertyKey::FillTranslateY, defaultStyleProperties().translate[1] }, + { PropertyKey::FillTranslate, defaultStyleProperties().translate }, { PropertyKey::FillTranslateAnchor, defaultStyleProperties().translateAnchor }, { PropertyKey::LineOpacity, defaultStyleProperties().opacity }, { PropertyKey::LineColor, defaultStyleProperties().color }, - { PropertyKey::LineTranslateX, defaultStyleProperties().translate[0] }, - { PropertyKey::LineTranslateY, defaultStyleProperties().translate[1] }, + { PropertyKey::LineTranslate, defaultStyleProperties().translate }, { PropertyKey::LineTranslateAnchor, defaultStyleProperties().translateAnchor }, { PropertyKey::LineWidth, defaultStyleProperties().width }, { PropertyKey::LineGapWidth, defaultStyleProperties().gap_width }, @@ -29,8 +27,7 @@ const std::map PropertyFallbackValue::properties = { { PropertyKey::IconHaloColor, defaultStyleProperties().icon.halo_color }, { PropertyKey::IconHaloWidth, defaultStyleProperties().icon.halo_width }, { PropertyKey::IconHaloBlur, defaultStyleProperties().icon.halo_blur }, - { PropertyKey::IconTranslateX, defaultStyleProperties().icon.translate[0] }, - { PropertyKey::IconTranslateY, defaultStyleProperties().icon.translate[1] }, + { PropertyKey::IconTranslate, defaultStyleProperties().icon.translate }, { PropertyKey::IconTranslateAnchor, defaultStyleProperties().icon.translate_anchor }, { PropertyKey::TextOpacity, defaultStyleProperties().text.opacity }, @@ -39,8 +36,7 @@ const std::map PropertyFallbackValue::properties = { { PropertyKey::TextHaloColor, defaultStyleProperties().text.halo_color }, { PropertyKey::TextHaloWidth, defaultStyleProperties().text.halo_width }, { PropertyKey::TextHaloBlur, defaultStyleProperties().text.halo_blur }, - { PropertyKey::TextTranslateX, defaultStyleProperties().text.translate[0] }, - { PropertyKey::TextTranslateY, defaultStyleProperties().text.translate[1] }, + { PropertyKey::TextTranslate, defaultStyleProperties().text.translate }, { PropertyKey::TextTranslateAnchor, defaultStyleProperties().text.translate_anchor }, { PropertyKey::RasterOpacity, defaultStyleProperties().opacity }, @@ -72,8 +68,7 @@ const std::map PropertyFallbackValue::properties = { { PropertyKey::IconRotate, defaultLayoutProperties().icon.rotate }, { PropertyKey::IconPadding, defaultLayoutProperties().icon.padding }, { PropertyKey::IconKeepUpright, defaultLayoutProperties().icon.keep_upright }, - { PropertyKey::IconOffsetX, defaultLayoutProperties().icon.offset[0] }, - { PropertyKey::IconOffsetY, defaultLayoutProperties().icon.offset[1] }, + { PropertyKey::IconOffset, defaultLayoutProperties().icon.offset }, { PropertyKey::TextRotationAlignment, defaultLayoutProperties().text.rotation_alignment }, { PropertyKey::TextField, defaultLayoutProperties().text.field }, @@ -89,8 +84,7 @@ const std::map PropertyFallbackValue::properties = { { PropertyKey::TextPadding, defaultLayoutProperties().text.padding }, { PropertyKey::TextKeepUpright, defaultLayoutProperties().text.keep_upright }, { PropertyKey::TextTransform, defaultLayoutProperties().text.transform }, - { PropertyKey::TextOffsetX, defaultLayoutProperties().text.offset[0] }, - { PropertyKey::TextOffsetY, defaultLayoutProperties().text.offset[1] }, + { PropertyKey::TextOffset, defaultLayoutProperties().text.offset }, { PropertyKey::TextAllowOverlap, defaultLayoutProperties().text.allow_overlap }, { PropertyKey::TextIgnorePlacement, defaultLayoutProperties().text.ignore_placement }, { PropertyKey::TextOptional, defaultLayoutProperties().text.optional }, diff --git a/src/mbgl/style/property_key.hpp b/src/mbgl/style/property_key.hpp index f10607a7af..dfe82e4bb0 100644 --- a/src/mbgl/style/property_key.hpp +++ b/src/mbgl/style/property_key.hpp @@ -9,16 +9,12 @@ enum class PropertyKey { FillColor, FillOutlineColor, FillTranslate, // for transitions only - FillTranslateX, - FillTranslateY, FillTranslateAnchor, FillImage, LineOpacity, LineColor, LineTranslate, // for transitions only - LineTranslateX, - LineTranslateY, LineTranslateAnchor, LineWidth, LineGapWidth, @@ -41,9 +37,7 @@ enum class PropertyKey { IconHaloColor, IconHaloWidth, IconHaloBlur, - IconTranslate, // for transitions only - IconTranslateX, - IconTranslateY, + IconTranslate, IconTranslateAnchor, IconAllowOverlap, @@ -52,11 +46,10 @@ enum class PropertyKey { IconRotationAlignment, IconMaxSize, IconImage, + IconOffset, IconPadding, IconRotate, IconKeepUpright, - IconOffsetX, - IconOffsetY, TextOpacity, TextSize, @@ -64,9 +57,7 @@ enum class PropertyKey { TextHaloColor, TextHaloWidth, TextHaloBlur, - TextTranslate, // for transitions only - TextTranslateX, - TextTranslateY, + TextTranslate, TextTranslateAnchor, TextRotationAlignment, @@ -85,8 +76,7 @@ enum class PropertyKey { TextAnchor, TextKeepUpright, TextTransform, - TextOffsetX, - TextOffsetY, + TextOffset, TextAllowOverlap, RasterOpacity, diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp index 00f72ea643..fbc3f3bd6a 100644 --- a/src/mbgl/style/property_value.hpp +++ b/src/mbgl/style/property_value.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace mbgl { @@ -22,6 +23,7 @@ typedef mapbox::util::variant< Function, Function, Function, + Function>, Function, Function, Function, diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/style/style_layer.cpp index 9a7066c497..1a4354be27 100644 --- a/src/mbgl/style/style_layer.cpp +++ b/src/mbgl/style/style_layer.cpp @@ -167,8 +167,7 @@ void StyleLayer::applyStyleProperties(const float z, const std:: applyTransitionedStyleProperty(PropertyKey::FillOpacity, fill.opacity, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::FillColor, fill.fill_color, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::FillOutlineColor, fill.stroke_color, z, now, zoomHistory); - applyTransitionedStyleProperty(PropertyKey::FillTranslateX, fill.translate[0], z, now, zoomHistory); - applyTransitionedStyleProperty(PropertyKey::FillTranslateY, fill.translate[1], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::FillTranslate, fill.translate, z, now, zoomHistory); applyStyleProperty(PropertyKey::FillTranslateAnchor, fill.translateAnchor, z, now, zoomHistory); applyStyleProperty(PropertyKey::FillImage, fill.image, z, now, zoomHistory); } @@ -179,8 +178,7 @@ void StyleLayer::applyStyleProperties(const float z, const std:: LineProperties &line = properties.get(); applyTransitionedStyleProperty(PropertyKey::LineOpacity, line.opacity, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::LineColor, line.color, z, now, zoomHistory); - applyTransitionedStyleProperty(PropertyKey::LineTranslateX, line.translate[0], z, now, zoomHistory); - applyTransitionedStyleProperty(PropertyKey::LineTranslateY, line.translate[1], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::LineTranslate, line.translate, z, now, zoomHistory); applyStyleProperty(PropertyKey::LineTranslateAnchor, line.translateAnchor, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::LineWidth, line.width, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::LineGapWidth, line.gap_width, z, now, zoomHistory); @@ -203,8 +201,7 @@ void StyleLayer::applyStyleProperties(const float z, const std applyTransitionedStyleProperty(PropertyKey::IconHaloColor, symbol.icon.halo_color, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::IconHaloWidth, symbol.icon.halo_width, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::IconHaloBlur, symbol.icon.halo_blur, z, now, zoomHistory); - applyTransitionedStyleProperty(PropertyKey::IconTranslateX, symbol.icon.translate[0], z, now, zoomHistory); - applyTransitionedStyleProperty(PropertyKey::IconTranslateY, symbol.icon.translate[1], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::IconTranslate, symbol.icon.translate, z, now, zoomHistory); applyStyleProperty(PropertyKey::IconTranslateAnchor, symbol.icon.translate_anchor, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::TextOpacity, symbol.text.opacity, z, now, zoomHistory); @@ -213,8 +210,7 @@ void StyleLayer::applyStyleProperties(const float z, const std applyTransitionedStyleProperty(PropertyKey::TextHaloColor, symbol.text.halo_color, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::TextHaloWidth, symbol.text.halo_width, z, now, zoomHistory); applyTransitionedStyleProperty(PropertyKey::TextHaloBlur, symbol.text.halo_blur, z, now, zoomHistory); - applyTransitionedStyleProperty(PropertyKey::TextTranslateX, symbol.text.translate[0], z, now, zoomHistory); - applyTransitionedStyleProperty(PropertyKey::TextTranslateY, symbol.text.translate[1], z, now, zoomHistory); + applyTransitionedStyleProperty(PropertyKey::TextTranslate, symbol.text.translate, z, now, zoomHistory); applyStyleProperty(PropertyKey::TextTranslateAnchor, symbol.text.translate_anchor, z, now, zoomHistory); } diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 15a9f64aad..c8b62a97ee 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -227,6 +227,21 @@ std::tuple> parseFloatArray(JSVal value) { return std::tuple> { true, vec }; } +template <> +std::tuple> StyleParser::parseProperty(JSVal value, const char*) { + if (value.IsArray() && value.Size() == 2 && + value[rapidjson::SizeType(0)].IsNumber() && + value[rapidjson::SizeType(1)].IsNumber()) { + + float first = value[rapidjson::SizeType(0)].GetDouble(); + float second = value[rapidjson::SizeType(1)].GetDouble(); + return std::tuple> { false, {{ first, second }} }; + } else { + Log::Warning(Event::ParseStyle, "value must be array of two numbers"); + return std::tuple> { false, {{ 0.0f, 0.0f }} }; + } +} + template <> std::tuple StyleParser::parseProperty(JSVal value, const char*) { JSVal rvalue = replaceConstant(value); @@ -520,6 +535,10 @@ template<> std::tuple StyleParser::parseProperty(JSVal return std::tuple { true, std::move(transition) }; } +template<> std::tuple>> StyleParser::parseProperty(JSVal value, const char *property_name) { + return parseFunction>(value, property_name); +} + template<> std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { return parseFunction(value, property_name); } @@ -751,7 +770,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("fill-color-transition", Key::FillColor, klass, value); parseOptionalProperty>("fill-outline-color", Key::FillOutlineColor, klass, value); parseOptionalProperty("fill-outline-color-transition", Key::FillOutlineColor, klass, value); - parseOptionalProperty>("fill-translate", { Key::FillTranslateX, Key::FillTranslateY }, klass, value); + parseOptionalProperty>>("fill-translate", Key::FillTranslate, klass, value); parseOptionalProperty("fill-translate-transition", Key::FillTranslate, klass, value); parseOptionalProperty>("fill-translate-anchor", Key::FillTranslateAnchor, klass, value); parseOptionalProperty>>("fill-image", Key::FillImage, klass, value, "fill-image-transition"); @@ -760,7 +779,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("line-opacity-transition", Key::LineOpacity, klass, value); parseOptionalProperty>("line-color", Key::LineColor, klass, value); parseOptionalProperty("line-color-transition", Key::LineColor, klass, value); - parseOptionalProperty>("line-translate", { Key::LineTranslateX, Key::LineTranslateY }, klass, value); + parseOptionalProperty>>("line-translate", Key::LineTranslate, klass, value); parseOptionalProperty("line-translate-transition", Key::LineTranslate, klass, value); parseOptionalProperty>("line-translate-anchor", Key::LineTranslateAnchor, klass, value); parseOptionalProperty>("line-width", Key::LineWidth, klass, value); @@ -785,7 +804,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("icon-halo-width-transition", Key::IconHaloWidth, klass, value); parseOptionalProperty>("icon-halo-blur", Key::IconHaloBlur, klass, value); parseOptionalProperty("icon-halo-blur-transition", Key::IconHaloBlur, klass, value); - parseOptionalProperty>("icon-translate", { Key::IconTranslateX, Key::IconTranslateY }, klass, value); + parseOptionalProperty>>("icon-translate", Key::IconTranslate, klass, value); parseOptionalProperty("icon-translate-transition", Key::IconTranslate, klass, value); parseOptionalProperty>("icon-translate-anchor", Key::IconTranslateAnchor, klass, value); @@ -801,7 +820,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("text-halo-width-transition", Key::TextHaloWidth, klass, value); parseOptionalProperty>("text-halo-blur", Key::TextHaloBlur, klass, value); parseOptionalProperty("text-halo-blur-transition", Key::TextHaloBlur, klass, value); - parseOptionalProperty>("text-translate", { Key::TextTranslateX, Key::TextTranslateY }, klass, value); + parseOptionalProperty>>("text-translate", Key::TextTranslate, klass, value); parseOptionalProperty("text-translate-transition", Key::TextTranslate, klass, value); parseOptionalProperty>("text-translate-anchor", Key::TextTranslateAnchor, klass, value); @@ -845,7 +864,7 @@ void StyleParser::parseLayout(JSVal value, util::ptr &bucket) { parseOptionalProperty>("icon-rotate", Key::IconRotate, bucket->layout, value); parseOptionalProperty>("icon-padding", Key::IconPadding, bucket->layout, value); parseOptionalProperty>("icon-keep-upright", Key::IconKeepUpright, bucket->layout, value); - parseOptionalProperty>("icon-offset", { Key::IconOffsetX, Key::IconOffsetY }, bucket->layout, value); + parseOptionalProperty>>("icon-offset", Key::IconOffset, bucket->layout, value); parseOptionalProperty>("text-rotation-alignment", Key::TextRotationAlignment, bucket->layout, value); parseOptionalProperty>("text-field", Key::TextField, bucket->layout, value); parseOptionalProperty>("text-font", Key::TextFont, bucket->layout, value); @@ -860,7 +879,7 @@ void StyleParser::parseLayout(JSVal value, util::ptr &bucket) { parseOptionalProperty>("text-padding", Key::TextPadding, bucket->layout, value); parseOptionalProperty>("text-keep-upright", Key::TextKeepUpright, bucket->layout, value); parseOptionalProperty>("text-transform", Key::TextTransform, bucket->layout, value); - parseOptionalProperty>("text-offset", { Key::TextOffsetX, Key::TextOffsetY }, bucket->layout, value); + parseOptionalProperty>>("text-offset", Key::TextOffset, bucket->layout, value); parseOptionalProperty>("text-allow-overlap", Key::TextAllowOverlap, bucket->layout, value); parseOptionalProperty>("text-ignore-placement", Key::TextIgnorePlacement, bucket->layout, value); parseOptionalProperty>("text-optional", Key::TextOptional, bucket->layout, value); diff --git a/src/mbgl/util/interpolate.hpp b/src/mbgl/util/interpolate.hpp index a2998233b5..55b1e2add4 100644 --- a/src/mbgl/util/interpolate.hpp +++ b/src/mbgl/util/interpolate.hpp @@ -24,6 +24,14 @@ inline std::array interpolate(const std::array& a, const std::array< }}; } +template +inline std::array interpolate(const std::array& a, const std::array& b, const double t) { + return {{ + interpolate(a[0], b[0], t), + interpolate(a[1], b[1], t) + }}; +} + // fake interpolations that just return the first value template<> inline bool interpolate(const bool a, const bool, const double) { return a; } template<> inline std::vector interpolate(const std::vector a, const std::vector, const double) { return a; } -- cgit v1.2.1 From 968d6812db7b2754a671a309f925134e8c79d051 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 17:35:13 -0800 Subject: make raster-brightness two separate properties --- src/mbgl/style/style_parser.cpp | 22 ++-------------------- src/mbgl/style/style_parser.hpp | 2 -- 2 files changed, 2 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index c8b62a97ee..c9c711d46f 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -630,25 +630,6 @@ template<> std::tuple>> Style } } -template -bool StyleParser::parseOptionalProperty(const char *property_name, const std::vector &keys, ClassProperties &klass, JSVal value) { - if (value.HasMember(property_name)) { - JSVal rvalue = replaceConstant(value[property_name]); - if (!rvalue.IsArray()) { - Log::Warning(Event::ParseStyle, "array value must be an array"); - } - - if (rvalue.Size() != keys.size()) { - Log::Warning(Event::ParseStyle, "array value has unexpected number of elements"); - } - - for (uint16_t i = 0; i < keys.size(); i++) { - setProperty(rvalue[(rapidjson::SizeType)i], property_name, keys[i], klass); - } - } - return true; -} - #pragma mark - Parse Layers std::unique_ptr StyleParser::createLayers(JSVal value) { @@ -828,7 +809,8 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty("raster-opacity-transition", Key::RasterOpacity, klass, value); parseOptionalProperty>("raster-hue-rotate", Key::RasterHueRotate, klass, value); parseOptionalProperty("raster-hue-rotate-transition", Key::RasterHueRotate, klass, value); - parseOptionalProperty>("raster-brightness", { Key::RasterBrightnessLow, Key::RasterBrightnessHigh }, klass, value); + parseOptionalProperty>("raster-brightness-min", Key::RasterBrightnessLow, klass, value); + parseOptionalProperty>("raster-brightness-max", Key::RasterBrightnessLow, klass, value); parseOptionalProperty("raster-brightness-transition", Key::RasterBrightness, klass, value); parseOptionalProperty>("raster-saturation", Key::RasterSaturation, klass, value); parseOptionalProperty("raster-saturation-transition", Key::RasterSaturation, klass, value); diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index a32e6dd1d3..2f7aa0110e 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -71,8 +71,6 @@ private: template bool parseOptionalProperty(const char *property_name, PropertyKey key, ClassProperties &klass, JSVal value, const char *transition_name); template - bool parseOptionalProperty(const char *property_name, const std::vector &keys, ClassProperties &klass, JSVal value); - template bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass); template bool setProperty(JSVal value, const char *property_name, PropertyKey key, ClassProperties &klass, JSVal transition); -- cgit v1.2.1 From fe5b618484e9d1a06770c394dd3251229a5472eb Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 17:38:34 -0800 Subject: fix compilation errors --- src/mbgl/style/style_parser.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index c9c711d46f..3244839a7d 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -246,17 +246,17 @@ template <> std::tuple StyleParser::parseProperty(JSVal value, const char*) { JSVal rvalue = replaceConstant(value); if (rvalue.IsNumber()) { - return { true, rvalue.GetDouble() }; + return std::tuple { true, rvalue.GetDouble() }; } else { Log::Warning(Event::ParseStyle, "function argument must be a numeric value"); - return { false, 0.0f }; + return std::tuple { false, 0.0f }; } } template <> std::tuple StyleParser::parseProperty(JSVal value, const char*) { JSVal rvalue = replaceConstant(value); - return { true, parseColor(rvalue) }; + return std::tuple { true, parseColor(rvalue) }; } template <> @@ -264,7 +264,7 @@ std::tuple>> StyleParser::parseProperty(JSVal val Faded> parsed; JSVal rvalue = replaceConstant(value); parsed.to = std::get<1>(parseFloatArray(rvalue)); - return { true, parsed }; + return std::tuple>> { true, parsed }; } template <> @@ -273,10 +273,10 @@ std::tuple> StyleParser::parseProperty(JSVal value, con Faded parsed; if (rvalue.IsString()) { parsed.to = { value.GetString(), value.GetStringLength() }; - return { true, parsed }; + return std::tuple> { true, parsed }; } else { Log::Warning(Event::ParseStyle, "function argument must be a string"); - return { false, parsed }; + return std::tuple> { false, parsed }; } } -- cgit v1.2.1 From 5eb08baf14f2eda6ea860f4d0957c4eec672edec Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 18:33:00 -0800 Subject: tweak style parsing error messages --- src/mbgl/style/style_parser.cpp | 20 ++++++++++---------- src/mbgl/style/style_parser.hpp | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 3244839a7d..aedb8255cd 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -243,12 +243,12 @@ std::tuple> StyleParser::parseProperty(JSVal value, c } template <> -std::tuple StyleParser::parseProperty(JSVal value, const char*) { +std::tuple StyleParser::parseProperty(JSVal value, const char* property_name) { JSVal rvalue = replaceConstant(value); if (rvalue.IsNumber()) { return std::tuple { true, rvalue.GetDouble() }; } else { - Log::Warning(Event::ParseStyle, "function argument must be a numeric value"); + Log::Warning(Event::ParseStyle, "value of '%s' must be a number, or a number function", property_name); return std::tuple { false, 0.0f }; } } @@ -268,20 +268,20 @@ std::tuple>> StyleParser::parseProperty(JSVal val } template <> -std::tuple> StyleParser::parseProperty(JSVal value, const char*) { +std::tuple> StyleParser::parseProperty(JSVal value, const char *property_name) { JSVal rvalue = replaceConstant(value); Faded parsed; if (rvalue.IsString()) { parsed.to = { value.GetString(), value.GetStringLength() }; return std::tuple> { true, parsed }; } else { - Log::Warning(Event::ParseStyle, "function argument must be a string"); + Log::Warning(Event::ParseStyle, "value of '%s' must be a string, or a string function", property_name); return std::tuple> { false, parsed }; } } template -std::tuple>> StyleParser::parseStops(JSVal value_stops) { +std::tuple>> StyleParser::parseStops(JSVal value_stops, const char *property_name) { if (!value_stops.IsArray()) { Log::Warning(Event::ParseStyle, "stops function must specify a stops array"); @@ -304,7 +304,7 @@ std::tuple>> StyleParser::parseStops(JSVal return std::tuple>> { false, {}}; } - stops.emplace_back(z.GetDouble(), std::get<1>(parseProperty(replaceConstant(stop[rapidjson::SizeType(1)]), ""))); + stops.emplace_back(z.GetDouble(), std::get<1>(parseProperty(replaceConstant(stop[rapidjson::SizeType(1)]), property_name))); } else { Log::Warning(Event::ParseStyle, "function argument must be a numeric value"); return std::tuple>> { false, {}}; @@ -317,10 +317,10 @@ template inline float defaultBaseValue() { return 1.75; } template <> inline float defaultBaseValue() { return 1.0; } template -std::tuple> StyleParser::parseFunction(JSVal value, const char *) { +std::tuple> StyleParser::parseFunction(JSVal value, const char *property_name) { if (!value.IsObject()) { - return std::tuple> { true, ConstantFunction(std::get<1>(parseProperty(value, ""))) }; + return std::tuple> { true, ConstantFunction(std::get<1>(parseProperty(value, property_name))) }; } if (!value.HasMember("stops")) { @@ -339,7 +339,7 @@ std::tuple> StyleParser::parseFunction(JSVal value, const char } } - auto stops = parseStops(value["stops"]); + auto stops = parseStops(value["stops"], property_name); if (!std::get<0>(stops)) { return std::tuple> { false, ConstantFunction(T()) }; @@ -355,7 +355,7 @@ std::tuple> StyleParser::parsePiecewiseConsta return std::tuple> { false, {} }; } - auto stops = parseStops(value["stops"]); + auto stops = parseStops(value["stops"], ""); if (!std::get<0>(stops)) { return std::tuple> { false, {} }; diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 2f7aa0110e..90dd4224e0 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -85,7 +85,7 @@ private: template std::tuple> parsePiecewiseConstantFunction(JSVal value, std::chrono::steady_clock::duration duration); template - std::tuple>> parseStops(JSVal value); + std::tuple>> parseStops(JSVal value, const char *property_name); FilterExpression parseFilter(JSVal); -- cgit v1.2.1 From 97f19e8b849cd0d48ac57e03c3ad49459e7a0d94 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 9 Feb 2015 11:48:36 -0800 Subject: support constants within dasharrays --- src/mbgl/style/style_parser.cpp | 4 ++-- src/mbgl/style/style_parser.hpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index aedb8255cd..251ba8321e 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -209,7 +209,7 @@ Color parseColor(JSVal value) { css_color.a}}; } -std::tuple> parseFloatArray(JSVal value) { +std::tuple> StyleParser::parseFloatArray(JSVal value) { if (!value.IsArray()) { Log::Warning(Event::ParseStyle, "dasharray value must be an array of numbers"); return std::tuple> { false, std::vector() }; @@ -217,7 +217,7 @@ std::tuple> parseFloatArray(JSVal value) { std::vector vec; for (rapidjson::SizeType i = 0; i < value.Size(); ++i) { - JSVal part = value[i]; + JSVal part = replaceConstant(value[i]); if (!part.IsNumber()) { Log::Warning(Event::ParseStyle, "dasharray value must be an array of numbers"); return std::tuple> { false, std::vector() }; diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 90dd4224e0..736cb9e9fa 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -87,6 +87,8 @@ private: template std::tuple>> parseStops(JSVal value, const char *property_name); + std::tuple> parseFloatArray(JSVal value); + FilterExpression parseFilter(JSVal); private: -- cgit v1.2.1 From fdc9283c5cc5c70e7c287547590cc9cdfaa7589b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 9 Feb 2015 12:03:47 -0800 Subject: fix raster-brightness --- src/mbgl/style/style_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 251ba8321e..af6a84492d 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -810,7 +810,7 @@ void StyleParser::parsePaint(JSVal value, ClassProperties &klass) { parseOptionalProperty>("raster-hue-rotate", Key::RasterHueRotate, klass, value); parseOptionalProperty("raster-hue-rotate-transition", Key::RasterHueRotate, klass, value); parseOptionalProperty>("raster-brightness-min", Key::RasterBrightnessLow, klass, value); - parseOptionalProperty>("raster-brightness-max", Key::RasterBrightnessLow, klass, value); + parseOptionalProperty>("raster-brightness-max", Key::RasterBrightnessHigh, klass, value); parseOptionalProperty("raster-brightness-transition", Key::RasterBrightness, klass, value); parseOptionalProperty>("raster-saturation", Key::RasterSaturation, klass, value); parseOptionalProperty("raster-saturation-transition", Key::RasterSaturation, klass, value); -- cgit v1.2.1 From 6d47e9b6849f7c383dc6e71d9e8d6baeaacf8e9f Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 10 Feb 2015 10:59:32 -0800 Subject: use correct interpolation for background images --- src/mbgl/renderer/painter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index ebb2f77cc5..116ae3ad2f 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -389,7 +389,7 @@ void Painter::renderBackground(util::ptr layer_desc) { patternShader->u_pattern_br_a = imagePosA.br; patternShader->u_pattern_tl_b = imagePosB.tl; patternShader->u_pattern_br_b = imagePosB.br; - patternShader->u_mix = zoomFraction; + patternShader->u_mix = properties.image.t; patternShader->u_opacity = properties.opacity; double lon, lat; -- cgit v1.2.1