summaryrefslogtreecommitdiff
path: root/src/mbgl/gfx/color_mode.hpp
blob: 077c7771bd38d50a967c7d79d8a1baa052214e1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once

#include <mbgl/gfx/types.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/color.hpp>

namespace mbgl {
namespace gfx {

class ColorMode {
public:
    template <ColorBlendEquationType E>
    struct ConstantBlend {
        static constexpr ColorBlendEquationType equation = E;
        static constexpr ColorBlendFactorType srcFactor = ColorBlendFactorType::One;
        static constexpr ColorBlendFactorType dstFactor = ColorBlendFactorType::One;
    };

    template <ColorBlendEquationType E>
    struct LinearBlend {
        static constexpr ColorBlendEquationType equation = E;
        ColorBlendFactorType srcFactor;
        ColorBlendFactorType dstFactor;
    };

    struct Replace {
        static constexpr ColorBlendEquationType equation = ColorBlendEquationType::Add;
        static constexpr ColorBlendFactorType srcFactor = ColorBlendFactorType::One;
        static constexpr ColorBlendFactorType dstFactor = ColorBlendFactorType::Zero;
    };

    using Add              = LinearBlend<ColorBlendEquationType::Add>;
    using Subtract         = LinearBlend<ColorBlendEquationType::Subtract>;
    using ReverseSubtract  = LinearBlend<ColorBlendEquationType::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{ ColorBlendFactorType::One, ColorBlendFactorType::OneMinusSrcAlpha }, {}, { true, true, true, true } };
    }

    static ColorMode additive() {
        return { Add{ ColorBlendFactorType::One, ColorBlendFactorType::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