summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/annotation/annotation.hpp4
-rw-r--r--include/mbgl/gl/gl_values.hpp7
-rw-r--r--include/mbgl/util/color.hpp18
-rw-r--r--src/mbgl/renderer/painter.cpp4
-rw-r--r--src/mbgl/renderer/painter_background.cpp2
-rw-r--r--src/mbgl/renderer/painter_debug.cpp4
-rw-r--r--src/mbgl/renderer/painter_fill.cpp4
-rw-r--r--src/mbgl/renderer/painter_line.cpp2
-rw-r--r--src/mbgl/renderer/render_item.hpp2
-rw-r--r--src/mbgl/style/style.cpp6
10 files changed, 29 insertions, 24 deletions
diff --git a/include/mbgl/annotation/annotation.hpp b/include/mbgl/annotation/annotation.hpp
index fc0595af0f..e8ac9a2fb7 100644
--- a/include/mbgl/annotation/annotation.hpp
+++ b/include/mbgl/annotation/annotation.hpp
@@ -30,14 +30,14 @@ public:
ShapeAnnotationGeometry geometry;
float opacity = 1;
float width = 1;
- Color color = { 0, 0, 0, 1 };
+ Color color = Color::black();
};
class FillAnnotation {
public:
ShapeAnnotationGeometry geometry;
float opacity = 1;
- Color color = { 0, 0, 0, 1 };
+ Color color = Color::black();
Color outlineColor = { 0, 0, 0, -1 };
};
diff --git a/include/mbgl/gl/gl_values.hpp b/include/mbgl/gl/gl_values.hpp
index 4204ca8e13..0d7d294cf7 100644
--- a/include/mbgl/gl/gl_values.hpp
+++ b/include/mbgl/gl/gl_values.hpp
@@ -5,6 +5,7 @@
#include <array>
#include <mbgl/gl/gl.hpp>
+#include <mbgl/util/color.hpp>
namespace mbgl {
namespace gl {
@@ -23,7 +24,7 @@ struct ClearDepth {
};
struct ClearColor {
- struct Type { GLfloat r, g, b, a; };
+ using Type = Color;
static const Type Default;
inline static void Set(const Type& value) {
MBGL_CHECK_ERROR(glClearColor(value.r, value.g, value.b, value.a));
@@ -35,10 +36,6 @@ struct ClearColor {
}
};
-inline bool operator!=(const ClearColor::Type& a, const ClearColor::Type& b) {
- return a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a;
-}
-
struct ClearStencil {
using Type = GLint;
static const Type Default;
diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp
index 82cd3c42e7..87d3175178 100644
--- a/include/mbgl/util/color.hpp
+++ b/include/mbgl/util/color.hpp
@@ -11,14 +11,26 @@ public:
float g = 0.0f;
float b = 0.0f;
float a = 0.0f;
+
+ static constexpr Color black() { return { 0.0f, 0.0f, 0.0f, 1.0f }; };
+ static constexpr Color white() { return { 1.0f, 1.0f, 1.0f, 1.0f }; };
};
-inline bool operator== (const Color& colorA, const Color& colorB) {
+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);
+inline bool operator!=(const Color& colorA, const Color& colorB) {
+ return !(colorA == colorB);
+}
+
+inline Color operator*(const Color& color, float alpha) {
+ return {
+ color.r * alpha,
+ color.g * alpha,
+ color.b * alpha,
+ color.a * alpha
+ };
}
} // namespace mbgl
diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp
index 5f90140eb7..eee568ec92 100644
--- a/src/mbgl/renderer/painter.cpp
+++ b/src/mbgl/renderer/painter.cpp
@@ -144,9 +144,9 @@ void Painter::render(const Style& style, const FrameData& frame_, SpriteAtlas& a
config.depthMask = GL_TRUE;
config.colorMask = { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
if (frame.debugOptions & MapDebugOptions::Wireframe) {
- config.clearColor = { 0.0f, 0.0f, 0.0f, 1.0f };
+ config.clearColor = Color::black();
} else {
- config.clearColor = { background.r, background.g, background.b, background.a };
+ config.clearColor = background;
}
config.clearStencil = 0;
config.clearDepth = 1;
diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp
index e6fa79eb51..022d3dd7ab 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 = Color::black();
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 c368ac0345..9ddae289ee 100644
--- a/src/mbgl/renderer/painter_debug.cpp
+++ b/src/mbgl/renderer/painter_debug.cpp
@@ -44,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 = Color::white();
config.lineWidth = 4.0f * frame.pixelRatio;
tile.debugBucket->drawLines(*plainShader, store);
@@ -55,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 = Color::black();
config.lineWidth = 2.0f * frame.pixelRatio;
tile.debugBucket->drawLines(*plainShader, store);
diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp
index 087dcf2f58..710fa444e2 100644
--- a/src/mbgl/renderer/painter_fill.cpp
+++ b/src/mbgl/renderer/painter_fill.cpp
@@ -38,8 +38,8 @@ void Painter::renderFill(FillBucket& bucket,
bool wireframe = frame.debugOptions & MapDebugOptions::Wireframe;
if (wireframe) {
- fillColor = { 1.0f, 1.0f, 1.0f, 1.0f };
- strokeColor = { 1.0f, 1.0f, 1.0f, 1.0f };
+ fillColor = Color::white();
+ strokeColor = Color::white();
opacity = 1.0f;
pattern = false;
outline = true;
diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp
index 455535d337..bb759abc5f 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 = Color::white();
float opacity = 1.0f;
if (!wireframe) {
color = properties.lineColor;
diff --git a/src/mbgl/renderer/render_item.hpp b/src/mbgl/renderer/render_item.hpp
index a664f4b910..82ea897047 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;
std::set<style::Source*> sources;
std::vector<RenderItem> order;
};
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index 44192fc985..af19c41393 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -266,11 +266,7 @@ RenderData Style::getRenderData() const {
const BackgroundPaintProperties& paint = background->impl->paint;
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.r *= paint.backgroundOpacity;
- result.backgroundColor.g *= paint.backgroundOpacity;
- result.backgroundColor.b *= paint.backgroundOpacity;
- result.backgroundColor.a *= paint.backgroundOpacity;
+ result.backgroundColor = paint.backgroundColor * 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);