diff options
author | Young Hahn <young@mapbox.com> | 2016-06-15 11:38:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-15 11:38:22 -0400 |
commit | 24b66bc8cdd40a52e08d198c063daa3e1f6be92a (patch) | |
tree | 6d98a5e1216a83f7d6d4c78422c8306d4a4cb157 /src | |
parent | fe64238b4cd5a7da403a4f29a62b14234ecba569 (diff) | |
download | qtlocation-mapboxgl-24b66bc8cdd40a52e08d198c063daa3e1f6be92a.tar.gz |
Color class (#5361)
* Color class
* Switch to list initialization
Diffstat (limited to 'src')
30 files changed, 69 insertions, 43 deletions
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index e4d30ec107..5f90140eb7 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -146,7 +146,7 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a if (frame.debugOptions & MapDebugOptions::Wireframe) { config.clearColor = { 0.0f, 0.0f, 0.0f, 1.0f }; } else { - config.clearColor = { background[0], background[1], background[2], background[3] }; + config.clearColor = { background.r, background.g, background.b, background.a }; } config.clearStencil = 0; config.clearDepth = 1; diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index 634eed67a7..402d0d23ba 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -45,7 +45,7 @@ void Painter::renderBackground(const BackgroundLayer& layer) { } else { if (wireframe) { - plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }}; + plainShader->u_color = { 0.0f, 0.0f, 0.0f, 1.0f }; plainShader->u_opacity = 1.0f; } else { plainShader->u_color = properties.backgroundColor; diff --git a/src/mbgl/renderer/painter_debug.cpp b/src/mbgl/renderer/painter_debug.cpp index 92fb3e5867..c368ac0345 100644 --- a/src/mbgl/renderer/painter_debug.cpp +++ b/src/mbgl/renderer/painter_debug.cpp @@ -8,6 +8,7 @@ #include <mbgl/gl/gl.hpp> #include <mbgl/gl/gl_values.hpp> #include <mbgl/gl/gl_helper.hpp> +#include <mbgl/util/color.hpp> using namespace mbgl; @@ -43,7 +44,7 @@ void Painter::renderDebugText(Tile& tile, const mat4 &matrix) { plainShader->u_matrix = matrix; // Draw white outline - plainShader->u_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; + plainShader->u_color = { 1.0f, 1.0f, 1.0f, 1.0f }; config.lineWidth = 4.0f * frame.pixelRatio; tile.debugBucket->drawLines(*plainShader, store); @@ -54,7 +55,7 @@ void Painter::renderDebugText(Tile& tile, const mat4 &matrix) { #endif // Draw black text. - plainShader->u_color = {{ 0.0f, 0.0f, 0.0f, 1.0f }}; + plainShader->u_color = { 0.0f, 0.0f, 0.0f, 1.0f }; config.lineWidth = 2.0f * frame.pixelRatio; tile.debugBucket->drawLines(*plainShader, store); @@ -77,7 +78,7 @@ void Painter::renderDebugFrame(const mat4 &matrix) { // draw tile outline tileBorderArray.bind(*plainShader, tileBorderBuffer, BUFFER_OFFSET_0, store); - plainShader->u_color = {{ 1.0f, 0.0f, 0.0f, 1.0f }}; + plainShader->u_color = { 1.0f, 0.0f, 0.0f, 1.0f }; config.lineWidth = 4.0f * frame.pixelRatio; MBGL_CHECK_ERROR(glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)tileBorderBuffer.index())); } diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 5317555727..d99069c6b3 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -24,7 +24,7 @@ void Painter::renderFill(FillBucket& bucket, float opacity = properties.fillOpacity; Color stroke_color = properties.fillOutlineColor; - if (stroke_color[3] < 0) { + if (stroke_color.a < 0) { stroke_color = fill_color; } @@ -34,8 +34,8 @@ void Painter::renderFill(FillBucket& bucket, bool wireframe = frame.debugOptions & MapDebugOptions::Wireframe; if (wireframe) { - fill_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; - stroke_color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; + fill_color = { 1.0f, 1.0f, 1.0f, 1.0f }; + stroke_color = { 1.0f, 1.0f, 1.0f, 1.0f }; opacity = 1.0f; pattern = false; outline = true; @@ -161,7 +161,7 @@ void Painter::renderFill(FillBucket& bucket, } } else if (!wireframe) { // No image fill. - if ((fill_color[3] >= 1.0f && opacity >= 1.0f) == (pass == RenderPass::Opaque)) { + if ((fill_color.a >= 1.0f && opacity >= 1.0f) == (pass == RenderPass::Opaque)) { // Only draw the fill when it's either opaque and we're drawing opaque // fragments or when it's translucent and we're drawing translucent // fragments diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index d21497d459..455535d337 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -37,7 +37,7 @@ void Painter::renderLine(LineBucket& bucket, float blur = properties.lineBlur + antialiasing; - Color color = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; + Color color { 1.0f, 1.0f, 1.0f, 1.0f }; float opacity = 1.0f; if (!wireframe) { color = properties.lineColor; diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 1a248d494b..b65ae34a12 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -88,7 +88,7 @@ void Painter::renderSDF(SymbolBucket &bucket, // We're drawing in the translucent pass which is bottom-to-top, so we need // to draw the halo first. - if (haloColor[3] > 0.0f && haloWidth > 0.0f) { + if (haloColor.a > 0.0f && haloWidth > 0.0f) { sdfShader.u_gamma = (haloBlur * blurOffset / fontScale / sdfPx + gamma) * gammaScale; sdfShader.u_color = haloColor; sdfShader.u_opacity = opacity; @@ -99,7 +99,7 @@ void Painter::renderSDF(SymbolBucket &bucket, } // Then, we draw the text/icon over the halo - if (color[3] > 0.0f) { + if (color.a > 0.0f) { sdfShader.u_gamma = gamma * gammaScale; sdfShader.u_color = color; sdfShader.u_opacity = opacity; diff --git a/src/mbgl/renderer/render_item.hpp b/src/mbgl/renderer/render_item.hpp index d452fb7759..a664f4b910 100644 --- a/src/mbgl/renderer/render_item.hpp +++ b/src/mbgl/renderer/render_item.hpp @@ -30,7 +30,7 @@ public: class RenderData { public: - Color backgroundColor = {{ 0, 0, 0, 0 }}; + Color backgroundColor = { 0, 0, 0, 0 }; std::set<style::Source*> sources; std::vector<RenderItem> order; }; diff --git a/src/mbgl/shader/circle_shader.hpp b/src/mbgl/shader/circle_shader.hpp index cd22d4c9b1..70faad9b78 100644 --- a/src/mbgl/shader/circle_shader.hpp +++ b/src/mbgl/shader/circle_shader.hpp @@ -2,6 +2,7 @@ #include <mbgl/shader/shader.hpp> #include <mbgl/shader/uniform.hpp> +#include <mbgl/util/color.hpp> namespace mbgl { @@ -14,7 +15,7 @@ public: UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform<std::array<GLfloat, 2>> u_extrude_scale = {"u_extrude_scale", *this}; Uniform<GLfloat> u_devicepixelratio = {"u_devicepixelratio", *this}; - Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this}; + Uniform<Color> u_color = {"u_color", *this}; Uniform<GLfloat> u_radius = {"u_radius", *this}; Uniform<GLfloat> u_blur = {"u_blur", *this}; Uniform<GLfloat> u_opacity = {"u_opacity", *this}; diff --git a/src/mbgl/shader/line_shader.hpp b/src/mbgl/shader/line_shader.hpp index e0d14094a6..1265e768f2 100644 --- a/src/mbgl/shader/line_shader.hpp +++ b/src/mbgl/shader/line_shader.hpp @@ -2,6 +2,7 @@ #include <mbgl/shader/shader.hpp> #include <mbgl/shader/uniform.hpp> +#include <mbgl/util/color.hpp> namespace mbgl { @@ -12,7 +13,7 @@ public: void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this}; + Uniform<Color> u_color = {"u_color", *this}; Uniform<GLfloat> u_opacity = {"u_opacity", *this}; Uniform<GLfloat> u_ratio = {"u_ratio", *this}; Uniform<GLfloat> u_linewidth = {"u_linewidth", *this}; diff --git a/src/mbgl/shader/linesdf_shader.hpp b/src/mbgl/shader/linesdf_shader.hpp index 8791f243c0..98bbc2b8f8 100644 --- a/src/mbgl/shader/linesdf_shader.hpp +++ b/src/mbgl/shader/linesdf_shader.hpp @@ -2,6 +2,7 @@ #include <mbgl/shader/shader.hpp> #include <mbgl/shader/uniform.hpp> +#include <mbgl/util/color.hpp> namespace mbgl { @@ -12,7 +13,7 @@ public: void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this}; + Uniform<Color> u_color = {"u_color", *this}; Uniform<GLfloat> u_opacity = {"u_opacity", *this}; Uniform<GLfloat> u_linewidth = {"u_linewidth", *this}; Uniform<GLfloat> u_gapwidth = {"u_gapwidth", *this}; diff --git a/src/mbgl/shader/outline_shader.hpp b/src/mbgl/shader/outline_shader.hpp index 25c873b4fe..5ec2c68e7f 100644 --- a/src/mbgl/shader/outline_shader.hpp +++ b/src/mbgl/shader/outline_shader.hpp @@ -2,6 +2,7 @@ #include <mbgl/shader/shader.hpp> #include <mbgl/shader/uniform.hpp> +#include <mbgl/util/color.hpp> namespace mbgl { @@ -12,7 +13,7 @@ public: void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<GLfloat, 4>> u_outline_color = {"u_outline_color", *this}; + Uniform<Color> u_outline_color = {"u_outline_color", *this}; Uniform<GLfloat> u_opacity = {"u_opacity", *this}; Uniform<std::array<GLfloat, 2>> u_world = {"u_world", *this}; }; diff --git a/src/mbgl/shader/plain_shader.hpp b/src/mbgl/shader/plain_shader.hpp index 7edf4b4b19..8eec69147e 100644 --- a/src/mbgl/shader/plain_shader.hpp +++ b/src/mbgl/shader/plain_shader.hpp @@ -2,6 +2,7 @@ #include <mbgl/shader/shader.hpp> #include <mbgl/shader/uniform.hpp> +#include <mbgl/util/color.hpp> namespace mbgl { @@ -12,7 +13,7 @@ public: void bind(GLbyte *offset) final; UniformMatrix<4> u_matrix = {"u_matrix", *this}; - Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this}; + Uniform<Color> u_color = {"u_color", *this}; Uniform<GLfloat> u_opacity = {"u_opacity", *this}; }; diff --git a/src/mbgl/shader/sdf_shader.hpp b/src/mbgl/shader/sdf_shader.hpp index 6889288c28..88f671b543 100644 --- a/src/mbgl/shader/sdf_shader.hpp +++ b/src/mbgl/shader/sdf_shader.hpp @@ -2,6 +2,7 @@ #include <mbgl/shader/shader.hpp> #include <mbgl/shader/uniform.hpp> +#include <mbgl/util/color.hpp> namespace mbgl { @@ -11,7 +12,7 @@ public: UniformMatrix<4> u_matrix = {"u_matrix", *this}; Uniform<std::array<GLfloat, 2>> u_extrude_scale = {"u_extrude_scale", *this}; - Uniform<std::array<GLfloat, 4>> u_color = {"u_color", *this}; + Uniform<Color> u_color = {"u_color", *this}; Uniform<GLfloat> u_opacity = {"u_opacity", *this}; Uniform<std::array<GLfloat, 2>> u_texsize = {"u_texsize", *this}; Uniform<GLfloat> u_buffer = {"u_buffer", *this}; diff --git a/src/mbgl/shader/uniform.cpp b/src/mbgl/shader/uniform.cpp index d43dd20016..4c7646119a 100644 --- a/src/mbgl/shader/uniform.cpp +++ b/src/mbgl/shader/uniform.cpp @@ -1,4 +1,5 @@ #include <mbgl/shader/uniform.hpp> +#include <mbgl/util/color.hpp> namespace mbgl { @@ -28,6 +29,12 @@ void Uniform<std::array<GLfloat, 4>>::bind(const std::array<GLfloat, 4>& t) { } template <> +void Uniform<Color>::bind(const Color& t) { + std::array<GLfloat, 4> a = {{ t.r, t.g, t.b, t.a }}; + MBGL_CHECK_ERROR(glUniform4fv(location, 1, a.data())); +} + +template <> void UniformMatrix<2>::bind(const std::array<GLfloat, 4>& t) { MBGL_CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, t.data())); } diff --git a/src/mbgl/style/layers/background_layer_properties.cpp b/src/mbgl/style/layers/background_layer_properties.cpp index f4c9b952b0..a20cedf12c 100644 --- a/src/mbgl/style/layers/background_layer_properties.cpp +++ b/src/mbgl/style/layers/background_layer_properties.cpp @@ -1,7 +1,6 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. #include <mbgl/style/layers/background_layer_properties.hpp> -#include <utility> namespace mbgl { namespace style { diff --git a/src/mbgl/style/layers/background_layer_properties.hpp b/src/mbgl/style/layers/background_layer_properties.hpp index a1a1a3a5a7..60e4b22684 100644 --- a/src/mbgl/style/layers/background_layer_properties.hpp +++ b/src/mbgl/style/layers/background_layer_properties.hpp @@ -18,7 +18,7 @@ public: void cascade(const CascadeParameters&); bool recalculate(const CalculationParameters&); - PaintProperty<Color> backgroundColor { {{ 0, 0, 0, 1 }} }; + PaintProperty<Color> backgroundColor { { 0, 0, 0, 1 } }; PaintProperty<std::string, CrossFadedPropertyEvaluator> backgroundPattern { "" }; PaintProperty<float> backgroundOpacity { 1 }; }; diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp index c2efac5cef..d64759e743 100644 --- a/src/mbgl/style/layers/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -19,7 +19,7 @@ void CircleLayer::Impl::cascade(const CascadeParameters& parameters) { bool CircleLayer::Impl::recalculate(const CalculationParameters& parameters) { bool hasTransitions = paint.recalculate(parameters); - passes = (paint.circleRadius > 0 && paint.circleColor.value[3] > 0 && paint.circleOpacity > 0) + passes = (paint.circleRadius > 0 && paint.circleColor.value.a > 0 && paint.circleOpacity > 0) ? RenderPass::Translucent : RenderPass::None; return hasTransitions; diff --git a/src/mbgl/style/layers/circle_layer_properties.cpp b/src/mbgl/style/layers/circle_layer_properties.cpp index fed6d5cddc..b21df1e2d0 100644 --- a/src/mbgl/style/layers/circle_layer_properties.cpp +++ b/src/mbgl/style/layers/circle_layer_properties.cpp @@ -1,7 +1,6 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. #include <mbgl/style/layers/circle_layer_properties.hpp> -#include <utility> namespace mbgl { namespace style { diff --git a/src/mbgl/style/layers/circle_layer_properties.hpp b/src/mbgl/style/layers/circle_layer_properties.hpp index 956e423c45..35c0f1ad51 100644 --- a/src/mbgl/style/layers/circle_layer_properties.hpp +++ b/src/mbgl/style/layers/circle_layer_properties.hpp @@ -19,7 +19,7 @@ public: bool recalculate(const CalculationParameters&); PaintProperty<float> circleRadius { 5 }; - PaintProperty<Color> circleColor { {{ 0, 0, 0, 1 }} }; + PaintProperty<Color> circleColor { { 0, 0, 0, 1 } }; PaintProperty<float> circleBlur { 0 }; PaintProperty<float> circleOpacity { 1 }; PaintProperty<std::array<float, 2>> circleTranslate { {{ 0, 0 }} }; diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp index c183617482..3d847127c9 100644 --- a/src/mbgl/style/layers/fill_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_layer_impl.cpp @@ -25,7 +25,7 @@ bool FillLayer::Impl::recalculate(const CalculationParameters& parameters) { passes |= RenderPass::Translucent; } - if (!paint.fillPattern.value.from.empty() || (paint.fillColor.value[3] * paint.fillOpacity) < 1.0f) { + if (!paint.fillPattern.value.from.empty() || (paint.fillColor.value.a * paint.fillOpacity) < 1.0f) { passes |= RenderPass::Translucent; } else { passes |= RenderPass::Opaque; diff --git a/src/mbgl/style/layers/fill_layer_properties.hpp b/src/mbgl/style/layers/fill_layer_properties.hpp index 43396f45d2..09aa432d23 100644 --- a/src/mbgl/style/layers/fill_layer_properties.hpp +++ b/src/mbgl/style/layers/fill_layer_properties.hpp @@ -20,8 +20,8 @@ public: PaintProperty<bool> fillAntialias { true }; PaintProperty<float> fillOpacity { 1 }; - PaintProperty<Color> fillColor { {{ 0, 0, 0, 1 }} }; - PaintProperty<Color> fillOutlineColor { {{ 0, 0, 0, -1 }} }; + PaintProperty<Color> fillColor { { 0, 0, 0, 1 } }; + PaintProperty<Color> fillOutlineColor { { 0, 0, 0, -1 } }; PaintProperty<std::array<float, 2>> fillTranslate { {{ 0, 0 }} }; PaintProperty<TranslateAnchorType> fillTranslateAnchor { TranslateAnchorType::Map }; PaintProperty<std::string, CrossFadedPropertyEvaluator> fillPattern { "" }; diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs index 55e07ad61b..8ea713e20a 100644 --- a/src/mbgl/style/layers/layer_properties.hpp.ejs +++ b/src/mbgl/style/layers/layer_properties.hpp.ejs @@ -39,7 +39,7 @@ public: <% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%> PaintProperty<<%- propertyType(property) %>, CrossFadedPropertyEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; <% } else if (property.name === 'fill-outline-color') { -%> - PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { {{ 0, 0, 0, -1 }} }; + PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { { 0, 0, 0, -1 } }; <% } else { -%> PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; <% } -%> diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp index b7ee9dc5bf..589b129ee6 100644 --- a/src/mbgl/style/layers/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -29,7 +29,7 @@ bool LineLayer::Impl::recalculate(const CalculationParameters& parameters) { bool hasTransitions = paint.recalculate(parameters); - passes = (paint.lineOpacity > 0 && paint.lineColor.value[3] > 0 && paint.lineWidth > 0) + passes = (paint.lineOpacity > 0 && paint.lineColor.value.a > 0 && paint.lineWidth > 0) ? RenderPass::Translucent : RenderPass::None; return hasTransitions; diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp index 01a8534222..c715171c88 100644 --- a/src/mbgl/style/layers/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -30,7 +30,7 @@ public: bool recalculate(const CalculationParameters&); PaintProperty<float> lineOpacity { 1 }; - PaintProperty<Color> lineColor { {{ 0, 0, 0, 1 }} }; + PaintProperty<Color> lineColor { { 0, 0, 0, 1 } }; PaintProperty<std::array<float, 2>> lineTranslate { {{ 0, 0 }} }; PaintProperty<TranslateAnchorType> lineTranslateAnchor { TranslateAnchorType::Map }; PaintProperty<float> lineWidth { 1 }; diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index 34438285c5..eeceb52078 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -26,8 +26,8 @@ bool SymbolLayer::Impl::recalculate(const CalculationParameters& parameters) { iconSize = layout.iconSize; textSize = layout.textSize; - passes = ((paint.iconOpacity > 0 && (paint.iconColor.value[3] > 0 || paint.iconHaloColor.value[3] > 0) && iconSize > 0) - || (paint.textOpacity > 0 && (paint.textColor.value[3] > 0 || paint.textHaloColor.value[3] > 0) && textSize > 0)) + passes = ((paint.iconOpacity > 0 && (paint.iconColor.value.a > 0 || paint.iconHaloColor.value.a > 0) && iconSize > 0) + || (paint.textOpacity > 0 && (paint.textColor.value.a > 0 || paint.textHaloColor.value.a > 0) && textSize > 0)) ? RenderPass::Translucent : RenderPass::None; return hasTransitions; diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index e938a09c56..772445f051 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -58,15 +58,15 @@ public: bool recalculate(const CalculationParameters&); PaintProperty<float> iconOpacity { 1 }; - PaintProperty<Color> iconColor { {{ 0, 0, 0, 1 }} }; - PaintProperty<Color> iconHaloColor { {{ 0, 0, 0, 0 }} }; + PaintProperty<Color> iconColor { { 0, 0, 0, 1 } }; + PaintProperty<Color> iconHaloColor { { 0, 0, 0, 0 } }; PaintProperty<float> iconHaloWidth { 0 }; PaintProperty<float> iconHaloBlur { 0 }; PaintProperty<std::array<float, 2>> iconTranslate { {{ 0, 0 }} }; PaintProperty<TranslateAnchorType> iconTranslateAnchor { TranslateAnchorType::Map }; PaintProperty<float> textOpacity { 1 }; - PaintProperty<Color> textColor { {{ 0, 0, 0, 1 }} }; - PaintProperty<Color> textHaloColor { {{ 0, 0, 0, 0 }} }; + PaintProperty<Color> textColor { { 0, 0, 0, 1 } }; + PaintProperty<Color> textHaloColor { { 0, 0, 0, 0 } }; PaintProperty<float> textHaloWidth { 0 }; PaintProperty<float> textHaloBlur { 0 }; PaintProperty<std::array<float, 2>> textTranslate { {{ 0, 0 }} }; diff --git a/src/mbgl/style/property_evaluator.cpp b/src/mbgl/style/property_evaluator.cpp index 3993456b6d..7b91b9e500 100644 --- a/src/mbgl/style/property_evaluator.cpp +++ b/src/mbgl/style/property_evaluator.cpp @@ -15,7 +15,7 @@ inline T defaultStopsValue(); template <> inline bool defaultStopsValue() { return true; } template <> inline float defaultStopsValue() { return 1.0f; } -template <> inline Color defaultStopsValue() { return {{ 0, 0, 0, 1 }}; } +template <> inline Color defaultStopsValue() { return { 0, 0, 0, 1 }; } template <> inline std::vector<float> defaultStopsValue() { return {{ 1, 0 }}; } template <> inline std::vector<std::string> defaultStopsValue() { return {{}}; } template <> inline std::array<float, 2> defaultStopsValue() { return {{ 0, 0 }}; } diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp index 9985cc7f39..f5e0cca993 100644 --- a/src/mbgl/style/property_parsing.cpp +++ b/src/mbgl/style/property_parsing.cpp @@ -49,10 +49,10 @@ optional<Color> parseConstant(const char* name, const JSValue& value) { // Premultiply the color. const float factor = css_color.a / 255; - return Color{{(float)css_color.r * factor, + return Color{ (float)css_color.r * factor, (float)css_color.g * factor, (float)css_color.b * factor, - css_color.a}}; + css_color.a }; } template <> diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 5dd00bd309..44192fc985 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -267,10 +267,10 @@ RenderData Style::getRenderData() const { if (layer.get() == layers[0].get() && paint.backgroundPattern.value.from.empty()) { // This is a solid background. We can use glClear(). result.backgroundColor = paint.backgroundColor; - result.backgroundColor[0] *= paint.backgroundOpacity; - result.backgroundColor[1] *= paint.backgroundOpacity; - result.backgroundColor[2] *= paint.backgroundOpacity; - result.backgroundColor[3] *= paint.backgroundOpacity; + result.backgroundColor.r *= paint.backgroundOpacity; + result.backgroundColor.g *= paint.backgroundOpacity; + result.backgroundColor.b *= paint.backgroundOpacity; + result.backgroundColor.a *= paint.backgroundOpacity; } else { // This is a textured background, or not the bottommost layer. We need to render it with a quad. result.order.emplace_back(*layer); diff --git a/src/mbgl/util/interpolate.hpp b/src/mbgl/util/interpolate.hpp index 18a9e6bbc5..8b9929fa4a 100644 --- a/src/mbgl/util/interpolate.hpp +++ b/src/mbgl/util/interpolate.hpp @@ -5,6 +5,7 @@ #include <string> #include <type_traits> #include <utility> +#include <mbgl/util/color.hpp> namespace mbgl { namespace util { @@ -41,6 +42,19 @@ public: } }; +template <> +struct Interpolator<Color> { +public: + Color operator()(const Color& a, const Color& b, const double t) { + return { + interpolate(a.r, b.r, t), + interpolate(a.g, b.g, t), + interpolate(a.b, b.b, t), + interpolate(a.a, b.a, t) + }; + } +}; + struct Uninterpolated { template <class T> T operator()(const T&, const T& b, const double) const { |