1 #include <msp/core/hash.h>
2 #include <msp/strings/format.h>
3 #include "basicmaterial.h"
14 Program *Material::create_compatible_shader() const
16 return new Program(create_program_source());
19 const Program *Material::create_compatible_shader(DataFile::Collection &coll) const
21 string source = create_program_source();
22 string name = format("_material_%016x.glsl", hash64(source));
23 Program *shprog = coll.find<Program>(name);
27 shprog = new Program(create_program_source());
30 coll.add(name, shprog);
41 void Material::attach_texture_to(const Texture *tex, Texturing &texturing, ProgramData &tex_shdata, const string &name) const
48 if(const Uniform *uni = tex_shdata.find_uniform(name))
49 if(const Uniform1i *uni_int = dynamic_cast<const Uniform1i *>(uni))
50 unit = uni_int->get();
53 unit = texturing.find_free_unit(name);
55 throw runtime_error("no free texunit");
57 texturing.attach(unit, *tex);
58 tex_shdata.uniform(name, unit);
61 Material::MaterialRegistry &Material::get_material_registry()
63 static MaterialRegistry registry;
64 static bool initialized = false;
67 registry.register_type<BasicMaterial>("basic");
73 DataFile::Loader::ActionMap Material::GenericLoader::shared_actions;
75 Material::GenericLoader::GenericLoader(DataFile::Collection *c):
78 set_actions(shared_actions);
81 void Material::GenericLoader::init_actions()
83 get_material_registry().add_all(*this);