summaryrefslogtreecommitdiff
path: root/src/mbgl/gl/uniform.cpp
blob: 07a27963d979b145b9313e15612847e710e8f04c (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
#include <mbgl/gl/uniform.hpp>
#include <mbgl/gl/gl.hpp>
#include <mbgl/util/color.hpp>

namespace mbgl {
namespace gl {

template <>
void Uniform<float>::bind(const float& t) {
    MBGL_CHECK_ERROR(glUniform1f(location, t));
}

template <>
void Uniform<int32_t>::bind(const int32_t& t) {
    MBGL_CHECK_ERROR(glUniform1i(location, t));
}

template <>
void Uniform<std::array<float, 2>>::bind(const std::array<float, 2>& t) {
    MBGL_CHECK_ERROR(glUniform2fv(location, 1, t.data()));
}

template <>
void Uniform<std::array<float, 3>>::bind(const std::array<float, 3>& t) {
    MBGL_CHECK_ERROR(glUniform3fv(location, 1, t.data()));
}

template <>
void Uniform<std::array<float, 4>>::bind(const std::array<float, 4>& t) {
    MBGL_CHECK_ERROR(glUniform4fv(location, 1, t.data()));
}

template <>
void Uniform<Color>::bind(const Color& t) {
    std::array<float, 4> a = {{ t.r, t.g, t.b, t.a }};
    MBGL_CHECK_ERROR(glUniform4fv(location, 1, a.data()));
}

template <>
void UniformMatrix<2>::bind(const std::array<float, 4>& t) {
    MBGL_CHECK_ERROR(glUniformMatrix2fv(location, 1, GL_FALSE, t.data()));
}

template <>
void UniformMatrix<3>::bind(const std::array<float, 9>& t) {
    MBGL_CHECK_ERROR(glUniformMatrix3fv(location, 1, GL_FALSE, t.data()));
}

template <>
void UniformMatrix<4>::bind(const std::array<float, 16>& t) {
    MBGL_CHECK_ERROR(glUniformMatrix4fv(location, 1, GL_FALSE, t.data()));
}

// Add more as needed.

} // namespace gl
} // namespace mbgl