summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/annotation/annotation.hpp6
-rw-r--r--include/mbgl/util/color.hpp16
-rwxr-xr-xplatform/android/src/jni.cpp2
-rw-r--r--platform/darwin/src/MGLMultiPoint.mm4
-rw-r--r--platform/ios/src/MGLMapView.mm4
-rw-r--r--platform/macos/src/MGLMapView.mm4
-rw-r--r--scripts/generate-style-code.js2
-rw-r--r--src/mbgl/renderer/painter.cpp2
-rw-r--r--src/mbgl/renderer/painter_background.cpp2
-rw-r--r--src/mbgl/renderer/painter_debug.cpp7
-rw-r--r--src/mbgl/renderer/painter_fill.cpp8
-rw-r--r--src/mbgl/renderer/painter_line.cpp2
-rw-r--r--src/mbgl/renderer/painter_symbol.cpp4
-rw-r--r--src/mbgl/renderer/render_item.hpp2
-rw-r--r--src/mbgl/shader/circle_shader.hpp3
-rw-r--r--src/mbgl/shader/line_shader.hpp3
-rw-r--r--src/mbgl/shader/linesdf_shader.hpp3
-rw-r--r--src/mbgl/shader/outline_shader.hpp3
-rw-r--r--src/mbgl/shader/plain_shader.hpp3
-rw-r--r--src/mbgl/shader/sdf_shader.hpp3
-rw-r--r--src/mbgl/shader/uniform.cpp7
-rw-r--r--src/mbgl/style/layers/background_layer_properties.cpp1
-rw-r--r--src/mbgl/style/layers/background_layer_properties.hpp2
-rw-r--r--src/mbgl/style/layers/circle_layer_impl.cpp2
-rw-r--r--src/mbgl/style/layers/circle_layer_properties.cpp1
-rw-r--r--src/mbgl/style/layers/circle_layer_properties.hpp2
-rw-r--r--src/mbgl/style/layers/fill_layer_impl.cpp2
-rw-r--r--src/mbgl/style/layers/fill_layer_properties.hpp4
-rw-r--r--src/mbgl/style/layers/layer_properties.hpp.ejs2
-rw-r--r--src/mbgl/style/layers/line_layer_impl.cpp2
-rw-r--r--src/mbgl/style/layers/line_layer_properties.hpp2
-rw-r--r--src/mbgl/style/layers/symbol_layer_impl.cpp4
-rw-r--r--src/mbgl/style/layers/symbol_layer_properties.hpp8
-rw-r--r--src/mbgl/style/property_evaluator.cpp2
-rw-r--r--src/mbgl/style/property_parsing.cpp4
-rw-r--r--src/mbgl/style/style.cpp8
-rw-r--r--src/mbgl/util/interpolate.hpp14
-rw-r--r--test/api/annotations.cpp9
-rw-r--r--test/map/map.cpp5
-rw-r--r--test/style/style_layer.cpp3
40 files changed, 105 insertions, 62 deletions
diff --git a/include/mbgl/annotation/annotation.hpp b/include/mbgl/annotation/annotation.hpp
index 6cb26e6a82..fc0595af0f 100644
--- a/include/mbgl/annotation/annotation.hpp
+++ b/include/mbgl/annotation/annotation.hpp
@@ -30,15 +30,15 @@ public:
ShapeAnnotationGeometry geometry;
float opacity = 1;
float width = 1;
- Color color = {{ 0, 0, 0, 1 }};
+ Color color = { 0, 0, 0, 1 };
};
class FillAnnotation {
public:
ShapeAnnotationGeometry geometry;
float opacity = 1;
- Color color = {{ 0, 0, 0, 1 }};
- Color outlineColor = {{ 0, 0, 0, -1 }};
+ Color color = { 0, 0, 0, 1 };
+ Color outlineColor = { 0, 0, 0, -1 };
};
// An annotation whose type and properties are sourced from a style layer.
diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp
index d7fe61c640..82cd3c42e7 100644
--- a/include/mbgl/util/color.hpp
+++ b/include/mbgl/util/color.hpp
@@ -5,6 +5,20 @@
namespace mbgl {
// Stores a premultiplied color, with all four channels ranging from 0..1
-using Color = std::array<float, 4>;
+class Color {
+public:
+ float r = 0.0f;
+ float g = 0.0f;
+ float b = 0.0f;
+ float a = 0.0f;
+};
+
+inline bool operator== (const Color& colorA, const Color& colorB) {
+ return colorA.r == colorB.r && colorA.g == colorB.g && colorA.b == colorB.b && colorA.a == colorB.a;
+}
+
+inline bool operator!= (const Color& colorA, const Color& colorB) {
+ return !(colorA.r == colorB.r && colorA.g == colorB.g && colorA.b == colorB.b && colorA.a == colorB.a);
+}
} // namespace mbgl
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 077f574469..a790064d53 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -711,7 +711,7 @@ static mbgl::Color toColor(jint color) {
float g = (color >> 8) & 0xFF;
float b = (color) & 0xFF;
float a = (color >> 24) & 0xFF;
- return {{ r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f }};
+ return { r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f };
}
template <class Geometry>
diff --git a/platform/darwin/src/MGLMultiPoint.mm b/platform/darwin/src/MGLMultiPoint.mm
index 6084535d05..a5b9eb8efc 100644
--- a/platform/darwin/src/MGLMultiPoint.mm
+++ b/platform/darwin/src/MGLMultiPoint.mm
@@ -5,11 +5,11 @@
mbgl::Color MGLColorObjectFromCGColorRef(CGColorRef cgColor) {
if (!cgColor) {
- return {{ 0, 0, 0, 0 }};
+ return { 0, 0, 0, 0 };
}
NSCAssert(CGColorGetNumberOfComponents(cgColor) >= 4, @"Color must have at least 4 components");
const CGFloat *components = CGColorGetComponents(cgColor);
- return {{ (float)components[0], (float)components[1], (float)components[2], (float)components[3] }};
+ return { (float)components[0], (float)components[1], (float)components[2], (float)components[3] };
}
@implementation MGLMultiPoint
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 4e304b23a5..4c09894a11 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -126,11 +126,11 @@ mbgl::Color MGLColorObjectFromUIColor(UIColor *color)
{
if (!color)
{
- return {{ 0, 0, 0, 0 }};
+ return { 0, 0, 0, 0 };
}
CGFloat r, g, b, a;
[color getRed:&r green:&g blue:&b alpha:&a];
- return {{ (float)r, (float)g, (float)b, (float)a }};
+ return { (float)r, (float)g, (float)b, (float)a };
}
@interface MGLAnnotationAccessibilityElement : UIAccessibilityElement
diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm
index 2f985b85d8..07b5259c7e 100644
--- a/platform/macos/src/MGLMapView.mm
+++ b/platform/macos/src/MGLMapView.mm
@@ -126,11 +126,11 @@ mbgl::util::UnitBezier MGLUnitBezierForMediaTimingFunction(CAMediaTimingFunction
/// Converts the given color into an mbgl::Color in calibrated RGB space.
mbgl::Color MGLColorObjectFromNSColor(NSColor *color) {
if (!color) {
- return {{ 0, 0, 0, 0 }};
+ return { 0, 0, 0, 0 };
}
CGFloat r, g, b, a;
[[color colorUsingColorSpaceName:NSCalibratedRGBColorSpace] getRed:&r green:&g blue:&b alpha:&a];
- return {{ (float)r, (float)g, (float)b, (float)a }};
+ return { (float)r, (float)g, (float)b, (float)a };
}
/// Lightweight container for metadata about an annotation, including the annotation itself.
diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js
index 6469cf55fd..7859c65a0e 100644
--- a/scripts/generate-style-code.js
+++ b/scripts/generate-style-code.js
@@ -63,7 +63,7 @@ global.defaultValue = function (property) {
return `${propertyType(property)}::${camelize(property.default)}`;
}
case 'color':
- return `{{ ${parseCSSColor(property.default).join(', ')} }}`
+ return `{ ${parseCSSColor(property.default).join(', ')} }`
case 'array':
const defaults = (property.default || []).map((e) => defaultValue({ type: property.value, default: e }));
if (property.length) {
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 {
diff --git a/test/api/annotations.cpp b/test/api/annotations.cpp
index fefc1c79b1..abe3862f4e 100644
--- a/test/api/annotations.cpp
+++ b/test/api/annotations.cpp
@@ -8,6 +8,7 @@
#include <mbgl/platform/default/headless_view.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
+#include <mbgl/util/color.hpp>
using namespace mbgl;
@@ -48,7 +49,7 @@ TEST(Annotations, LineAnnotation) {
LineString<double> line = {{ { 0, 0 }, { 45, 45 }, { 30, 0 } }};
LineAnnotation annotation { line };
- annotation.color = {{ 255, 0, 0, 1 }};
+ annotation.color = { 255, 0, 0, 1 };
annotation.width = 5;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
@@ -61,7 +62,7 @@ TEST(Annotations, FillAnnotation) {
Polygon<double> polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }};
FillAnnotation annotation { polygon };
- annotation.color = {{ 255, 0, 0, 1 }};
+ annotation.color = { 255, 0, 0, 1 };
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
test.map.addAnnotation(annotation);
@@ -99,7 +100,7 @@ TEST(Annotations, NonImmediateAdd) {
Polygon<double> polygon = {{ {{ { 0, 0 }, { 0, 45 }, { 45, 45 }, { 45, 0 } }} }};
FillAnnotation annotation { polygon };
- annotation.color = {{ 255, 0, 0, 1 }};
+ annotation.color = { 255, 0, 0, 1 };
test.map.addAnnotation(annotation);
test.checkRendering("non_immediate_add");
@@ -153,7 +154,7 @@ TEST(Annotations, RemoveShape) {
LineString<double> line = {{ { 0, 0 }, { 45, 45 } }};
LineAnnotation annotation { line };
- annotation.color = {{ 255, 0, 0, 1 }};
+ annotation.color = { 255, 0, 0, 1 };
annotation.width = 5;
test.map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
diff --git a/test/map/map.cpp b/test/map/map.cpp
index 57adee567d..b304712e1f 100644
--- a/test/map/map.cpp
+++ b/test/map/map.cpp
@@ -9,6 +9,7 @@
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/style/layers/background_layer.hpp>
+#include <mbgl/util/color.hpp>
using namespace mbgl;
using namespace mbgl::style;
@@ -67,7 +68,7 @@ TEST(Map, AddLayer) {
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
auto layer = std::make_unique<BackgroundLayer>("background");
- layer->setBackgroundColor({{{ 1, 0, 0, 1 }}});
+ layer->setBackgroundColor({{ 1, 0, 0, 1 }});
map.addLayer(std::move(layer));
test::checkImage("test/fixtures/map/add_layer", test::render(map));
@@ -80,7 +81,7 @@ TEST(Map, RemoveLayer) {
map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"));
auto layer = std::make_unique<BackgroundLayer>("background");
- layer->setBackgroundColor({{{ 1, 0, 0, 1 }}});
+ layer->setBackgroundColor({{ 1, 0, 0, 1 }});
map.addLayer(std::move(layer));
map.removeLayer("background");
diff --git a/test/style/style_layer.cpp b/test/style/style_layer.cpp
index 8af7a07d30..3274131966 100644
--- a/test/style/style_layer.cpp
+++ b/test/style/style_layer.cpp
@@ -13,6 +13,7 @@
#include <mbgl/style/layers/raster_layer_impl.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
+#include <mbgl/util/color.hpp>
using namespace mbgl;
using namespace mbgl::style;
@@ -28,7 +29,7 @@ template <class T, class... Params> void testClone(Params... params) {
EXPECT_EQ("test", layer->baseImpl->clone()->getID());
}
-const auto color = PropertyValue<Color> {{{ 1, 0, 0, 1 }}};
+const auto color = PropertyValue<Color> {{ 1, 0, 0, 1 }};
const auto opacity = PropertyValue<float> { 1.0f };
const auto radius = PropertyValue<float> { 1.0f };
const auto blur = PropertyValue<float> { 1.0f };