X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterials%2Fmaterial.h;h=a5ee59e5ee1ecb9b181e53ffda03bf5562d0d8dd;hp=a04e74585e56c9fbfc9088b27bc9eb4f1ff96c81;hb=fe2fc291a4fc618425c64112c9ffd3519f0b8a3e;hpb=6f39983060a27634c012f66c82fea0d09fea9774 diff --git a/source/materials/material.h b/source/materials/material.h index a04e7458..a5ee59e5 100644 --- a/source/materials/material.h +++ b/source/materials/material.h @@ -1,8 +1,8 @@ #ifndef MSP_GL_MATERIAL_H_ #define MSP_GL_MATERIAL_H_ +#include #include -#include #include #include "color.h" #include "programdata.h" @@ -62,31 +62,32 @@ public: { private: template - struct AddType + struct CreateMaterial { - static void add(GenericLoader &ldr, const std::string &kw) { ldr.add(kw, &GenericLoader::typed_material); } + void operator()(const std::string &, GenericLoader &) const; }; DataFile::Collection *coll; - RefPtr material; + Material *material; + Loader *mat_loader; static ActionMap shared_actions; public: GenericLoader(DataFile::Collection * = 0); + ~GenericLoader(); - Material *get_material() { return material.release(); } + Material *get_material() { Material *m = material; material = 0; return m; } private: virtual void init_actions(); - template - void typed_material(); + void type(const DataFile::Symbol &); friend class Material; }; private: - typedef DataFile::LoadableTypeRegistry MaterialRegistry; + typedef TypeRegistry MaterialRegistry; protected: const Sampler *sampler; @@ -96,7 +97,7 @@ protected: public: virtual ~Material() { } - virtual const Program *create_compatible_shader(DataFile::Collection &) const; + virtual const Program *create_compatible_shader(const std::map & = std::map()) const; protected: virtual void fill_program_info(std::string &, std::map &) const = 0; @@ -113,6 +114,8 @@ public: virtual const Texture *get_texture(Tag) const = 0; const Sampler *get_sampler() const { return sampler; } + void set_debug_name(const std::string &); + template static void register_type(const std::string &); private: @@ -194,16 +197,18 @@ void Material::PropertyLoader::property_texture(void (C::*set_texture)(const template -void Material::GenericLoader::typed_material() +void Material::GenericLoader::CreateMaterial::operator()(const std::string &, GenericLoader &ldr) const { - if(material) - throw std::logic_error("Material was already loaded"); - RefPtr mat = new T; - if(coll) - load_sub(*mat, *coll); + if(ldr.material) + throw std::logic_error("Material type was already specified"); + + T *mat = new T; + ldr.material = mat; + if(ldr.coll) + ldr.mat_loader = new typename T::Loader(*mat, *ldr.coll); else - load_sub(*mat); - material = mat; + ldr.mat_loader = new typename T::Loader(*mat); + ldr.add_auxiliary_loader(*ldr.mat_loader); } } // namespace GL