X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fmaterial.h;h=571f4cb027c4da3a41e8d317e1e4c042603a2706;hp=3e9765d2a2b9cbfa7d408a37642ca12577fa9ed1;hb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;hpb=fd62e55d37716787fe909883a1b18e5b8128ec80 diff --git a/source/material.h b/source/material.h index 3e9765d2..571f4cb0 100644 --- a/source/material.h +++ b/source/material.h @@ -6,15 +6,28 @@ #include #include "color.h" #include "programdata.h" +#include "texture.h" namespace Msp { namespace GL { -class Texture; class Texturing; class Material { +private: + class Loader: public DataFile::CollectionObjectLoader + { + protected: + Loader(Material &); + Loader(Material &, Collection &); + + virtual void init_actions(); + + private: + void sampler(const std::string &); + }; + protected: template struct Property @@ -26,11 +39,11 @@ protected: }; template - class LoaderBase: public DataFile::CollectionObjectLoader + class PropertyLoader: public DataFile::DerivedObjectLoader { protected: - LoaderBase(C &m): CollectionObjectLoader(m, 0) { } - LoaderBase(C &m, Collection &c): CollectionObjectLoader(m, &c) { } + 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 *)); void add_property(const std::string &, void (C::*)(const Color &), void (C::*)(const Texture *), bool); @@ -76,9 +89,10 @@ private: typedef DataFile::LoadableTypeRegistry MaterialRegistry; protected: + const Sampler *sampler; ProgramData shdata; - Material() { } + Material(): sampler(0) { } public: virtual ~Material() { } @@ -110,65 +124,67 @@ void Material::register_type(const std::string &kw) template -void Material::LoaderBase::add_property(const std::string &kw, void (C::*set_value)(float), void (C::*set_texture)(const Texture *)) +void Material::PropertyLoader::add_property(const std::string &kw, void (C::*set_value)(float), void (C::*set_texture)(const Texture *)) { - add(kw, &LoaderBase::property_value_scalar, set_value); - add(kw+"_map", &LoaderBase::property_texture, set_texture); + add(kw, &PropertyLoader::property_value_scalar, set_value); + add(kw+"_map", &PropertyLoader::property_texture, set_texture); } template -void Material::LoaderBase::add_property(const std::string &kw, void (C::*set_value)(const Color &), void (C::*set_texture)(const Texture *), bool allow_alpha) +void Material::PropertyLoader::add_property(const std::string &kw, void (C::*set_value)(const Color &), void (C::*set_texture)(const Texture *), bool allow_alpha) { - add(kw, &LoaderBase::property_value_rgb, set_value); - add(kw+"_srgb", &LoaderBase::property_value_srgb, set_value); + add(kw, &PropertyLoader::property_value_rgb, set_value); + add(kw+"_srgb", &PropertyLoader::property_value_srgb, set_value); if(allow_alpha) { - add(kw, &LoaderBase::property_value_rgba, set_value); - add(kw+"_srgb", &LoaderBase::property_value_srgb_alpha, set_value); + add(kw, &PropertyLoader::property_value_rgba, set_value); + add(kw+"_srgb", &PropertyLoader::property_value_srgb_alpha, set_value); } - add(kw+"_map", &LoaderBase::property_texture, set_texture); + add(kw+"_map", &PropertyLoader::property_texture, set_texture); } template -void Material::LoaderBase::add_property(const std::string &kw, void (C::*set_texture)(const Texture *)) +void Material::PropertyLoader::add_property(const std::string &kw, void (C::*set_texture)(const Texture *)) { - add(kw+"_map", &LoaderBase::property_texture, set_texture); + add(kw+"_map", &PropertyLoader::property_texture, set_texture); } template -void Material::LoaderBase::property_value_scalar(void (C::*set_value)(float), float value) +void Material::PropertyLoader::property_value_scalar(void (C::*set_value)(float), float value) { (static_cast(obj).*set_value)(value); } template -void Material::LoaderBase::property_value_rgb(void (C::*set_value)(const Color &), float r, float g, float b) +void Material::PropertyLoader::property_value_rgb(void (C::*set_value)(const Color &), float r, float g, float b) { (static_cast(obj).*set_value)(Color(r, g, b)); } template -void Material::LoaderBase::property_value_rgba(void (C::*set_value)(const Color &), float r, float g, float b, float a) +void Material::PropertyLoader::property_value_rgba(void (C::*set_value)(const Color &), float r, float g, float b, float a) { (static_cast(obj).*set_value)(Color(r, g, b, a)); } template -void Material::LoaderBase::property_value_srgb(void (C::*set_value)(const Color &), float r, float g, float b) +void Material::PropertyLoader::property_value_srgb(void (C::*set_value)(const Color &), float r, float g, float b) { (static_cast(obj).*set_value)(Color(r, g, b).to_linear()); } template -void Material::LoaderBase::property_value_srgb_alpha(void (C::*set_value)(const Color &), float r, float g, float b, float a) +void Material::PropertyLoader::property_value_srgb_alpha(void (C::*set_value)(const Color &), float r, float g, float b, float a) { (static_cast(obj).*set_value)(Color(r, g, b, a).to_linear()); } template -void Material::LoaderBase::property_texture(void (C::*set_texture)(const Texture *), const std::string &name) +void Material::PropertyLoader::property_texture(void (C::*set_texture)(const Texture *), const std::string &name) { - (static_cast(obj).*set_texture)(&get_collection().get(name)); + /* The static_cast around get_collection is needed because otherwise Android + SDK's g++ 4.9 fails to parse get as a template function call */ + (static_cast(obj).*set_texture)(&static_cast(get_collection()).get(name)); }