summaryrefslogtreecommitdiff
path: root/src/mbgl/gfx/texture.hpp
blob: 758bdd1b0933db843c44a92db3ba6df22c85b465 (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
#pragma once

#include <mbgl/gfx/types.hpp>
#include <mbgl/util/size.hpp>
#include <mbgl/util/type_list.hpp>
#include <mbgl/util/indexed_tuple.hpp>

#include <memory>

#define MBGL_DEFINE_TEXTURE(name_)                                                                 \
    struct name_ {                                                                                 \
        using Value = ::mbgl::gfx::TextureBinding;                                                 \
        static constexpr auto name() {                                                             \
            return #name_;                                                                         \
        }                                                                                          \
    }

namespace mbgl {
namespace gfx {

class TextureResource {
protected:
    TextureResource() = default;
public:
    virtual ~TextureResource() = default;
};

class Texture {
public:
    Texture(Size size_, std::unique_ptr<TextureResource>&& resource_)
        : size(std::move(size_)), resource(std::move(resource_)) {
    }

    Size size;
    std::unique_ptr<TextureResource> resource;
};

class TextureBinding {
public:
    TextureBinding(TextureResource& resource_,
                   TextureFilterType filter_ = TextureFilterType::Nearest,
                   TextureMipMapType mipmap_ = TextureMipMapType::No,
                   TextureWrapType wrapX_ = TextureWrapType::Clamp,
                   TextureWrapType wrapY_ = TextureWrapType::Clamp)
        : resource(&resource_), filter(filter_), mipmap(mipmap_), wrapX(wrapX_), wrapY(wrapY_) {
    }

    TextureResource* resource;
    TextureFilterType filter;
    TextureMipMapType mipmap;
    TextureWrapType wrapX;
    TextureWrapType wrapY;
};

namespace detail {

template <class>
class TextureBindings;

template <class... Ts>
class TextureBindings<TypeList<Ts...>> {
public:
    using Type = IndexedTuple<TypeList<Ts...>, TypeList<ExpandToType<Ts, TextureBinding>...>>;
};

} // namespace detail

template <class TextureTypeList>
using TextureBindings = typename detail::TextureBindings<TextureTypeList>::Type;

} // namespace gfx
} // namespace mbgl