Unravel Engine C++ Reference
Loading...
Searching...
No Matches
material.cpp
Go to the documentation of this file.
1#include "material.h"
2
3#include <graphics/texture.h>
4#include <graphics/uniform.h>
5
6namespace unravel
7{
8
10{
11 auto mat = std::make_shared<material>(*this);
12 return mat;
13}
14
16{
17 static asset_handle<gfx::texture> texture;
18 return texture;
19}
20
22{
23 static asset_handle<gfx::texture> texture;
24 return texture;
25}
26
27auto material::submit(gpu_program* program) const -> bool
28{
29 return false;
30}
31
33{
34 return cull_type_;
35}
36
38{
39 cull_type_ = val;
40}
41
42auto material::get_render_states(bool apply_cull, bool depth_write, bool depth_test) const -> uint64_t
43{
44 // Set render states.
45 uint64_t states = 0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_MSAA;
46
47 if(depth_write)
48 {
49 states |= BGFX_STATE_WRITE_Z;
50 }
51
52 if(depth_test)
53 {
54 states |= BGFX_STATE_DEPTH_TEST_LESS;
55 }
56
57 if(apply_cull)
58 {
59 auto cull_type = get_cull_type();
61 {
62 states |= BGFX_STATE_CULL_CCW;
63 }
65 {
66 states |= BGFX_STATE_CULL_CW;
67 }
68 }
69
70 return states;
71}
72
73
74auto pbr_material::clone() const -> material::sptr
75{
76 auto mat = std::make_shared<pbr_material>(*this);
77 return mat;
78}
79
80
81} // namespace unravel
Class representing a GPU program.
Definition gpu_program.h:17
Base class for materials used in rendering.
Definition material.h:32
static auto default_normal_map() -> asset_handle< gfx::texture > &
Gets the default normal map.
Definition material.cpp:21
static auto default_color_map() -> asset_handle< gfx::texture > &
Gets the default color map.
Definition material.cpp:15
std::shared_ptr< material > sptr
Definition material.h:36
void set_cull_type(cull_type val)
Sets the culling type of the material.
Definition material.cpp:37
virtual auto submit(gpu_program *program) const -> bool
Submits the material properties to the GPU program.
Definition material.cpp:27
virtual auto get_render_states(bool apply_cull=true, bool depth_write=true, bool depth_test=true) const -> uint64_t
Gets the render states for the material.
Definition material.cpp:42
cull_type cull_type_
< The culling type for this material.
Definition material.h:92
auto get_cull_type() const -> cull_type
Gets the culling type of the material.
Definition material.cpp:32
virtual auto clone() const -> material::sptr
Clones a materiial.
Definition material.cpp:9
auto clone() const -> std::shared_ptr< material > override
Definition material.cpp:74
cull_type
Enum representing the type of culling to be used.
Definition material.h:21
@ counter_clockwise
Cull counter-clockwise faces.
@ clockwise
Cull clockwise faces.
Represents a handle to an asset, providing access and management functions.