X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterials%2Fmaterial.h;h=ea02df6b1e00dad8d0dc5275399a55104c5086d5;hp=727c61b7303c7faa230241d875c21605b6de598c;hb=ae45c0397e2cb8f0a01f2f31d01c95ff3870271e;hpb=842c817bb679a5a0abc05e8149e2e6e0ae1a0412 diff --git a/source/materials/material.h b/source/materials/material.h index 727c61b7..ea02df6b 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,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 *)); @@ -62,31 +60,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; + DataFile::Collection &coll; + Material *material; + Loader *mat_loader; static ActionMap shared_actions; public: - GenericLoader(DataFile::Collection * = 0); + GenericLoader(DataFile::Collection &); + ~GenericLoader(); - Material *get_material() { return material.release(); } + Material *get_object() { 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 +95,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,10 +103,11 @@ 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 &); @@ -190,16 +190,15 @@ 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); - else - load_sub(*mat); - material = mat; + if(ldr.material) + throw std::logic_error("Material type was already specified"); + + T *mat = new T; + ldr.material = mat; + ldr.mat_loader = new typename T::Loader(*mat, ldr.coll); + ldr.add_auxiliary_loader(*ldr.mat_loader); } } // namespace GL