]> git.tdb.fi Git - libs/gl.git/blobdiff - source/material.h
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / material.h
index 5515f29eee539a211059fb15f6869332659c1224..571f4cb027c4da3a41e8d317e1e4c042603a2706 100644 (file)
@@ -15,6 +15,19 @@ class Texturing;
 
 class Material
 {
+private:
+       class Loader: public DataFile::CollectionObjectLoader<Material>
+       {
+       protected:
+               Loader(Material &);
+               Loader(Material &, Collection &);
+
+               virtual void init_actions();
+
+       private:
+               void sampler(const std::string &);
+       };
+
 protected:
        template<typename T>
        struct Property
@@ -26,11 +39,11 @@ protected:
        };
 
        template<typename C>
-       class LoaderBase: public DataFile::CollectionObjectLoader<Material>
+       class PropertyLoader: public DataFile::DerivedObjectLoader<Material, Loader>
        {
        protected:
-               LoaderBase(C &m): CollectionObjectLoader<Material>(m, 0) { }
-               LoaderBase(C &m, Collection &c): CollectionObjectLoader<Material>(m, &c) { }
+               PropertyLoader(C &m): DerivedObjectLoader<Material, Loader>(m) { }
+               PropertyLoader(C &m, Collection &c): DerivedObjectLoader<Material, Loader>(m, c) { }
 
                void add_property(const std::string &, void (C::*)(float), void (C::*)(const Texture *));
                void add_property(const std::string &, void (C::*)(const Color &), void (C::*)(const Texture *), bool);
@@ -76,9 +89,10 @@ private:
        typedef DataFile::LoadableTypeRegistry<GenericLoader, GenericLoader::AddType> MaterialRegistry;
 
 protected:
+       const Sampler *sampler;
        ProgramData shdata;
 
-       Material() { }
+       Material(): sampler(0) { }
 public:
        virtual ~Material() { }
 
@@ -110,63 +124,63 @@ void Material::register_type(const std::string &kw)
 
 
 template<typename C>
-void Material::LoaderBase<C>::add_property(const std::string &kw, void (C::*set_value)(float), void (C::*set_texture)(const Texture *))
+void Material::PropertyLoader<C>::add_property(const std::string &kw, void (C::*set_value)(float), void (C::*set_texture)(const Texture *))
 {
-       add(kw, &LoaderBase<C>::property_value_scalar, set_value);
-       add(kw+"_map", &LoaderBase<C>::property_texture, set_texture);
+       add(kw, &PropertyLoader<C>::property_value_scalar, set_value);
+       add(kw+"_map", &PropertyLoader<C>::property_texture, set_texture);
 }
 
 template<typename C>
-void Material::LoaderBase<C>::add_property(const std::string &kw, void (C::*set_value)(const Color &), void (C::*set_texture)(const Texture *), bool allow_alpha)
+void Material::PropertyLoader<C>::add_property(const std::string &kw, void (C::*set_value)(const Color &), void (C::*set_texture)(const Texture *), bool allow_alpha)
 {
-       add(kw, &LoaderBase<C>::property_value_rgb, set_value);
-       add(kw+"_srgb", &LoaderBase<C>::property_value_srgb, set_value);
+       add(kw, &PropertyLoader<C>::property_value_rgb, set_value);
+       add(kw+"_srgb", &PropertyLoader<C>::property_value_srgb, set_value);
        if(allow_alpha)
        {
-               add(kw, &LoaderBase<C>::property_value_rgba, set_value);
-               add(kw+"_srgb", &LoaderBase<C>::property_value_srgb_alpha, set_value);
+               add(kw, &PropertyLoader<C>::property_value_rgba, set_value);
+               add(kw+"_srgb", &PropertyLoader<C>::property_value_srgb_alpha, set_value);
        }
-       add(kw+"_map", &LoaderBase<C>::property_texture, set_texture);
+       add(kw+"_map", &PropertyLoader<C>::property_texture, set_texture);
 }
 
 template<typename C>
-void Material::LoaderBase<C>::add_property(const std::string &kw, void (C::*set_texture)(const Texture *))
+void Material::PropertyLoader<C>::add_property(const std::string &kw, void (C::*set_texture)(const Texture *))
 {
-       add(kw+"_map", &LoaderBase<C>::property_texture, set_texture);
+       add(kw+"_map", &PropertyLoader<C>::property_texture, set_texture);
 }
 
 template<typename C>
-void Material::LoaderBase<C>::property_value_scalar(void (C::*set_value)(float), float value)
+void Material::PropertyLoader<C>::property_value_scalar(void (C::*set_value)(float), float value)
 {
        (static_cast<C &>(obj).*set_value)(value);
 }
 
 template<typename C>
-void Material::LoaderBase<C>::property_value_rgb(void (C::*set_value)(const Color &), float r, float g, float b)
+void Material::PropertyLoader<C>::property_value_rgb(void (C::*set_value)(const Color &), float r, float g, float b)
 {
        (static_cast<C &>(obj).*set_value)(Color(r, g, b));
 }
 
 template<typename C>
-void Material::LoaderBase<C>::property_value_rgba(void (C::*set_value)(const Color &), float r, float g, float b, float a)
+void Material::PropertyLoader<C>::property_value_rgba(void (C::*set_value)(const Color &), float r, float g, float b, float a)
 {
        (static_cast<C &>(obj).*set_value)(Color(r, g, b, a));
 }
 
 template<typename C>
-void Material::LoaderBase<C>::property_value_srgb(void (C::*set_value)(const Color &), float r, float g, float b)
+void Material::PropertyLoader<C>::property_value_srgb(void (C::*set_value)(const Color &), float r, float g, float b)
 {
        (static_cast<C &>(obj).*set_value)(Color(r, g, b).to_linear());
 }
 
 template<typename C>
-void Material::LoaderBase<C>::property_value_srgb_alpha(void (C::*set_value)(const Color &), float r, float g, float b, float a)
+void Material::PropertyLoader<C>::property_value_srgb_alpha(void (C::*set_value)(const Color &), float r, float g, float b, float a)
 {
        (static_cast<C &>(obj).*set_value)(Color(r, g, b, a).to_linear());
 }
 
 template<typename C>
-void Material::LoaderBase<C>::property_texture(void (C::*set_texture)(const Texture *), const std::string &name)
+void Material::PropertyLoader<C>::property_texture(void (C::*set_texture)(const Texture *), const std::string &name)
 {
        /* The static_cast around get_collection is needed because otherwise Android
        SDK's g++ 4.9 fails to parse get<Texture> as a template function call */