void BasicMaterial::Loader::init_actions()
{
+ Material::PropertyLoader<BasicMaterial>::init_actions();
add_property("diffuse", &BasicMaterial::set_diffuse, &BasicMaterial::set_diffuse_map, true);
add_property("specular", &BasicMaterial::set_specular, &BasicMaterial::set_specular_map, false);
add_property("normal", &BasicMaterial::set_normal_map);
if(unit<0)
throw runtime_error("no free texunit");
- texturing.attach(unit, *tex);
+ texturing.attach(unit, *tex, sampler);
tex_shdata.uniform(name, unit);
}
}
+Material::Loader::Loader(Material &m):
+ CollectionObjectLoader(m, 0)
+{ }
+
+Material::Loader::Loader(Material &m, Collection &c):
+ CollectionObjectLoader(m, &c)
+{ }
+
+void Material::Loader::init_actions()
+{
+ add("sampler", &Loader::sampler);
+}
+
+void Material::Loader::sampler(const std::string &name)
+{
+ obj.sampler = &get_collection().get<Sampler>(name);
+}
+
+
DataFile::Loader::ActionMap Material::GenericLoader::shared_actions;
Material::GenericLoader::GenericLoader(DataFile::Collection *c):
class Material
{
+private:
+ class Loader: public DataFile::CollectionObjectLoader<Material>
+ {
+ protected:
+ Loader(Material &);
+ Loader(Material &, Collection &);
+
+ virtual void init_actions();
+
+ private:
+ void sampler(const std::string &);
+ };
+
protected:
template<typename T>
struct Property
};
template<typename C>
- class PropertyLoader: public DataFile::CollectionObjectLoader<Material>
+ class PropertyLoader: public DataFile::DerivedObjectLoader<Material, Loader>
{
protected:
- PropertyLoader(C &m): CollectionObjectLoader<Material, Loader>(m, 0) { }
- PropertyLoader(C &m, Collection &c): CollectionObjectLoader<Material, Loader>(m, c) { }
+ PropertyLoader(C &m): DerivedObjectLoader<Material, Loader>(m) { }
+ PropertyLoader(C &m, Collection &c): DerivedObjectLoader<Material, Loader>(m, c) { }
void add_property(const std::string &, void (C::*)(float), void (C::*)(const Texture *));
void add_property(const std::string &, void (C::*)(const Color &), void (C::*)(const Texture *), bool);
typedef DataFile::LoadableTypeRegistry<GenericLoader, GenericLoader::AddType> MaterialRegistry;
protected:
+ const Sampler *sampler;
ProgramData shdata;
- Material() { }
+ Material(): sampler(0) { }
public:
virtual ~Material() { }
void PbrMaterial::Loader::init_actions()
{
+ Material::PropertyLoader<PbrMaterial>::init_actions();
add_property("base_color", &PbrMaterial::set_base_color, &PbrMaterial::set_base_color_map, true);
add_property("normal", &PbrMaterial::set_normal_map);
add_property("metalness", &PbrMaterial::set_metalness, &PbrMaterial::set_metalness_map);