summaryrefslogtreecommitdiff
path: root/src/mbgl/gl
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2019-02-28 16:19:33 +0100
committerKonstantin Käfer <mail@kkaefer.com>2019-03-01 09:33:37 +0100
commitda6e1390c68e01e02652104586c759d46e04c7fd (patch)
tree002942c69e886a2ad86ac7bea8272d36a16c28e2 /src/mbgl/gl
parentfd37d9065029c732d97e6fa59bc0a0d27ecd3c72 (diff)
downloadqtlocation-mapboxgl-da6e1390c68e01e02652104586c759d46e04c7fd.tar.gz
[core] move ColorMode to gfx namespace
Diffstat (limited to 'src/mbgl/gl')
-rw-r--r--src/mbgl/gl/color_mode.cpp44
-rw-r--r--src/mbgl/gl/color_mode.hpp99
-rw-r--r--src/mbgl/gl/context.cpp6
-rw-r--r--src/mbgl/gl/context.hpp4
-rw-r--r--src/mbgl/gl/program.hpp2
-rw-r--r--src/mbgl/gl/value.cpp75
-rw-r--r--src/mbgl/gl/value.hpp14
7 files changed, 83 insertions, 161 deletions
diff --git a/src/mbgl/gl/color_mode.cpp b/src/mbgl/gl/color_mode.cpp
deleted file mode 100644
index e524bfdf98..0000000000
--- a/src/mbgl/gl/color_mode.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-#include <mbgl/gl/color_mode.hpp>
-#include <mbgl/gl/defines.hpp>
-#include <mbgl/util/traits.hpp>
-
-namespace mbgl {
-namespace gl {
-
-static_assert(underlying_type(ColorMode::BlendEquation::Add) == GL_FUNC_ADD, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::BlendEquation::Subtract) == GL_FUNC_SUBTRACT, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::BlendEquation::ReverseSubtract) == GL_FUNC_REVERSE_SUBTRACT, "OpenGL enum mismatch");
-
-static_assert(underlying_type(ColorMode::Zero) == GL_ZERO, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::One) == GL_ONE, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::SrcColor) == GL_SRC_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusSrcColor) == GL_ONE_MINUS_SRC_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::DstColor) == GL_DST_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusDstColor) == GL_ONE_MINUS_DST_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::SrcAlpha) == GL_SRC_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusSrcAlpha) == GL_ONE_MINUS_SRC_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::DstAlpha) == GL_DST_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusDstAlpha) == GL_ONE_MINUS_DST_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::ConstantColor) == GL_CONSTANT_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusConstantColor) == GL_ONE_MINUS_CONSTANT_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::ConstantAlpha) == GL_CONSTANT_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusConstantAlpha) == GL_ONE_MINUS_CONSTANT_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::SrcAlphaSaturate) == GL_SRC_ALPHA_SATURATE, "OpenGL enum mismatch");
-
-static_assert(underlying_type(ColorMode::Zero) == GL_ZERO, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::One) == GL_ONE, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::SrcColor) == GL_SRC_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusSrcColor) == GL_ONE_MINUS_SRC_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::DstColor) == GL_DST_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusDstColor) == GL_ONE_MINUS_DST_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::SrcAlpha) == GL_SRC_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusSrcAlpha) == GL_ONE_MINUS_SRC_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::DstAlpha) == GL_DST_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusDstAlpha) == GL_ONE_MINUS_DST_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::ConstantColor) == GL_CONSTANT_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusConstantColor) == GL_ONE_MINUS_CONSTANT_COLOR, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::ConstantAlpha) == GL_CONSTANT_ALPHA, "OpenGL enum mismatch");
-static_assert(underlying_type(ColorMode::OneMinusConstantAlpha) == GL_ONE_MINUS_CONSTANT_ALPHA, "OpenGL enum mismatch");
-
-} // namespace gl
-} // namespace mbgl
diff --git a/src/mbgl/gl/color_mode.hpp b/src/mbgl/gl/color_mode.hpp
deleted file mode 100644
index e394f43501..0000000000
--- a/src/mbgl/gl/color_mode.hpp
+++ /dev/null
@@ -1,99 +0,0 @@
-#pragma once
-
-#include <mbgl/util/variant.hpp>
-#include <mbgl/util/color.hpp>
-
-namespace mbgl {
-namespace gl {
-
-class ColorMode {
-public:
- enum class BlendEquation {
- Add = 0x8006,
- Subtract = 0x800A,
- ReverseSubtract = 0x800B
- };
-
- enum BlendFactor {
- Zero = 0x0000,
- One = 0x0001,
- SrcColor = 0x0300,
- OneMinusSrcColor = 0x0301,
- SrcAlpha = 0x0302,
- OneMinusSrcAlpha = 0x0303,
- DstAlpha = 0x0304,
- OneMinusDstAlpha = 0x0305,
- DstColor = 0x0306,
- OneMinusDstColor = 0x0307,
- SrcAlphaSaturate = 0x0308,
- ConstantColor = 0x8001,
- OneMinusConstantColor = 0x8002,
- ConstantAlpha = 0x8003,
- OneMinusConstantAlpha = 0x8004
- };
-
- template <BlendEquation E>
- struct ConstantBlend {
- static constexpr BlendEquation equation = E;
- static constexpr BlendFactor srcFactor = One;
- static constexpr BlendFactor dstFactor = One;
- };
-
- template <BlendEquation E>
- struct LinearBlend {
- static constexpr BlendEquation equation = E;
- BlendFactor srcFactor;
- BlendFactor dstFactor;
- };
-
- struct Replace {
- static constexpr BlendEquation equation = BlendEquation::Add;
- static constexpr BlendFactor srcFactor = One;
- static constexpr BlendFactor dstFactor = Zero;
- };
-
- using Add = LinearBlend<BlendEquation::Add>;
- using Subtract = LinearBlend<BlendEquation::Subtract>;
- using ReverseSubtract = LinearBlend<BlendEquation::ReverseSubtract>;
-
- using BlendFunction = variant<
- Replace,
- Add,
- Subtract,
- ReverseSubtract>;
-
- BlendFunction blendFunction;
- Color blendColor;
-
- struct Mask {
- bool r;
- bool g;
- bool b;
- bool a;
- };
-
- Mask mask;
-
- static ColorMode disabled() {
- return ColorMode { Replace(), {}, { false, false, false, false } };
- }
-
- static ColorMode unblended() {
- return ColorMode { Replace(), {}, { true, true, true, true } };
- }
-
- static ColorMode alphaBlended() {
- return ColorMode { Add { One, OneMinusSrcAlpha }, {}, { true, true, true, true } };
- }
-
- static ColorMode additive() {
- return ColorMode { Add { One, One }, {}, { true, true, true, true } };
- }
-};
-
-constexpr bool operator!=(const ColorMode::Mask& a, const ColorMode::Mask& b) {
- return a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a;
-}
-
-} // namespace gl
-} // namespace mbgl
diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp
index 64365a1018..ee82fa76ae 100644
--- a/src/mbgl/gl/context.cpp
+++ b/src/mbgl/gl/context.cpp
@@ -728,14 +728,14 @@ void Context::setStencilMode(const StencilMode& stencil) {
}
}
-void Context::setColorMode(const ColorMode& color) {
- if (color.blendFunction.is<ColorMode::Replace>()) {
+void Context::setColorMode(const gfx::ColorMode& color) {
+ if (color.blendFunction.is<gfx::ColorMode::Replace>()) {
blend = false;
} else {
blend = true;
blendColor = color.blendColor;
apply_visitor([&] (const auto& blendFunction) {
- blendEquation = ColorMode::BlendEquation(blendFunction.equation);
+ blendEquation = gfx::ColorMode::BlendEquation(blendFunction.equation);
blendFunc = { blendFunction.srcFactor, blendFunction.dstFactor };
}, color.blendFunction);
}
diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp
index b09c64de5a..ceab6aadf1 100644
--- a/src/mbgl/gl/context.hpp
+++ b/src/mbgl/gl/context.hpp
@@ -14,7 +14,7 @@
#include <mbgl/gfx/draw_mode.hpp>
#include <mbgl/gl/depth_mode.hpp>
#include <mbgl/gl/stencil_mode.hpp>
-#include <mbgl/gl/color_mode.hpp>
+#include <mbgl/gfx/color_mode.hpp>
#include <mbgl/platform/gl_functions.hpp>
#include <mbgl/util/noncopyable.hpp>
@@ -172,7 +172,7 @@ public:
void setDepthMode(const DepthMode&);
void setStencilMode(const StencilMode&);
- void setColorMode(const ColorMode&);
+ void setColorMode(const gfx::ColorMode&);
void setCullFaceMode(const CullFaceMode&);
void draw(gfx::PrimitiveType,
diff --git a/src/mbgl/gl/program.hpp b/src/mbgl/gl/program.hpp
index 3ef7955949..83dd9a86f6 100644
--- a/src/mbgl/gl/program.hpp
+++ b/src/mbgl/gl/program.hpp
@@ -117,7 +117,7 @@ public:
DrawMode drawMode,
DepthMode depthMode,
StencilMode stencilMode,
- ColorMode colorMode,
+ gfx::ColorMode colorMode,
CullFaceMode cullFaceMode,
const UniformValues& uniformValues,
VertexArray& vertexArray,
diff --git a/src/mbgl/gl/value.cpp b/src/mbgl/gl/value.cpp
index d685e533a5..b926f599ee 100644
--- a/src/mbgl/gl/value.cpp
+++ b/src/mbgl/gl/value.cpp
@@ -8,6 +8,9 @@ namespace value {
using namespace platform;
+template <class T>
+T fromGLenum(const GLint);
+
const constexpr ClearDepth::Type ClearDepth::Default;
void ClearDepth::Set(const Type& value) {
@@ -174,29 +177,91 @@ Blend::Type Blend::Get() {
const constexpr BlendEquation::Type BlendEquation::Default;
+GLenum toGLenum(const gfx::ColorMode::BlendEquation blendEquation) {
+ switch (blendEquation) {
+ case gfx::ColorMode::BlendEquation::Add: return GL_FUNC_ADD;
+ case gfx::ColorMode::BlendEquation::Subtract: return GL_FUNC_SUBTRACT;
+ case gfx::ColorMode::BlendEquation::ReverseSubtract: return GL_FUNC_REVERSE_SUBTRACT;
+ }
+ return GL_INVALID_ENUM;
+}
+
void BlendEquation::Set(const Type& value) {
- MBGL_CHECK_ERROR(glBlendEquation(static_cast<GLenum>(value)));
+ MBGL_CHECK_ERROR(glBlendEquation(toGLenum(value)));
+}
+
+template <>
+gfx::ColorMode::BlendEquation fromGLenum<gfx::ColorMode::BlendEquation>(const GLint blendEquation) {
+ switch (blendEquation) {
+ case GL_FUNC_ADD: return gfx::ColorMode::BlendEquation::Add;
+ case GL_FUNC_SUBTRACT: return gfx::ColorMode::BlendEquation::Subtract;
+ case GL_FUNC_REVERSE_SUBTRACT: return gfx::ColorMode::BlendEquation::ReverseSubtract;
+ }
+ return {};
}
BlendEquation::Type BlendEquation::Get() {
GLint blend;
MBGL_CHECK_ERROR(glGetIntegerv(GL_BLEND_EQUATION_RGB, &blend));
- return static_cast<Type>(blend);
+ return fromGLenum<gfx::ColorMode::BlendEquation>(blend);
}
const constexpr BlendFunc::Type BlendFunc::Default;
+GLenum toGLenum(const gfx::ColorMode::BlendFactor blendFactor) {
+ switch (blendFactor) {
+ case gfx::ColorMode::BlendFactor::Zero: return GL_ZERO;
+ case gfx::ColorMode::BlendFactor::One: return GL_ONE;
+ case gfx::ColorMode::BlendFactor::SrcColor: return GL_SRC_COLOR;
+ case gfx::ColorMode::BlendFactor::OneMinusSrcColor: return GL_ONE_MINUS_SRC_COLOR;
+ case gfx::ColorMode::BlendFactor::DstColor: return GL_DST_COLOR;
+ case gfx::ColorMode::BlendFactor::OneMinusDstColor: return GL_ONE_MINUS_DST_COLOR;
+ case gfx::ColorMode::BlendFactor::SrcAlpha: return GL_SRC_ALPHA;
+ case gfx::ColorMode::BlendFactor::OneMinusSrcAlpha: return GL_ONE_MINUS_SRC_ALPHA;
+ case gfx::ColorMode::BlendFactor::DstAlpha: return GL_DST_ALPHA;
+ case gfx::ColorMode::BlendFactor::OneMinusDstAlpha: return GL_ONE_MINUS_DST_ALPHA;
+ case gfx::ColorMode::BlendFactor::ConstantColor: return GL_CONSTANT_COLOR;
+ case gfx::ColorMode::BlendFactor::OneMinusConstantColor: return GL_ONE_MINUS_CONSTANT_COLOR;
+ case gfx::ColorMode::BlendFactor::ConstantAlpha: return GL_CONSTANT_ALPHA;
+ case gfx::ColorMode::BlendFactor::OneMinusConstantAlpha: return GL_ONE_MINUS_CONSTANT_ALPHA;
+ case gfx::ColorMode::BlendFactor::SrcAlphaSaturate: return GL_SRC_ALPHA_SATURATE;
+ }
+ return GL_INVALID_ENUM;
+}
+
void BlendFunc::Set(const Type& value) {
MBGL_CHECK_ERROR(
- glBlendFunc(static_cast<GLenum>(value.sfactor), static_cast<GLenum>(value.dfactor)));
+ glBlendFunc(toGLenum(value.sfactor), toGLenum(value.dfactor)));
+}
+
+template <>
+gfx::ColorMode::BlendFactor fromGLenum<gfx::ColorMode::BlendFactor>(const GLint blendFactor) {
+ switch (blendFactor) {
+ case GL_ZERO: return gfx::ColorMode::BlendFactor::Zero;
+ case GL_ONE: return gfx::ColorMode::BlendFactor::One;
+ case GL_SRC_COLOR: return gfx::ColorMode::BlendFactor::SrcColor;
+ case GL_ONE_MINUS_SRC_COLOR: return gfx::ColorMode::BlendFactor::OneMinusSrcColor;
+ case GL_DST_COLOR: return gfx::ColorMode::BlendFactor::DstColor;
+ case GL_ONE_MINUS_DST_COLOR: return gfx::ColorMode::BlendFactor::OneMinusDstColor;
+ case GL_SRC_ALPHA: return gfx::ColorMode::BlendFactor::SrcAlpha;
+ case GL_ONE_MINUS_SRC_ALPHA: return gfx::ColorMode::BlendFactor::OneMinusSrcAlpha;
+ case GL_DST_ALPHA: return gfx::ColorMode::BlendFactor::DstAlpha;
+ case GL_ONE_MINUS_DST_ALPHA: return gfx::ColorMode::BlendFactor::OneMinusDstAlpha;
+ case GL_CONSTANT_COLOR: return gfx::ColorMode::BlendFactor::ConstantColor;
+ case GL_ONE_MINUS_CONSTANT_COLOR: return gfx::ColorMode::BlendFactor::OneMinusConstantColor;
+ case GL_CONSTANT_ALPHA: return gfx::ColorMode::BlendFactor::ConstantAlpha;
+ case GL_ONE_MINUS_CONSTANT_ALPHA: return gfx::ColorMode::BlendFactor::OneMinusConstantAlpha;
+ case GL_SRC_ALPHA_SATURATE: return gfx::ColorMode::BlendFactor::SrcAlphaSaturate;
+ }
+ return {};
}
BlendFunc::Type BlendFunc::Get() {
GLint sfactor, dfactor;
MBGL_CHECK_ERROR(glGetIntegerv(GL_BLEND_SRC_ALPHA, &sfactor));
MBGL_CHECK_ERROR(glGetIntegerv(GL_BLEND_DST_ALPHA, &dfactor));
- return { static_cast<ColorMode::BlendFactor>(sfactor),
- static_cast<ColorMode::BlendFactor>(dfactor) };
+ return { fromGLenum<gfx::ColorMode::BlendFactor>(sfactor),
+ fromGLenum<gfx::ColorMode::BlendFactor>(dfactor) };
}
const BlendColor::Type BlendColor::Default { 0, 0, 0, 0 };
diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp
index 8e2c995e11..8bc5c624bf 100644
--- a/src/mbgl/gl/value.hpp
+++ b/src/mbgl/gl/value.hpp
@@ -3,7 +3,7 @@
#include <mbgl/gl/types.hpp>
#include <mbgl/gl/depth_mode.hpp>
#include <mbgl/gl/stencil_mode.hpp>
-#include <mbgl/gl/color_mode.hpp>
+#include <mbgl/gfx/color_mode.hpp>
#include <mbgl/gl/cull_face_mode.hpp>
#include <mbgl/gl/attribute.hpp>
#include <mbgl/platform/gl_functions.hpp>
@@ -54,7 +54,7 @@ struct DepthMask {
};
struct ColorMask {
- using Type = ColorMode::Mask;
+ using Type = gfx::ColorMode::Mask;
static const constexpr Type Default = { true, true, true, true };
static void Set(const Type&);
static Type Get();
@@ -126,18 +126,18 @@ struct Blend {
};
struct BlendEquation {
- using Type = ColorMode::BlendEquation;
- static const constexpr Type Default = ColorMode::BlendEquation::Add;
+ using Type = gfx::ColorMode::BlendEquation;
+ static const constexpr Type Default = gfx::ColorMode::BlendEquation::Add;
static void Set(const Type&);
static Type Get();
};
struct BlendFunc {
struct Type {
- ColorMode::BlendFactor sfactor;
- ColorMode::BlendFactor dfactor;
+ gfx::ColorMode::BlendFactor sfactor;
+ gfx::ColorMode::BlendFactor dfactor;
};
- static const constexpr Type Default = { ColorMode::One, ColorMode::Zero };
+ static const constexpr Type Default = { gfx::ColorMode::BlendFactor::One, gfx::ColorMode::BlendFactor::Zero };
static void Set(const Type&);
static Type Get();
};