Tatooine
shaders.h
Go to the documentation of this file.
1#ifndef TATOOINE_RENDERING_INTERACTIVE_SHADERS_H
2#define TATOOINE_RENDERING_INTERACTIVE_SHADERS_H
3//==============================================================================
5//==============================================================================
7//==============================================================================
9 //------------------------------------------------------------------------------
10 static constexpr std::string_view vertex_shader =
11 "#version 330 core\n"
12 "layout (location = 0) in vec2 position;\n"
13 "void main() {\n"
14 " gl_Position = vec4(position, 0, 1);\n"
15 "}\n";
16 //------------------------------------------------------------------------------
17 static constexpr std::string_view fragment_shader =
18 "#version 330 core\n"
19 "uniform vec4 color;\n"
20 "out vec4 out_color;\n"
21 "void main() {\n"
22 " out_color = color;\n"
23 "}\n";
24 //------------------------------------------------------------------------------
25 static auto get() -> auto& {
27 return s;
28 }
29 //------------------------------------------------------------------------------
30 private:
31 //------------------------------------------------------------------------------
33 add_stage<gl::vertexshader>(gl::shadersource{vertex_shader});
34 add_stage<gl::fragmentshader>(gl::shadersource{fragment_shader});
35 create();
36 set_color(0, 0, 0);
37 }
38 //------------------------------------------------------------------------------
39 public:
40 //------------------------------------------------------------------------------
41 auto set_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a = 1) -> void {
42 set_uniform("color", r, g, b, a);
43 }
44};
45//==============================================================================
47 //------------------------------------------------------------------------------
48 static constexpr std::string_view vertex_shader =
49 "#version 330 core\n"
50 "uniform mat4 projection_matrix;\n"
51 "uniform mat4 model_view_matrix;\n"
52 "layout (location = 0) in vec2 position;\n"
53 "void main() {\n"
54 " gl_Position = projection_matrix * \n"
55 " model_view_matrix * \n"
56 " vec4(position, 0, 1);\n"
57 "}\n";
58 //------------------------------------------------------------------------------
59 static constexpr std::string_view fragment_shader =
60 "#version 330 core\n"
61 "uniform vec4 color;\n"
62 "out vec4 out_color;\n"
63 "void main() {\n"
64 " out_color = color;\n"
65 "}\n";
66 //------------------------------------------------------------------------------
67 static auto get() -> auto& {
68 static auto s = colored_pass_through_2d{};
69 return s;
70 }
71 //------------------------------------------------------------------------------
72 private:
73 //------------------------------------------------------------------------------
75 add_stage<gl::vertexshader>(gl::shadersource{vertex_shader});
76 add_stage<gl::fragmentshader>(gl::shadersource{fragment_shader});
77 create();
78 set_color(0, 0, 0);
81 }
82 //------------------------------------------------------------------------------
83 public:
84 //------------------------------------------------------------------------------
85 auto set_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a = 1) -> void {
86 set_uniform("color", r, g, b, a);
87 }
88 //------------------------------------------------------------------------------
89 auto set_model_view_matrix(Mat4<GLfloat> const& MV) -> void {
90 set_uniform_mat4("model_view_matrix", MV.data());
91 }
92 //------------------------------------------------------------------------------
93 auto set_projection_matrix(Mat4<GLfloat> const& P) -> void {
94 set_uniform_mat4("projection_matrix", P.data());
95 }
96};
97//==============================================================================
98} // namespace tatooine::rendering::interactive::shaders
99//==============================================================================
100#endif
Definition: shader.h:24
DLL_API void set_uniform(const std::string &, GLfloat)
DLL_API void create()
DLL_API void set_uniform_mat4(const std::string &, GLfloat const *)
Definition: shadersource.h:8
Definition: mat.h:14
static constexpr std::string_view fragment_shader
Definition: shaders.h:17
static constexpr std::string_view vertex_shader
Definition: shaders.h:10
auto set_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a=1) -> void
Definition: shaders.h:41
static auto get() -> auto &
Definition: shaders.h:67
auto set_model_view_matrix(Mat4< GLfloat > const &MV) -> void
Definition: shaders.h:89
static constexpr std::string_view fragment_shader
Definition: shaders.h:59
static constexpr std::string_view vertex_shader
Definition: shaders.h:48
auto set_projection_matrix(Mat4< GLfloat > const &P) -> void
Definition: shaders.h:93
auto set_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a=1) -> void
Definition: shaders.h:85