X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Fmaterial.h;h=77e7d44ec29bdedf174d393d5f505aba0cfeb18f;hb=9813f8711628a0fbe786406e974dc33546dc9cee;hp=727c61b7303c7faa230241d875c21605b6de598c;hpb=842c817bb679a5a0abc05e8149e2e6e0ae1a0412;p=libs%2Fgl.git diff --git a/source/materials/material.h b/source/materials/material.h index 727c61b7..77e7d44e 100644 --- a/source/materials/material.h +++ b/source/materials/material.h @@ -2,7 +2,7 @@ #define MSP_GL_MATERIAL_H_ #include -#include +#include #include #include "color.h" #include "programdata.h" @@ -11,7 +11,7 @@ namespace Msp { namespace GL { -class Texturing; +class Sampler; class Material { @@ -19,7 +19,6 @@ private: class Loader: public DataFile::CollectionObjectLoader { protected: - Loader(Material &); Loader(Material &, Collection &); virtual void init_actions(); @@ -42,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 *)); @@ -58,36 +56,17 @@ protected: }; public: - class GenericLoader: public DataFile::Loader + class GenericLoader: public DataFile::DynamicObjectLoader { - private: - template - struct AddType - { - static void add(GenericLoader &ldr, const std::string &kw) { ldr.add(kw, &GenericLoader::typed_material); } - }; - - DataFile::Collection *coll; - RefPtr material; - - static ActionMap shared_actions; + friend class Material; public: - GenericLoader(DataFile::Collection * = 0); - - Material *get_material() { return material.release(); } - private: - virtual void init_actions(); - - template - void typed_material(); + GenericLoader(Collection &c): DynamicObjectLoader(&c) { } - friend class Material; + protected: + virtual const TypeRegistry &get_type_registry() const { return get_material_registry(); } }; -private: - typedef DataFile::LoadableTypeRegistry MaterialRegistry; - protected: const Sampler *sampler; ProgramData shdata; @@ -96,7 +75,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; @@ -104,15 +83,16 @@ public: /** Returns the uniforms for the material. */ const ProgramData &get_shader_data() const { return shdata; } -protected: - void attach_texture_to(const Texture *, Texturing &, ProgramData &, const std::string &) const; -public: - virtual void attach_textures_to(Texturing &, ProgramData &) const = 0; + virtual const Tag *get_texture_tags() const = 0; + virtual const Texture *get_texture(Tag) const = 0; + 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,20 +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::typed_material() -{ - if(material) - throw std::logic_error("Material was already loaded"); - RefPtr mat = new T; - if(coll) - load_sub(*mat, *coll); - else - load_sub(*mat); - material = mat; -} - } // namespace GL } // namespace Msp