summaryrefslogtreecommitdiffhomepage
path: root/tile-shader.cpp
blob: 12bf7fde3a8983604e3a571886a02abd326cc203 (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
#include "tile-shader.hpp"
#include "loader.hpp"

#include <Corrade/Containers/Reference.h>
#include <Corrade/Utility/Resource.h>
#include <Magnum/GL/Context.h>
#include <Magnum/GL/Shader.h>
#include <Magnum/GL/Version.h>

namespace Magnum::Examples {

tile_shader::tile_shader()
{
    MAGNUM_ASSERT_GL_VERSION_SUPPORTED(GL::Version::GL460);

    GL::Shader vert{GL::Version::GL460, GL::Shader::Type::Vertex};
    GL::Shader frag{GL::Version::GL460, GL::Shader::Type::Fragment};

    vert.addSource(loader.shader("shaders/tile-shader.vert"));
    frag.addSource(loader.shader("shaders/tile-shader.frag"));

    CORRADE_INTERNAL_ASSERT_OUTPUT(GL::Shader::compile({vert, frag}));

    attachShaders({vert, frag});

    CORRADE_INTERNAL_ASSERT_OUTPUT(link());

    _color_uniform = uniformLocation("color");
    _projection_uniform = uniformLocation("projection");
    _y_scale_uniform = uniformLocation("y_scale");

    setUniform(uniformLocation("textureData"), TextureUnit);
}

tile_shader& tile_shader::bindTexture(GL::Texture2D& texture)
{
    texture.bind(TextureUnit);
    return *this;
}

tile_shader& tile_shader::set_projection(const Matrix4& mat, float y_scale)
{
    setUniform(_projection_uniform, mat);
    setUniform(_y_scale_uniform, y_scale);
    return *this;
}

} // namespace Magnum::Examples