Unravel Engine C++ Reference
Loading...
Searching...
No Matches
material.cpp
Go to the documentation of this file.
1#include "material.hpp"
2
3#include <fstream>
7
8namespace unravel
9{
10
12{
13 entt::meta_factory<alpha_mode>{}
14 .type("alpha_mode"_hs)
16 entt::attribute{"name", "alpha_mode"},
17 entt::attribute{"pretty_name", "Alpha Mode"},
18 })
19 .data<alpha_mode::opaque>("opaque"_hs)
21 entt::attribute{"name", "opaque"},
22 entt::attribute{"pretty_name", "Opaque"},
23 })
24 .data<alpha_mode::mask>("mask"_hs)
26 entt::attribute{"name", "mask"},
27 entt::attribute{"pretty_name", "Mask (Alpha Clip)"},
28 })
29 .data<alpha_mode::blend>("blend"_hs)
31 entt::attribute{"name", "blend"},
32 entt::attribute{"pretty_name", "Blend (Transparent)"},
33 });
34
35 entt::meta_factory<cull_type>{}
36 .type("cull_type"_hs)
38 entt::attribute{"name", "cull_type"},
39 entt::attribute{"pretty_name", "Cull Type"},
40 })
41 .data<cull_type::none>("none"_hs)
43 entt::attribute{"name", "none"},
44 entt::attribute{"pretty_name", "None"},
45 })
46 .data<cull_type::clockwise>("clockwise"_hs)
48 entt::attribute{"name", "clockwise"},
49 entt::attribute{"pretty_name", "Clockwise"},
50 })
51 .data<cull_type::counter_clockwise>("counter_clockwise"_hs)
53 entt::attribute{"name", "counter_clockwise"},
54 entt::attribute{"pretty_name", "Counter Clockwise"},
55 });
56
57 // Register material with entt
58 entt::meta_factory<material>{}
59 .type("material"_hs)
61 entt::attribute{"name", "material"},
62 entt::attribute{"pretty_name", "Material"},
63 })
64 .data<&material::set_cull_type, &material::get_cull_type>("cull_type"_hs)
66 entt::attribute{"name", "cull_type"},
67 entt::attribute{"pretty_name", "Cull Type"},
68 })
69 .func<&material::get_meta_type>("get_meta_type"_hs)
70 .func<&material::get_static_meta_type>("get_static_meta_type"_hs)
71 .func<&material::as_derived>("as_derived"_hs)
72 ;
73}
74
76{
77 try_save(ar, ser20::make_nvp("cull_type", obj.cull_type_));
78
79 // Changes here should be reflected in ex::get_format_version<material>() in asset_extensions.h
80}
83
85{
86 try_load(ar, ser20::make_nvp("cull_type", obj.cull_type_));
87
88 // Changes here should be reflected in ex::get_format_version<material>() in asset_extensions.h
89}
92
93void save_to_file(const std::string& absolute_path, const std::shared_ptr<material>& obj)
94{
95 std::ofstream stream(absolute_path);
96 if(stream.good())
97 {
98 auto ar = ser20::create_oarchive_associative(stream);
99 try_save(ar, ser20::make_nvp("material", obj));
100 }
101}
102
103void save_to_file_bin(const std::string& absolute_path, const std::shared_ptr<material>& obj)
104{
105 std::ofstream stream(absolute_path, std::ios::binary);
106 if(stream.good())
107 {
108 ser20::oarchive_binary_t ar(stream);
109 try_save(ar, ser20::make_nvp("material", obj));
110 }
111}
112
113void load_from_file(const std::string& absolute_path, std::shared_ptr<material>& obj)
114{
115 fs::file_istream input(absolute_path);
116 if(!input.is_open())
117 {
118 return;
119 }
121 try_load(ar, ser20::make_nvp("material", obj));
122}
123
124void load_from_file_bin(const std::string& absolute_path, std::shared_ptr<material>& obj)
125{
126 fs::file_istream input(absolute_path, std::ios::binary);
127 if(!input.is_open())
128 {
129 return;
130 }
132 try_load(ar, ser20::make_nvp("material", obj));
133}
134
135} // namespace unravel
stdio-backed input stream. Accepts std::ios open flags (e.g. std::ios::binary) when opening a
Base class for materials used in rendering.
Definition material.h:44
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto create_oarchive_associative(std::ostream &stream)
BinaryInputArchive iarchive_binary_t
auto create_iarchive_associative(std::istream &stream)
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
void save_to_file_bin(const std::string &absolute_path, const animation_clip &obj)
void load_from_file(const std::string &absolute_path, animation_clip &obj)
void save_to_file(const std::string &absolute_path, const animation_clip &obj)
void load_from_file_bin(const std::string &absolute_path, animation_clip &obj)
#define REFLECT(cls)
Definition reflection.h:149
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
static auto get_static_meta_type() -> entt::meta_type