summaryrefslogtreecommitdiff
path: root/include/mbgl/gfx/backend.hpp
blob: eed63dfcbacb58294af267fb7dca63dad0662223 (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
#pragma once

#include <cstdint>
#include <cstdlib>
#include <memory>

namespace mbgl {
namespace gfx {

class Backend {
public:
    enum class Type : uint8_t {
        OpenGL,
    };

    static constexpr Type DefaultType = Type::OpenGL;

    static void SetType(const Type value) {
        if (Value(value) != value) {
            abort(); // SetType must be called prior to any GetType calls.
        }
    }

    static Type GetType() {
        return Value(DefaultType);
    }

    template <typename T, typename... Args>
    static std::unique_ptr<T> Create(Args... args) {
        return Create<Type::OpenGL, T, Args...>(std::forward<Args>(args)...);
    }

private:
    template <Type, typename T, typename... Args>
    static std::unique_ptr<T> Create(Args...);

    static Type Value(Type value) {
        static const Type type = value;
        return type;
    }
};

} // namespace gfx
} // namespace mbgl