diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2019-02-28 16:19:33 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2019-03-01 09:33:37 +0100 |
commit | da6e1390c68e01e02652104586c759d46e04c7fd (patch) | |
tree | 002942c69e886a2ad86ac7bea8272d36a16c28e2 /src/mbgl/gfx | |
parent | fd37d9065029c732d97e6fa59bc0a0d27ecd3c72 (diff) | |
download | qtlocation-mapboxgl-da6e1390c68e01e02652104586c759d46e04c7fd.tar.gz |
[core] move ColorMode to gfx namespace
Diffstat (limited to 'src/mbgl/gfx')
-rw-r--r-- | src/mbgl/gfx/color_mode.hpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/mbgl/gfx/color_mode.hpp b/src/mbgl/gfx/color_mode.hpp new file mode 100644 index 0000000000..97bbc24096 --- /dev/null +++ b/src/mbgl/gfx/color_mode.hpp @@ -0,0 +1,99 @@ +#pragma once + +#include <mbgl/util/variant.hpp> +#include <mbgl/util/color.hpp> + +namespace mbgl { +namespace gfx { + +class ColorMode { +public: + enum class BlendEquation { + Add, + Subtract, + ReverseSubtract + }; + + enum class BlendFactor { + Zero, + One, + SrcColor, + OneMinusSrcColor, + SrcAlpha, + OneMinusSrcAlpha, + DstAlpha, + OneMinusDstAlpha, + DstColor, + OneMinusDstColor, + SrcAlphaSaturate, + ConstantColor, + OneMinusConstantColor, + ConstantAlpha, + OneMinusConstantAlpha + }; + + template <BlendEquation E> + struct ConstantBlend { + static constexpr BlendEquation equation = E; + static constexpr BlendFactor srcFactor = BlendFactor::One; + static constexpr BlendFactor dstFactor = BlendFactor::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 = BlendFactor::One; + static constexpr BlendFactor dstFactor = BlendFactor::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 { Replace{}, {}, { false, false, false, false } }; + } + + static ColorMode unblended() { + return { Replace{}, {}, { true, true, true, true } }; + } + + static ColorMode alphaBlended() { + return { Add{ BlendFactor::One, BlendFactor::OneMinusSrcAlpha }, {}, { true, true, true, true } }; + } + + static ColorMode additive() { + return { Add{ BlendFactor::One, BlendFactor::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 gfx +} // namespace mbgl |