1 #include <msp/core/hash.h>
2 #include <msp/strings/format.h>
3 #include "basicmaterial.h"
5 #include "pbrmaterial.h"
15 Program *Material::create_compatible_shader() const
17 return new Program(create_program_source());
20 const Program *Material::create_compatible_shader(DataFile::Collection &coll) const
22 string source = create_program_source();
23 string name = format("_material_%016x.glsl", hash64(source));
24 Program *shprog = coll.find<Program>(name);
28 shprog = new Program(create_program_source());
31 coll.add(name, shprog);
42 void Material::attach_texture_to(const Texture *tex, Texturing &texturing, ProgramData &tex_shdata, const string &name) const
49 if(const Uniform *uni = tex_shdata.find_uniform(name))
50 if(const Uniform1i *uni_int = dynamic_cast<const Uniform1i *>(uni))
51 unit = uni_int->get();
54 unit = texturing.find_free_unit(name);
56 throw runtime_error("no free texunit");
58 texturing.attach(unit, *tex);
59 tex_shdata.uniform(name, unit);
62 Material::MaterialRegistry &Material::get_material_registry()
64 static MaterialRegistry registry;
65 static bool initialized = false;
68 registry.register_type<BasicMaterial>("basic");
69 registry.register_type<PbrMaterial>("pbr");
75 DataFile::Loader::ActionMap Material::GenericLoader::shared_actions;
77 Material::GenericLoader::GenericLoader(DataFile::Collection *c):
80 set_actions(shared_actions);
83 void Material::GenericLoader::init_actions()
85 get_material_registry().add_all(*this);