summaryrefslogtreecommitdiff
path: root/src/mbgl/programs/program.hpp
blob: fa41d43e5cc84e526ffbf3be0daa98fbfa97db52 (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
#pragma once

#include <mbgl/gl/program.hpp>

#include <cassert>

namespace mbgl {

enum class ProgramDefines : bool {
    None = false,
    Overdraw = true,
};

template <class Shaders, class Primitive, class Attributes, class Uniforms>
class Program : public gl::Program<Primitive, Attributes, Uniforms> {
public:
    using ParentType = gl::Program<Primitive, Attributes, Uniforms>;

    Program(gl::Context& context, ProgramDefines defines)
        : ParentType(context, Shaders::vertexSource, fragmentSource(defines))
        {}

    static std::string fragmentSource(ProgramDefines defines) {
        std::string fragment = Shaders::fragmentSource;
        if (defines == ProgramDefines::Overdraw) {
            assert(fragment.find("#ifdef OVERDRAW_INSPECTOR") != std::string::npos);
            fragment.replace(fragment.find_first_of('\n'), 1, "\n#define OVERDRAW_INSPECTOR\n");
        }
        return fragment;
    }
};

} // namespace mbgl