X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterials%2Fmaterial.h;h=98baaa54ff2faf41b7975427dc4412306ac2e906;hp=43da2542612d7ba50bbb4f4e0d2ee886f7a48483;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=5b652353d545a3190ea2d86ba82a87b2e3382a0d diff --git a/source/materials/material.h b/source/materials/material.h index 43da2542..98baaa54 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" @@ -11,13 +11,14 @@ namespace Msp { namespace GL { +class Sampler; + class Material { private: class Loader: public DataFile::CollectionObjectLoader { protected: - Loader(Material &); Loader(Material &, Collection &); virtual void init_actions(); @@ -40,7 +41,6 @@ protected: class PropertyLoader: public DataFile::DerivedObjectLoader { protected: - PropertyLoader(C &m): DerivedObjectLoader(m) { } PropertyLoader(C &m, Collection &c): DerivedObjectLoader(m, c) { } void add_property(const std::string &, void (C::*)(float), void (C::*)(const Texture *)); @@ -56,44 +56,24 @@ protected: }; public: - class GenericLoader: public DataFile::Loader + class GenericLoader: public DataFile::DynamicObjectLoader { - private: - template - struct CreateMaterial - { - void operator()(const std::string &, GenericLoader &) const; - }; - - DataFile::Collection *coll; - Material *material; - Loader *mat_loader; - - static ActionMap shared_actions; + friend class Material; public: - GenericLoader(DataFile::Collection * = 0); - ~GenericLoader(); - - Material *get_material() { Material *m = material; material = 0; return m; } - private: - virtual void init_actions(); - - void type(const DataFile::Symbol &); + GenericLoader(Collection &c): DynamicObjectLoader(&c) { } - friend class Material; + protected: + virtual const TypeRegistry &get_type_registry() const { return get_material_registry(); } }; -private: - typedef TypeRegistry MaterialRegistry; - protected: - const Sampler *sampler; + const Sampler *sampler = 0; ProgramData shdata; - Material(): sampler(0) { } + Material() = default; public: - virtual ~Material() { } + virtual ~Material() = default; virtual const Program *create_compatible_shader(const std::map & = std::map()) const; protected: @@ -105,14 +85,14 @@ public: virtual const Tag *get_texture_tags() const = 0; virtual const Texture *get_texture(Tag) const = 0; - const Sampler *get_sampler() const { return sampler; } + virtual const Sampler *get_sampler(Tag) const { return sampler; } void set_debug_name(const std::string &); template static void register_type(const std::string &); private: - static MaterialRegistry &get_material_registry(); + static GenericLoader::TypeRegistry &get_material_registry(); }; template @@ -188,22 +168,6 @@ void Material::PropertyLoader::property_texture(void (C::*set_texture)(const (static_cast(obj).*set_texture)(&static_cast(get_collection()).get(name)); } - -template -void Material::GenericLoader::CreateMaterial::operator()(const std::string &, GenericLoader &ldr) const -{ - 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 - ldr.mat_loader = new typename T::Loader(*mat); - ldr.add_auxiliary_loader(*ldr.mat_loader); -} - } // namespace GL } // namespace Msp