GCC Code Coverage Report


./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
0 of 3, 0 excluded
0.0%
Functions:
0 of 2, 0 excluded
0.0%
Branches:
0 of 0, 0 excluded
-%

libs/render/src/eu/render/material.h
Line Branch Exec Source
1 #pragma once
2
3 // #include "eu/render/color.h"
4 #include "eu/render/texture.h"
5 #include "eu/render/assets.h"
6
7 #include <memory>
8 #include <optional>
9
10 namespace eu::render
11 {
12 struct CompiledCamera;
13 struct LoadedShader_Default_Container;
14 struct LoadedShader_Unlit_Container;
15 struct RenderSettings;
16 struct Lights;
17 struct State;
18
19 /** \addtogroup render Renderer
20 * @{
21 */
22
23 /// All loaded/known shaders
24 struct ShaderResource;
25 struct RenderContext;
26
27 /// Base class for all materials
28 struct Material
29 {
30 Material() = default;
31 virtual ~Material() = default;
32
33 Material(const Material&) = delete;
34 Material(Material&&) = delete;
35 void operator=(const Material&) = delete;
36 void operator=(Material&&) = delete;
37
38 virtual void use_shader(const RenderContext&) = 0;
39 virtual void set_uniforms(const RenderContext&, const CompiledCamera&, const std::optional<m4>&) = 0;
40 virtual void bind_textures(const RenderContext&, State* states, Assets* assets) = 0;
41 virtual void apply_lights(
42 const RenderContext&, const Lights& lights, const RenderSettings& settings, State* states, Assets* assets
43 ) = 0;
44
45 [[nodiscard]] virtual bool is_transparent() const = 0;
46 };
47
48 /// A unlit (or fully lit) material, not affected by light.
49 struct UnlitMaterial : Material
50 {
51 const LoadedShader_Unlit_Container* shader_container;
52 Rgb color = colors::white;
53 float alpha = 1.0f;
54 std::shared_ptr<Texture2d> texture;
55
56 explicit UnlitMaterial(const ShaderResource& resource);
57 void use_shader(const RenderContext&) override;
58 void set_uniforms(const RenderContext&, const CompiledCamera&, const std::optional<m4>&) override;
59 void bind_textures(const RenderContext&, State* states, Assets* assets) override;
60 void apply_lights(
61 const RenderContext&, const Lights& lights, const RenderSettings& settings, State* states, Assets* assets
62 ) override;
63
64 [[nodiscard]] bool is_transparent() const override;
65 };
66
67 /// A material affected by light.
68 struct DefaultMaterial : Material
69 {
70 const LoadedShader_Default_Container* shader_container = nullptr;
71 Rgb color = colors::white;
72 float alpha = 1.0f;
73
74 Rgb ambient_tint = colors::white;
75 Rgb specular_color = colors::white;
76 float shininess = 32.0f;
77 float emissive_factor = 0.0f;
78
79 std::shared_ptr<Texture2d> diffuse;
80 std::shared_ptr<Texture2d> specular;
81 std::shared_ptr<Texture2d> emissive;
82
83 explicit DefaultMaterial(const ShaderResource& resource);
84 void use_shader(const RenderContext&) override;
85 void set_uniforms(const RenderContext&, const CompiledCamera&, const std::optional<m4>&) override;
86 void bind_textures(const RenderContext&, State* states, Assets* assets) override;
87 void apply_lights(
88 const RenderContext&, const Lights& lights, const RenderSettings& settings, State* states, Assets* assets
89 ) override;
90
91 [[nodiscard]] bool is_transparent() const override;
92 };
93
94
95 v3 vec_from_lin(const Lin_rgb& lin);
96
97 /**
98 * @}
99 */
100
101 } // namespace eu::render
102