summaryrefslogtreecommitdiff
path: root/chisel/backends/opengl/gfx.cpp
blob: be254138e822deb2b3bb774dcc7aa197a46aa7c5 (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
#include "gfx.h"

const std::string standard_vs =
    "#version 330\n"
    "in vec2 pos;\n"
    "void main() {\n"
        "gl_Position = vec4(pos, 0.0, 1.0);\n"
    "}\n";
const std::string standard_fs =
    "#version 330\n"
    "out vec4 color;\n"
    "void main() {\n"
        "color = vec4(1.0, 1.0, 1.0, 1.0);\n"
    "}\n";

namespace gfx {
    Shaders shaders;

    Program* Shaders::standard() {
        if (_standard)
            return _standard;
        
        _standard = new Program();
        {
            auto vs = Shader(standard_vs, VERTEX_SHADER);
            auto fs = Shader(standard_fs, FRAGMENT_SHADER);

            _standard->attach(vs);
            _standard->attach(fs);
            _standard->link();
        }

        return _standard;
    }



    namespace state {
        GLuint current_program_id = 0;
        float width = 0.0;
        float height = 0.0;
    }

    void viewport(int w, int h) {
        state::width = (float)w;
        state::height = (float)h;
        glViewport(0, 0, w, h);
    }

    void draw(Drawable& object) {
        object.draw();
    }
}