X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Fmaterial.h;h=4f8e23ccc972001c892bb6e37a65f9448e3f1c9d;hb=23d4100160bfa33359ce297b6b36244abcaa5f82;hp=571f4cb027c4da3a41e8d317e1e4c042603a2706;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/materials/material.h b/source/materials/material.h index 571f4cb0..4f8e23cc 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 { @@ -62,31 +62,33 @@ 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(); + 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,19 +98,19 @@ protected: public: virtual ~Material() { } - virtual Program *create_compatible_shader() const; - virtual const Program *create_compatible_shader(DataFile::Collection &) const; + virtual const Program *create_compatible_shader(const std::map & = std::map()) const; protected: - virtual std::string create_program_source() const = 0; + virtual void fill_program_info(std::string &, std::map &) const = 0; 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 &); @@ -127,7 +129,8 @@ template void Material::PropertyLoader::add_property(const std::string &kw, void (C::*set_value)(float), void (C::*set_texture)(const Texture *)) { add(kw, &PropertyLoader::property_value_scalar, set_value); - add(kw+"_map", &PropertyLoader::property_texture, set_texture); + if(set_texture) + add(kw+"_map", &PropertyLoader::property_texture, set_texture); } template @@ -140,7 +143,8 @@ void Material::PropertyLoader::add_property(const std::string &kw, void (C::* add(kw, &PropertyLoader::property_value_rgba, set_value); add(kw+"_srgb", &PropertyLoader::property_value_srgb_alpha, set_value); } - add(kw+"_map", &PropertyLoader::property_texture, set_texture); + if(set_texture) + add(kw+"_map", &PropertyLoader::property_texture, set_texture); } template @@ -189,16 +193,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