summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/gl_config.hpp
blob: 41bee8fab706ec1ddfdd51ef83d5d2beaeae7337 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once

#include <cstdint>
#include <tuple>
#include <array>

#include <mbgl/gl/gl_values.hpp>

namespace mbgl {
namespace gl {

template <typename T>
class Value {
public:
    void operator=(const typename T::Type& value) {
        if (*this != value) {
            dirty = false;
            current = value;
            T::Set(current);
        }
    }

    bool operator!=(const typename T::Type& value) const {
        return dirty || current != value;
    }

    void reset() {
        *this = T::Default;
    }

    void setDirty() {
        dirty = true;
    }

    typename T::Type getCurrent() const {
        return current;
    }

    bool getDirty() const {
        return dirty;
    }

private:
    typename T::Type current = T::Default;
    bool dirty = false;
};

class Config {
public:
    void reset() {
        stencilFunc.reset();
        stencilMask.reset();
        stencilTest.reset();
        stencilOp.reset();
        depthRange.reset();
        depthMask.reset();
        depthTest.reset();
        depthFunc.reset();
        blend.reset();
        blendFunc.reset();
        blendColor.reset();
        colorMask.reset();
        clearDepth.reset();
        clearColor.reset();
        clearStencil.reset();
        program.reset();
        lineWidth.reset();
        activeTexture.reset();
#ifndef GL_ES_VERSION_2_0
        pixelZoom.reset();
        rasterPos.reset();
#endif // GL_ES_VERSION_2_0
    }

    void setDirty() {
        stencilFunc.setDirty();
        stencilMask.setDirty();
        stencilTest.setDirty();
        stencilOp.setDirty();
        depthRange.setDirty();
        depthMask.setDirty();
        depthTest.setDirty();
        depthFunc.setDirty();
        blend.setDirty();
        blendFunc.setDirty();
        blendColor.setDirty();
        colorMask.setDirty();
        clearDepth.setDirty();
        clearColor.setDirty();
        clearStencil.setDirty();
        program.setDirty();
        lineWidth.setDirty();
        activeTexture.setDirty();
#ifndef GL_ES_VERSION_2_0
        pixelZoom.setDirty();
        rasterPos.setDirty();
#endif // GL_ES_VERSION_2_0
    }

    Value<StencilFunc> stencilFunc;
    Value<StencilMask> stencilMask;
    Value<StencilTest> stencilTest;
    Value<StencilOp> stencilOp;
    Value<DepthRange> depthRange;
    Value<DepthMask> depthMask;
    Value<DepthTest> depthTest;
    Value<DepthFunc> depthFunc;
    Value<Blend> blend;
    Value<BlendFunc> blendFunc;
    Value<BlendColor> blendColor;
    Value<ColorMask> colorMask;
    Value<ClearDepth> clearDepth;
    Value<ClearColor> clearColor;
    Value<ClearStencil> clearStencil;
    Value<Program> program;
    Value<LineWidth> lineWidth;
    Value<ActiveTexture> activeTexture;
#ifndef GL_ES_VERSION_2_0
    Value<PixelZoom> pixelZoom;
    Value<RasterPos> rasterPos;
#endif // GL_ES_VERSION_2_0
    std::array<Value<BindTexture>, 2> texture;
};

} // namespace gl
} // namespace mbgl