1 #include <msp/core/hash.h>
2 #include <msp/strings/format.h>
3 #include "basicmaterial.h"
5 #include "pbrmaterial.h"
9 #include "unlitmaterial.h"
16 const Program *Material::create_compatible_shader(const map<string, int> &extra_spec) const
19 map<string, int> spec_values;
20 fill_program_info(module_name, spec_values);
22 for(const auto &kvp: extra_spec)
23 spec_values[kvp.first] = kvp.second;
25 string info = module_name;
26 for(const auto &kvp: spec_values)
27 info += format(",%s:%d", kvp.first, kvp.second);
29 Resources &res = Resources::get_global();
30 string name = format("_material_%016x.shader", hash64(info));
31 Program *shprog = res.find<Program>(name);
35 const Module &module = res.get<Module>(module_name);
36 shprog = new Program(module, spec_values);
39 res.add(name, shprog);
50 void Material::set_debug_name(const string &name)
53 shdata.set_debug_name(name+" [UBO]");
59 Material::MaterialRegistry &Material::get_material_registry()
61 static MaterialRegistry registry;
62 static bool initialized = false;
66 registry.register_type<BasicMaterial>("basic");
67 registry.register_type<PbrMaterial>("pbr");
68 registry.register_type<UnlitMaterial>("unlit");
74 Material::Loader::Loader(Material &m):
75 CollectionObjectLoader(m, 0)
78 Material::Loader::Loader(Material &m, Collection &c):
79 CollectionObjectLoader(m, &c)
82 void Material::Loader::init_actions()
84 add("sampler", &Loader::sampler);
87 void Material::Loader::sampler(const string &name)
89 obj.sampler = &get_collection().get<Sampler>(name);
93 DataFile::Loader::ActionMap Material::GenericLoader::shared_actions;
95 Material::GenericLoader::GenericLoader(DataFile::Collection *c):
100 set_actions(shared_actions);
103 Material::GenericLoader::~GenericLoader()
109 void Material::GenericLoader::init_actions()
111 add("type", &GenericLoader::type);
114 void Material::GenericLoader::type(const DataFile::Symbol &sym)
116 get_material_registry().invoke(sym.name, *this);