summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/gl_config.hpp
blob: 225f4f8de65afd412ef73227c95af8447188658f (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#pragma once

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

#include <mbgl/gl/gl_values.hpp>

namespace mbgl {
namespace gl {


template <typename T, typename = void>
struct DefaultValue {
    static typename T::Type Get() {
        return T::Get();
    }
};
template <typename T>
struct DefaultValue<T, decltype((void)T::Default, void())> {
    static typename T::Type Get() {
        return T::Default;
    }
};

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 = defaultValue;
    }

    void setDirty() {
        dirty = true;
    }

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

    bool getDirty() const {
        return dirty;
    }

    void setDefaultValue(const typename T::Type& value) {
        defaultValue = value;
    }

private:
    typename T::Type defaultValue = DefaultValue<T>::Get();
    typename T::Type current = defaultValue;
    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();
        bindFramebuffer.reset();
        viewport.reset();
#ifndef GL_ES_VERSION_2_0
        pixelZoom.reset();
        rasterPos.reset();
#endif // GL_ES_VERSION_2_0
        vertexBuffer.reset();
        elementBuffer.reset();
        vertexArrayObject.reset();
    }

    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();
        bindFramebuffer.setDirty();
        viewport.setDirty();
#ifndef GL_ES_VERSION_2_0
        pixelZoom.setDirty();
        rasterPos.setDirty();
#endif // GL_ES_VERSION_2_0
        vertexBuffer.setDirty();
        elementBuffer.setDirty();
        vertexArrayObject.setDirty();
    }

    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;
    Value<BindFramebuffer> bindFramebuffer;
    Value<Viewport> viewport;
#ifndef GL_ES_VERSION_2_0
    Value<PixelZoom> pixelZoom;
    Value<RasterPos> rasterPos;
#endif // GL_ES_VERSION_2_0
    std::array<Value<BindTexture>, 2> texture;
    Value<BindBuffer<GL_ARRAY_BUFFER>> vertexBuffer;
    Value<BindBuffer<GL_ELEMENT_ARRAY_BUFFER>> elementBuffer;
    Value<BindVAO> vertexArrayObject;
};

} // namespace gl
} // namespace mbgl