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

#include <mbgl/gfx/texture.hpp>
#include <mbgl/gl/uniform.hpp>
#include <mbgl/util/literal.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 TextureStates;

template <class... Ts>
class TextureStates<TypeList<Ts...>> {
private:
    using State =
        IndexedTuple<TypeList<Ts...>, TypeList<ExpandToType<Ts, gl::UniformState<uint8_t>>...>>;

    State state;

public:
    void queryLocations(const ProgramID& id) {
        state = State{ gl::uniformLocation(id,
            concat_literals<&string_literal<'u', '_'>::value, &Ts::name>::value())... };
    }

    template <class BinaryProgram>
    void loadNamedLocations(const BinaryProgram& program) {
        state = State{ program.textureLocation(
            concat_literals<&string_literal<'u', '_'>::value, &Ts::name>::value())... };
    }

    NamedUniformLocations getNamedLocations() const {
        return NamedUniformLocations{ { concat_literals<&string_literal<'u', '_'>::value, &Ts::name>::value(),
                                        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)... });
    }
};

} // namespace gl
} // namespace mbgl