1 #pragma once
2
3 #include <mbgl/util/variant.hpp>
4 #include <mbgl/util/color.hpp>
5
6 namespace mbgl {
7 namespace gl {
8
9 class ColorMode {
10 public:
11 enum class BlendEquation {
12 Add = 0x8006,
13 Subtract = 0x800A,
14 ReverseSubtract = 0x800B
15 };
16
17 enum BlendFactor {
18 Zero = 0x0000,
19 One = 0x0001,
20 SrcColor = 0x0300,
21 OneMinusSrcColor = 0x0301,
22 SrcAlpha = 0x0302,
23 OneMinusSrcAlpha = 0x0303,
24 DstAlpha = 0x0304,
25 OneMinusDstAlpha = 0x0305,
26 DstColor = 0x0306,
27 OneMinusDstColor = 0x0307,
28 SrcAlphaSaturate = 0x0308,
29 ConstantColor = 0x8001,
30 OneMinusConstantColor = 0x8002,
31 ConstantAlpha = 0x8003,
32 OneMinusConstantAlpha = 0x8004
33 };
34
35 template <BlendEquation E>
36 struct ConstantBlend {
37 static constexpr BlendEquation equation = E;
38 static constexpr BlendFactor srcFactor = One;
39 static constexpr BlendFactor dstFactor = One;
40 };
41
42 template <BlendEquation E>
43 struct LinearBlend {
44 static constexpr BlendEquation equation = E;
45 BlendFactor srcFactor;
46 BlendFactor dstFactor;
47 };
48
49 struct Replace {
50 static constexpr BlendEquation equation = BlendEquation::Add;
51 static constexpr BlendFactor srcFactor = One;
52 static constexpr BlendFactor dstFactor = Zero;
53 };
54
55 using Add = LinearBlend<BlendEquation::Add>;
56 using Subtract = LinearBlend<BlendEquation::Subtract>;
57 using ReverseSubtract = LinearBlend<BlendEquation::ReverseSubtract>;
58
59 using BlendFunction = variant<
60 Replace,
61 Add,
62 Subtract,
63 ReverseSubtract>;
64
65 BlendFunction blendFunction;
66 Color blendColor;
67
68 struct Mask {
69 bool r;
70 bool g;
71 bool b;
72 bool a;
73 };
74
75 Mask mask;
76
disabled()77 static ColorMode disabled() {
78 return ColorMode { Replace(), {}, { false, false, false, false } };
79 }
80
unblended()81 static ColorMode unblended() {
82 return ColorMode { Replace(), {}, { true, true, true, true } };
83 }
84
alphaBlended()85 static ColorMode alphaBlended() {
86 return ColorMode { Add { One, OneMinusSrcAlpha }, {}, { true, true, true, true } };
87 }
88
additive()89 static ColorMode additive() {
90 return ColorMode { Add { One, One }, {}, { true, true, true, true } };
91 }
92 };
93
operator !=(const ColorMode::Mask & a,const ColorMode::Mask & b)94 constexpr bool operator!=(const ColorMode::Mask& a, const ColorMode::Mask& b) {
95 return a.r != b.r || a.g != b.g || a.b != b.b || a.a != b.a;
96 }
97
98 } // namespace gl
99 } // namespace mbgl
100