GCC Code Coverage Report


./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
0 of 58, 0 excluded
0.0%
Functions:
0 of 9, 0 excluded
0.0%
Branches:
0 of 150, 0 excluded
0.0%

libs/render/src/eu/render/shader.source.cc
Line Branch Exec Source
1 #include "eu/log/log.h"
2
3
4 #include "eu/render/shader.source.h"
5
6 #include "mustache.hpp"
7
8 // #include "default_shader.frag.glsl.h"
9 // #include "default_shader.vert.glsl.h"
10 // #include "skybox.frag.glsl.h"
11 // #include "skybox.vert.glsl.h"
12
13 namespace eu::render
14 {
15
16
17 using Properties = std::unordered_map<std::string, std::string>;
18
19 ShaderOptions ShaderOptions::with_transparent_cutoff() const
20 {
21 auto ret = *this;
22 ret.transparent_cutoff = true;
23 return ret;
24 }
25
26 ShaderOptions ShaderOptions::with_instanced_mat4() const
27 {
28 auto ret = *this;
29 ret.use_instancing = true;
30 return ret;
31 }
32
33 kainjow::mustache::mustache load_mustache(std::string_view str)
34 {
35 auto input = kainjow::mustache::mustache{std::string{str.begin(), str.end()}};
36 if (input.is_valid() == false)
37 {
38 const auto& error = input.error_message();
39 LOG_ERR("Failed to parse mustache: {}", error);
40 }
41
42 input.set_custom_escape([](const std::string& s) { return s; });
43 return input;
44 }
45
46 std::string generate_blur(std::string_view src, const BlurOptions& options)
47 {
48 auto input = load_mustache(src);
49 auto data = kainjow::mustache::data{};
50
51 data["is_horizontal"] = options.blur == BlurType::horizontal;
52 data["is_vertical"] = options.blur == BlurType::vertical;
53 data["sample_count"] = fmt::format("{}", options.sample_count);
54 data["is_gauss"] = options.is_gauss == IsGauss::yes;
55
56 return input.render(data);
57 }
58
59 std::string generate(std::string_view str, const ShaderOptions& options, const std::string& uniform_buffer_source)
60 {
61 auto input = load_mustache(str);
62 auto data = kainjow::mustache::data{};
63
64 data["use_lights"] = options.use_lights;
65 data["use_blinn_phong"] = options.use_blinn_phong;
66 data["use_texture"] = options.use_texture;
67 data["number_of_directional_lights"] = fmt::format("{}", options.number_of_directional_lights);
68 data["number_of_point_lights"] = fmt::format("{}", options.number_of_point_lights);
69 data["number_of_frustum_lights"] = fmt::format("{}", options.number_of_frustum_lights);
70 data["transparent_cutoff"] = options.transparent_cutoff;
71 data["use_instancing"] = options.use_instancing;
72 data["uniform_buffer_source"] = uniform_buffer_source;
73 data["only_depth"] = options.only_depth;
74
75 return input.render(data);
76 }
77
78 std::string generate(std::string_view str, const std::string& uniform_buffer_source)
79 {
80 auto input = load_mustache(str);
81 auto data = kainjow::mustache::data{};
82
83 data["uniform_buffer_source"] = uniform_buffer_source;
84
85 return input.render(data);
86 }
87
88 ShaderSource_withLayout load_shader_source(const ShaderSource& source, const ShaderOptions& options, const std::string& uniform_buffer_source)
89 {
90 auto layout = core::ShaderVertexAttributes{{core::VertexType::position3, "a_position"}, {core::VertexType::color3, "a_color"}};
91
92 if (options.use_texture)
93 {
94 layout.emplace_back(core::VertexElementDescription{core::VertexType::texture2, "a_tex_coord"});
95 }
96
97 if (options.use_lights)
98 {
99 layout.emplace_back(core::VertexElementDescription{core::VertexType::normal3, "a_normal"});
100 }
101
102 return ShaderSource_withLayout{
103 layout,
104 generate(source.vertex, options, uniform_buffer_source),
105 generate(source.fragment, options, uniform_buffer_source)
106 };
107 }
108
109 ShaderSource load_skybox_source(const ShaderSource& source, const std::string& uniform_buffer_source)
110 {
111 return ShaderSource{
112 generate(source.vertex, uniform_buffer_source), generate(source.fragment, uniform_buffer_source)
113 };
114 }
115
116 } // namespace eu::render
117