summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/texture.hpp
blob: 8230be165208ba1bdd8edf84e42a0fee483de143 (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
#pragma once

#include <mbgl/gfx/texture.hpp>
#include <mbgl/gl/uniform.hpp>
#include <mbgl/util/ignore.hpp>

#include <vector>
#include <string>

namespace mbgl {
namespace gl {

class Context;

void bindTexture(gl::Context&, uint8_t unit, const gfx::TextureBinding&);

template <class>
class Textures;

template <class... Ts>
class Textures<TypeList<Ts...>> {
    using State =
        IndexedTuple<TypeList<Ts...>, TypeList<ExpandToType<Ts, gl::UniformState<uint8_t>>...>>;
    using NamedLocations = std::vector<std::pair<const std::string, gl::UniformLocation>>;

public:
    void queryLocations(const ProgramID& id) {
        state = State{ gl::uniformLocation(id, Ts::name())... };
    }

    template <class BinaryProgram>
    void loadNamedLocations(const BinaryProgram& program) {
        state = State{ program.textureLocation(Ts::name())... };
    }

    NamedLocations getNamedLocations() const {
        return NamedLocations{ { Ts::name(), state.template get<Ts>().location }... };
    }

    void bind(gl::Context& context, const gfx::TextureBindings<TypeList<Ts...>>& bindings) {
        util::ignore(
            { (state.template get<Ts>() = TypeIndex<Ts, Ts...>::value,
               gl::bindTexture(context, TypeIndex<Ts, Ts...>::value, bindings.template get<Ts>()),
               0)... });
    }

private:
    State state;
};

} // namespace gl
} // namespace mbgl