From d532824aec25e20efccb80860b990db0b85780ac Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 14:46:48 -0800 Subject: [PATCH 01/28] 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 | 133 ++++++++++---------- 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, 352 insertions(+), 141 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 diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 0fb99826c..448b38074 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 5e8f46d34..10d4aa332 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 ba6aed302..a28a52ce3 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 f2de884ea..dff4469d2 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 9fabd8e18..9fc8dcfa0 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 000000000..485bffd26 --- /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 000000000..4d49dafb4 --- /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 e017981de..7b6c38e75 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 ecff6fb5f..dc764106c 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 e9205712e..434b39421 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 262ca23af..bb9688e57 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::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); - 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::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 7cf661ca3..8531ad3a0 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 0ca0fa0cc..5ca020ee7 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 1af6e23bd..85cfcc6dd 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 f048b24bd..3f1fc64da 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 42e22f945..482fa0a00 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 c5149b2d1..db9e4c34c 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 c0b873dcd..cd9c29d30 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 000000000..703106862 --- /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 From b3ca6fcca6e3a1c383a0235aea3110bc940c0656 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 16:23:10 -0800 Subject: [PATCH 02/28] 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(-) diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 448b38074..f8347123c 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 3f1fc64da..1cf8d2e35 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 db9e4c34c..d2c134e8d 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< From 322f46a5db6d44633ffc7a45140e163f03365371 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 17:08:26 -0800 Subject: [PATCH 03/28] 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(-) diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index f8347123c..84bd24c5e 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 3951f2e7c..b26f1cfa5 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 45be7c8c2..08feff439 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 388cff17d..16d9ff8be 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 1cf8d2e35..5dcf3b114 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 d2c134e8d..178421010 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; From 6f5c6b58b48e762ed7aced6c4486f1060d0e34f1 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 17:52:44 -0800 Subject: [PATCH 04/28] use faded pattern functions for dasharrays --- src/mbgl/renderer/painter_line.cpp | 37 ++++++++------------- 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, 30 insertions(+), 36 deletions(-) diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index b26f1cfa5..149683cbc 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 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; - 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; + 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 485bffd26..8ac4f3be4 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 4d49dafb4..23b441136 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 7b6c38e75..8dcb8d737 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 5dcf3b114..454e78657 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 178421010..fd55cb0bb 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; From c9f8de863dc93e4fd587290357c8a3b572a4f956 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 2 Feb 2015 18:27:55 -0800 Subject: [PATCH 05/28] remove old version of zoomHistory --- src/mbgl/renderer/painter.cpp | 25 +------------------------ src/mbgl/renderer/painter.hpp | 5 ----- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 84bd24c5e..02e263a1c 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 5a4207020..4d4876a6f 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; From 93b07c367577b097e3791d38690b8fc37054c5fb Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 11:36:31 -0800 Subject: [PATCH 06/28] rename FadedFunction to PiecewiseConstant function --- ...s.cpp => piecewisefunction_properties.cpp} | 8 ++--- ...s.hpp => piecewisefunction_properties.hpp} | 8 ++--- 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 +- 7 files changed, 30 insertions(+), 30 deletions(-) rename src/mbgl/style/{fadedfunction_properties.cpp => piecewisefunction_properties.cpp} (73%) rename src/mbgl/style/{fadedfunction_properties.hpp => piecewisefunction_properties.hpp} (50%) diff --git a/src/mbgl/style/fadedfunction_properties.cpp b/src/mbgl/style/piecewisefunction_properties.cpp similarity index 73% rename from src/mbgl/style/fadedfunction_properties.cpp rename to src/mbgl/style/piecewisefunction_properties.cpp index 21c326751..e760ebdb1 100644 --- a/src/mbgl/style/fadedfunction_properties.cpp +++ b/src/mbgl/style/piecewisefunction_properties.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -16,7 +16,7 @@ uint32_t getBiggestStopLessThan(std::vector> stops, float z) } template -T FadedStopsFunction::evaluate(float z, const ZoomHistory &zh) const { +T PiecewiseConstantFunction::evaluate(float z, const ZoomHistory &zh) const { T result; float fraction = std::fmod(z, 1.0f); @@ -44,7 +44,7 @@ T FadedStopsFunction::evaluate(float z, const ZoomHistory &zh) const { return result; } -template Faded FadedStopsFunction>::evaluate(float z, const ZoomHistory &zoomHistory) const; -template Faded> FadedStopsFunction>>::evaluate(float z, const ZoomHistory &zoomHistory) const; +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/fadedfunction_properties.hpp b/src/mbgl/style/piecewisefunction_properties.hpp similarity index 50% rename from src/mbgl/style/fadedfunction_properties.hpp rename to src/mbgl/style/piecewisefunction_properties.hpp index 7313d3275..69ddc7cc2 100644 --- a/src/mbgl/style/fadedfunction_properties.hpp +++ b/src/mbgl/style/piecewisefunction_properties.hpp @@ -8,10 +8,10 @@ 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) {} +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: diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp index 49e837cf1..c7fe82302 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 795c651b8..9a7066c49 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 1fc57e2f7..4dd200aa2 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 5b55d6116..fd26dc864 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 fd55cb0bb..f50722542 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 From 4ec00288562f16f93ea0d46f63291b8bea4d66ac Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 12:08:29 -0800 Subject: [PATCH 07/28] 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 +++++++------- .../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(-) diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 78b6c18e4..ebb2f77cc 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 10d4aa332..9cfe26222 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 149683cbc..a66da1fcd 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 e760ebdb1..86d02e7b1 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 4dd200aa2..c6d3c8666 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 b7d675857..78938a282 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; }; From a49737e542dc518076add81fca7d02c0a9449ae7 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 13:51:52 -0800 Subject: [PATCH 08/28] 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(-) diff --git a/src/mbgl/style/piecewisefunction_properties.hpp b/src/mbgl/style/piecewisefunction_properties.hpp index 69ddc7cc2..769020002 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 c6d3c8666..a334cecc0 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 eee0d9b44..248868710 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; } From f07de8dd23779319909f20f9da384eaf46aa4ca3 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 15:30:51 -0800 Subject: [PATCH 09/28] make pattern and dasharray properties use duration from "*-transition" properties --- .../style/piecewisefunction_properties.cpp | 4 +- .../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(-) diff --git a/src/mbgl/style/piecewisefunction_properties.cpp b/src/mbgl/style/piecewisefunction_properties.cpp index 86d02e7b1..72ed0b8f7 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 769020002..0440655ba 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 a334cecc0..89a266a18 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 fd26dc864..d25c70579 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 From 6e95c3b2e189e91a6244eef58ad1057258b2724b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Wed, 4 Feb 2015 19:47:31 -0800 Subject: [PATCH 10/28] fix compilation on android --- src/mbgl/style/style_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 89a266a18..4120ef470 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); } } From 3a8aaad6a799fd4ab1feb47a47a7ffa0d05c1cc0 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 15:56:46 -0800 Subject: [PATCH 11/28] 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(-) diff --git a/src/mbgl/style/function_properties.cpp b/src/mbgl/style/function_properties.cpp index 81b1c85c7..2ea3682b8 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 c7fe82302..00f72ea64 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 4120ef470..15a9f64aa 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 d25c70579..a32e6dd1d 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 952d7b9c1..a2998233b 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; } + + } } From f99bd1c6ec6ed9369fe84e474ff539398f962715 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 17:30:34 -0800 Subject: [PATCH 12/28] 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(-) diff --git a/src/mbgl/map/tile_parser.cpp b/src/mbgl/map/tile_parser.cpp index c3e7a8244..6118d90a1 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 2ea3682b8..1ac2863a7 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 5fc3ce1f0..2827fd614 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 f10607a7a..dfe82e4bb 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 00f72ea64..fbc3f3bd6 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 9a7066c49..1a4354be2 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 15a9f64aa..c8b62a97e 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 a2998233b..55b1e2add 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; } From 968d6812db7b2754a671a309f925134e8c79d051 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 17:35:13 -0800 Subject: [PATCH 13/28] 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(-) diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index c8b62a97e..c9c711d46 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 a32e6dd1d..2f7aa0110 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); From fe5b618484e9d1a06770c394dd3251229a5472eb Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 17:38:34 -0800 Subject: [PATCH 14/28] fix compilation errors --- src/mbgl/style/style_parser.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index c9c711d46..3244839a7 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 }; } } From 5eb08baf14f2eda6ea860f4d0957c4eec672edec Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Thu, 5 Feb 2015 18:33:00 -0800 Subject: [PATCH 15/28] 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(-) diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 3244839a7..aedb8255c 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 2f7aa0110..90dd4224e 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); From 177f441cc990f3bbf4cc306a936dfe8a8212445d Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 6 Feb 2015 10:11:27 -0800 Subject: [PATCH 16/28] add test for parsing enum, bool, string functions. --- .../function-string-bool-enum.info.json | 6 +++ .../function-string-bool-enum.style.json | 43 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/fixtures/style_parser/function-string-bool-enum.info.json create mode 100644 test/fixtures/style_parser/function-string-bool-enum.style.json diff --git a/test/fixtures/style_parser/function-string-bool-enum.info.json b/test/fixtures/style_parser/function-string-bool-enum.info.json new file mode 100644 index 000000000..9c25a2f48 --- /dev/null +++ b/test/fixtures/style_parser/function-string-bool-enum.info.json @@ -0,0 +1,6 @@ +{ + "default": { + "log": [ + ] + } +} diff --git a/test/fixtures/style_parser/function-string-bool-enum.style.json b/test/fixtures/style_parser/function-string-bool-enum.style.json new file mode 100644 index 000000000..c38f19525 --- /dev/null +++ b/test/fixtures/style_parser/function-string-bool-enum.style.json @@ -0,0 +1,43 @@ +{ + "version": 6, + "sources": { + "mapbox": { + "type": "vector", + "url": "mapbox://mapbox.mapbox-terrain-v1,mapbox.mapbox-streets-v5", + "maxzoom": 14 + } + }, + "layers": [{ + "id": "waterway_river_canal", + "type": "line", + "source": "mapbox", + "source-layer": "waterway", + "filter": ["in", "type", "river", "canal"], + "layout": { + "line-cap": { + "stops": [[0, "round"], [10, "round"]] + } + }, + "paint": { + "line-translate-anchor": { + "stops": [[0, "map"], [10, "viewport"]] + } + } + }, + { + "id": "label", + "type": "symbol", + "source": "mapbox", + "source-layer": "waterway", + "layout": { + "text-font": { + "stops": [[0, "Open Sans Regular"]] + }, + "text-keep-upright": { + "stops": [[0, false], [10, true]] + } + }, + "paint": { + } + }] +} From 8f4a245c4014b0a2fad754300f3f8372a1b9051e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 6 Feb 2015 14:53:48 -0800 Subject: [PATCH 17/28] Update test suite and style submodules to latest v7 --- styles | 2 +- test/suite | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/styles b/styles index 25b1b7dff..9b582e2ad 160000 --- a/styles +++ b/styles @@ -1 +1 @@ -Subproject commit 25b1b7dff37a18151e3286144bc8013b432a8860 +Subproject commit 9b582e2adc9ed852bf1a9a26b0e10d43389e8618 diff --git a/test/suite b/test/suite index dba0f2b1f..d2fff4e20 160000 --- a/test/suite +++ b/test/suite @@ -1 +1 @@ -Subproject commit dba0f2b1fa749691435d06a251d733173d41e3f5 +Subproject commit d2fff4e2048bc4b0b2eb92c779fce01b4a45b063 From 97f19e8b849cd0d48ac57e03c3ad49459e7a0d94 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 9 Feb 2015 11:48:36 -0800 Subject: [PATCH 18/28] 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(-) diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index aedb8255c..251ba8321 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 90dd4224e..736cb9e9f 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: From fdc9283c5cc5c70e7c287547590cc9cdfaa7589b Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 9 Feb 2015 12:03:47 -0800 Subject: [PATCH 19/28] fix raster-brightness --- src/mbgl/style/style_parser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 251ba8321..af6a84492 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); From dbc4a460ef309b4d97fe0c0aac7f7bdfd0d7d0da Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Mon, 9 Feb 2015 17:32:43 -0800 Subject: [PATCH 20/28] Disable testmunk for now --- android/scripts/common.sh | 4 --- android/scripts/upload-testmunk.sh | 25 ------------- android/test/.gitignore | 1 - android/test/features/load-app.feature | 5 --- .../step_definitions/calabash_steps.rb | 1 - .../features/step_definitions/my_steps.rb | 6 ---- .../support/app_installation_hooks.rb | 36 ------------------- .../features/support/app_life_cycle_hooks.rb | 13 ------- android/test/features/support/env.rb | 1 - android/test/features/support/hooks.rb | 0 10 files changed, 92 deletions(-) delete mode 100755 android/scripts/upload-testmunk.sh delete mode 100644 android/test/.gitignore delete mode 100644 android/test/features/load-app.feature delete mode 100755 android/test/features/step_definitions/calabash_steps.rb delete mode 100644 android/test/features/step_definitions/my_steps.rb delete mode 100755 android/test/features/support/app_installation_hooks.rb delete mode 100755 android/test/features/support/app_life_cycle_hooks.rb delete mode 100755 android/test/features/support/env.rb delete mode 100755 android/test/features/support/hooks.rb diff --git a/android/scripts/common.sh b/android/scripts/common.sh index 5c214fe25..69f41997c 100755 --- a/android/scripts/common.sh +++ b/android/scripts/common.sh @@ -16,7 +16,3 @@ make android BUILDTYPE=$BUILDTYPE JOBS=$JOBS aws s3 cp ./android/java/app/build/outputs/apk/app-debug.apk s3://mapbox-gl-testing/android/${NAME}/app-debug.apk aws s3 cp ./android/java/app/build/outputs/apk/app-release-unsigned.apk s3://mapbox-gl-testing/android/${NAME}/app-release-unsigned.apk - -if [[ $TESTMUNK == "yes" ]]; then - ./android/scripts/upload-testmunk.sh ./android/java/app/build/outputs/apk/app-debug.apk -fi diff --git a/android/scripts/upload-testmunk.sh b/android/scripts/upload-testmunk.sh deleted file mode 100755 index 3fd1e70a1..000000000 --- a/android/scripts/upload-testmunk.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -o pipefail - -EMAIL="leith@mapbox.com" -APP_NAME="Mapbox" -APK_PATH=$1 - -echo "submitting testrun to testmunk" - -echo "uploading features..." - -zip -r android/test/features.zip android/test/features/ -RESPONSE=$(curl -f -H "Accept: application/vnd.testmunk.v1+json" -F "file=@android/test/features.zip" "https://${TESTMUNK_KEY}@api.testmunk.com/apps/${APP_NAME}/testcases") - -echo "uploading apk..." - -RESPONSE=$(curl -f -H "Accept: application/vnd.testmunk.v1+json" -F "file=@${APK_PATH}" -F "email=${EMAIL}" -F "autoStart=true" -F "public=true" "https://${TESTMUNK_KEY}@api.testmunk.com/apps/${APP_NAME}/testruns") - -TESTRUN_ID=$(echo "${RESPONSE}" | jq -r '.id') -TESTRUN_NAME=$(echo "${RESPONSE}" | jq -r '.name') - -echo "successully uploaded to Testmunk as '${TESTRUN_NAME}'" -echo "public link to test results: https://www.testmunk.com/testrun/${TESTRUN_ID}" diff --git a/android/test/.gitignore b/android/test/.gitignore deleted file mode 100644 index 68c12ecc0..000000000 --- a/android/test/.gitignore +++ /dev/null @@ -1 +0,0 @@ -features.zip diff --git a/android/test/features/load-app.feature b/android/test/features/load-app.feature deleted file mode 100644 index e6bd1158a..000000000 --- a/android/test/features/load-app.feature +++ /dev/null @@ -1,5 +0,0 @@ -Feature: Testapp V.1.2 - -Scenario: 1) Start app and load map - Given I await for 5 seconds - diff --git a/android/test/features/step_definitions/calabash_steps.rb b/android/test/features/step_definitions/calabash_steps.rb deleted file mode 100755 index 6d80ff0c9..000000000 --- a/android/test/features/step_definitions/calabash_steps.rb +++ /dev/null @@ -1 +0,0 @@ -require 'calabash-android/calabash_steps' diff --git a/android/test/features/step_definitions/my_steps.rb b/android/test/features/step_definitions/my_steps.rb deleted file mode 100644 index 3239322dd..000000000 --- a/android/test/features/step_definitions/my_steps.rb +++ /dev/null @@ -1,6 +0,0 @@ - -Then /^I await for ([\d\.]+) second(?:s)?$/ do |num_seconds| -num_seconds = num_seconds.to_f -sleep num_seconds - -end diff --git a/android/test/features/support/app_installation_hooks.rb b/android/test/features/support/app_installation_hooks.rb deleted file mode 100755 index 2e0a203bc..000000000 --- a/android/test/features/support/app_installation_hooks.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'calabash-android/management/app_installation' - -AfterConfiguration do |config| - FeatureNameMemory.feature_name = nil -end - -Before do |scenario| - @scenario_is_outline = (scenario.class == Cucumber::Ast::OutlineTable::ExampleRow) - if @scenario_is_outline - scenario = scenario.scenario_outline - end - - feature_name = scenario.feature.title - if FeatureNameMemory.feature_name != feature_name \ - or ENV["RESET_BETWEEN_SCENARIOS"] == "1" - if ENV["RESET_BETWEEN_SCENARIOS"] == "1" - log "New scenario - reinstalling apps" - else - log "First scenario in feature - reinstalling apps" - end - - uninstall_apps - install_app(ENV["TEST_APP_PATH"]) - install_app(ENV["APP_PATH"]) - FeatureNameMemory.feature_name = feature_name - FeatureNameMemory.invocation = 1 - else - FeatureNameMemory.invocation += 1 - end -end - -FeatureNameMemory = Class.new -class << FeatureNameMemory - @feature_name = nil - attr_accessor :feature_name, :invocation -end diff --git a/android/test/features/support/app_life_cycle_hooks.rb b/android/test/features/support/app_life_cycle_hooks.rb deleted file mode 100755 index 63d4678d9..000000000 --- a/android/test/features/support/app_life_cycle_hooks.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'calabash-android/management/adb' -require 'calabash-android/operations' - -Before do |scenario| - start_test_server_in_background -end - -After do |scenario| - if scenario.failed? - screenshot_embed - end - shutdown_test_server -end diff --git a/android/test/features/support/env.rb b/android/test/features/support/env.rb deleted file mode 100755 index bb2505d45..000000000 --- a/android/test/features/support/env.rb +++ /dev/null @@ -1 +0,0 @@ -require 'calabash-android/cucumber' diff --git a/android/test/features/support/hooks.rb b/android/test/features/support/hooks.rb deleted file mode 100755 index e69de29bb..000000000 From 80f1795b377b0d942ffe6d6e7dcf7afacbbbf073 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Tue, 10 Feb 2015 09:59:59 -0800 Subject: [PATCH 21/28] clean up iOS README notes --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 94c8d7c4f..002a530ca 100644 --- a/README.md +++ b/README.md @@ -40,19 +40,18 @@ To create projects, you can run: Note that you can't have more than one project in Xcode open at a time since they the static library project is shared across the OS X, Linux and iOS project. -Target OS: 10.9+ +Target OS X: 10.9+ ## iOS -If you just want to install the library for iOS and try it out as an Objective-C consumer, run `./scripts/package_ios.sh`. It will require the Boost headers to be installed, so use [Homebrew](http://brew.sh/) to install it via `brew install boost`. The script will produce the statically-linked `libMapboxGL.a`, `MapboxGL.bundle` for resources, and a `Headers` folder. +If you merely want to install the library for iOS and try it out as an Objective-C consumer, run `./scripts/package_ios.sh`. It requires the Boost headers to be installed, so use [Homebrew](http://brew.sh/) to install them (`brew install boost`). The packaging script will produce the statically-linked `libMapboxGL.a`, `MapboxGL.bundle` for resources, and a `Headers` folder. -If you want to build from source and/or contribute to development of the project, you can run `make iproj`, which will create and open an Xcode project which can build the entire library from source as well as an Objective-C test app. +If you want to build from source and/or contribute to development of the project, run `make iproj`, which will create and open an Xcode project which can build the entire library from source as well as an Objective-C test app. Target devices: iPhone 4S and above (5, 5c, 5s, 6, 6 Plus) and iPad 2 and above (3, 4, Mini, Air, Mini 2, Air 2). -iOS SDK: 8.1 -Supported iOS: 7.0+ +Target iOS: 7.0 through 8.1 ## Linux From 6d47e9b6849f7c383dc6e71d9e8d6baeaacf8e9f Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Tue, 10 Feb 2015 10:59:32 -0800 Subject: [PATCH 22/28] use correct interpolation for background images --- src/mbgl/renderer/painter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index ebb2f77cc..116ae3ad2 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; From ba6e3848dfd171722726ff91142ea5acc6d51c73 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Tue, 10 Feb 2015 11:21:00 -0800 Subject: [PATCH 23/28] Add target devices to Android README --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 002a530ca..0a19e7ecb 100644 --- a/README.md +++ b/README.md @@ -45,9 +45,9 @@ Target OS X: 10.9+ ## iOS -If you merely want to install the library for iOS and try it out as an Objective-C consumer, run `./scripts/package_ios.sh`. It requires the Boost headers to be installed, so use [Homebrew](http://brew.sh/) to install them (`brew install boost`). The packaging script will produce the statically-linked `libMapboxGL.a`, `MapboxGL.bundle` for resources, and a `Headers` folder. +If you merely want to install the library for iOS and try it out as an Objective-C consumer, run `./scripts/package_ios.sh`. It requires the Boost headers to be installed, so use [Homebrew](http://brew.sh/) to install them (`brew install boost`). The packaging script will produce the statically-linked `libMapboxGL.a`, `MapboxGL.bundle` for resources, and a `Headers` folder. -If you want to build from source and/or contribute to development of the project, run `make iproj`, which will create and open an Xcode project which can build the entire library from source as well as an Objective-C test app. +If you want to build from source and/or contribute to development of the project, run `make iproj`, which will create and open an Xcode project which can build the entire library from source as well as an Objective-C test app. Target devices: iPhone 4S and above (5, 5c, 5s, 6, 6 Plus) and iPad 2 and above (3, 4, Mini, Air, Mini 2, Air 2). @@ -100,7 +100,11 @@ Set an access token as described below, and then run: make run-linux -## Android (on Linux) +## Android + +Target devices: All Android devices on Android 4.0 or newer (API level >= 14) + +### On Linux Install a few build dependencies: @@ -125,7 +129,7 @@ Run: You can then open `android/java` in Android Studio via "Import Non-Android Studio Project". -## Android (on OS X) +### On OS X Install Oracle JDK 7 (requires license agreement) from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html From 9201133251a7e4bcc61ffecd9f08ce2d81e349a9 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Tue, 10 Feb 2015 11:47:50 -0800 Subject: [PATCH 24/28] fixes #764: cyclical iOS reference --- platform/ios/MGLMapView.mm | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index dde15567a..ecac9552c 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -1563,13 +1563,11 @@ class MBGLView : public mbgl::View { if (delay != std::chrono::steady_clock::duration::zero()) { - __weak MGLMapView *weakNativeView = nativeView; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, std::chrono::duration_cast(delay).count()), dispatch_get_main_queue(), ^ { - [weakNativeView performSelector:@selector(notifyMapChange:) - withObject:@(change) - afterDelay:0]; + [nativeView performSelector:@selector(notifyMapChange:) + withObject:@(change) + afterDelay:0]; }); } else @@ -1601,7 +1599,7 @@ class MBGLView : public mbgl::View } private: - MGLMapView *nativeView = nullptr; + __weak MGLMapView *nativeView = nullptr; }; @end From c5f35d0d11f329a5da543715c3181578af2b2b13 Mon Sep 17 00:00:00 2001 From: "Justin R. Miller" Date: Tue, 10 Feb 2015 12:21:40 -0800 Subject: [PATCH 25/28] fixes #839: add isPackedDepthStencilSupported & isDepth24Supported for iOS --- platform/ios/MGLMapView.mm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index ecac9552c..4328b4600 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -219,6 +219,14 @@ mbgl::DefaultFileSource *mbglFileSource = nullptr; gl::GenVertexArrays = glGenVertexArraysOES; gl::IsVertexArray = glIsVertexArrayOES; } + + if (extensions.find("GL_OES_packed_depth_stencil") != std::string::npos) { + gl::isPackedDepthStencilSupported = YES; + } + + if (extensions.find("GL_OES_depth24") != std::string::npos) { + gl::isDepth24Supported = YES; + } } // setup mbgl map From e8a2c393654a1ebfbc7502432fdd0a43398a0cdf Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Tue, 10 Feb 2015 10:53:44 -0800 Subject: [PATCH 26/28] forward declare GLX typedefs to limit conflicts from glx.h --- include/mbgl/platform/default/glx.h | 2 -- include/mbgl/platform/default/headless_view.hpp | 7 +++++-- platform/default/headless_display.cpp | 6 +++++- platform/default/headless_view.cpp | 6 ++++-- 4 files changed, 14 insertions(+), 7 deletions(-) delete mode 100644 include/mbgl/platform/default/glx.h diff --git a/include/mbgl/platform/default/glx.h b/include/mbgl/platform/default/glx.h deleted file mode 100644 index 6b7d9a3df..000000000 --- a/include/mbgl/platform/default/glx.h +++ /dev/null @@ -1,2 +0,0 @@ -#include -#undef None diff --git a/include/mbgl/platform/default/headless_view.hpp b/include/mbgl/platform/default/headless_view.hpp index 2fad430e6..ba318c2b4 100644 --- a/include/mbgl/platform/default/headless_view.hpp +++ b/include/mbgl/platform/default/headless_view.hpp @@ -5,9 +5,12 @@ #define MBGL_USE_CGL 1 #else #define GL_GLEXT_PROTOTYPES -#include #define MBGL_USE_GLX 1 -#undef Status +typedef struct _XDisplay Display; +typedef struct __GLXcontextRec* GLXContext; +typedef struct __GLXFBConfigRec* GLXFBConfig; +typedef long unsigned int XID; +typedef XID GLXPbuffer; #endif #include diff --git a/platform/default/headless_display.cpp b/platform/default/headless_display.cpp index 4756c8d2c..c4535fc1a 100644 --- a/platform/default/headless_display.cpp +++ b/platform/default/headless_display.cpp @@ -3,6 +3,10 @@ #include #include +#if MBGL_USE_GLX +#include +#endif + namespace mbgl { HeadlessDisplay::HeadlessDisplay() { @@ -52,7 +56,7 @@ HeadlessDisplay::HeadlessDisplay() { // We're creating a dummy pbuffer anyway that we're not using. static int pixelFormat[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT, - 0 + None }; int configs = 0; diff --git a/platform/default/headless_view.cpp b/platform/default/headless_view.cpp index 9df58f802..656a77439 100644 --- a/platform/default/headless_view.cpp +++ b/platform/default/headless_view.cpp @@ -28,6 +28,8 @@ CGLProc CGLGetProcAddress(const char *proc) { CFRelease(name); return symbol; } +#elif MBGL_USE_GLX +#include #endif namespace mbgl { @@ -104,7 +106,7 @@ void HeadlessView::createContext() { if (!glContext) { // Try to create a legacy context - glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, 0, True); + glContext = glXCreateNewContext(xDisplay, fbConfigs[0], GLX_RGBA_TYPE, None, True); if (glContext) { if (!glXIsDirect(xDisplay, glContext)) { mbgl::Log::Error(mbgl::Event::OpenGL, "Failed to create direct OpenGL Legacy context"); @@ -123,7 +125,7 @@ void HeadlessView::createContext() { int pbufferAttributes[] = { GLX_PBUFFER_WIDTH, 8, GLX_PBUFFER_HEIGHT, 8, - 0 + None }; glxPbuffer = glXCreatePbuffer(xDisplay, fbConfigs[0], pbufferAttributes); #endif From eaef4c08740097d11b11c1c087f73a034ced0097 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Mon, 9 Feb 2015 13:14:09 -0800 Subject: [PATCH 27/28] chmod +x python builds scripts, run directly instead of with python gyp var --- gyp/shaders.gypi | 2 +- gyp/version.gypi | 2 +- scripts/build-shaders.py | 0 scripts/build-version.py | 0 4 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 scripts/build-shaders.py mode change 100644 => 100755 scripts/build-version.py diff --git a/gyp/shaders.gypi b/gyp/shaders.gypi index edbcb61f2..fbf8e3197 100644 --- a/gyp/shaders.gypi +++ b/gyp/shaders.gypi @@ -16,7 +16,7 @@ '<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gl.cpp', '<(SHARED_INTERMEDIATE_DIR)/src/shader/shaders_gles2.cpp', ], - 'action': ['<@(python)', 'scripts/build-shaders.py', '<(SHARED_INTERMEDIATE_DIR)', '<@(_inputs)'], + 'action': ['scripts/build-shaders.py', '<(SHARED_INTERMEDIATE_DIR)', '<@(_inputs)'], } ], 'direct_dependent_settings': { diff --git a/gyp/version.gypi b/gyp/version.gypi index 68f777f0a..1cc2eb351 100644 --- a/gyp/version.gypi +++ b/gyp/version.gypi @@ -13,7 +13,7 @@ 'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/include/mbgl/util/version.hpp', ], - 'action': ['<@(python)', '<@(_inputs)', '<(SHARED_INTERMEDIATE_DIR)', ' Date: Mon, 9 Feb 2015 13:17:40 -0800 Subject: [PATCH 28/28] dont set python gyp var --- configure | 1 - 1 file changed, 1 deletion(-) diff --git a/configure b/configure index fec0bfd31..b818faa07 100755 --- a/configure +++ b/configure @@ -92,7 +92,6 @@ CONFIG="# Do not edit. Generated by the configure script. 'libraries': [] }, 'variables': { - 'python': '${PYTHON}', " if [ ! -z ${BOOST_VERSION} ]; then