1 #include <msp/gl/extensions/msp_legacy_features.h>
19 void Material::update_parameter(int mask) const
25 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, &ambient.r);
27 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuse.r);
29 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specular.r);
31 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, &emission.r);
33 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
36 void Material::set_ambient(const Color &a)
39 shdata.uniform("material.ambient", ambient);
40 update_parameter(AMBIENT);
43 void Material::set_diffuse(const Color &d)
46 shdata.uniform("material.diffuse", diffuse);
47 update_parameter(DIFFUSE);
50 void Material::set_specular(const Color &s)
53 shdata.uniform("material.specular", specular);
54 update_parameter(SPECULAR);
57 void Material::set_emission(const Color &e)
60 shdata.uniform("material.emission", emission);
61 update_parameter(EMISSION);
64 void Material::set_shininess(float s)
67 shdata.uniform("material.shininess", shininess);
68 update_parameter(SHININESS);
71 void Material::set_reflectivity(float r)
74 shdata.uniform("reflectivity", reflectivity);
77 void Material::bind() const
79 static Require _req(MSP_legacy_features);
86 Material::Loader::Loader(Material &m):
87 DataFile::CollectionObjectLoader<Material>(m, 0)
92 Material::Loader::Loader(Material &m, Collection &c):
93 DataFile::CollectionObjectLoader<Material>(m, &c)
98 void Material::Loader::init()
100 if(Resources *res = dynamic_cast<Resources *>(coll))
101 srgb = res->get_srgb_conversion();
105 add("ambient", &Loader::ambient);
106 add("diffuse", &Loader::diffuse);
107 add("specular", &Loader::specular);
108 add("emission", &Loader::emission);
109 add("shininess", &Loader::shininess);
110 add("reflectivity", &Loader::reflectivity);
113 Color Material::Loader::make_color(float r, float g, float b, float a)
121 void Material::Loader::ambient(float r, float g, float b, float a)
123 obj.set_ambient(make_color(r, g, b, a));
126 void Material::Loader::diffuse(float r, float g, float b, float a)
128 obj.set_diffuse(make_color(r, g, b, a));
131 void Material::Loader::specular(float r, float g, float b, float a)
133 obj.set_specular(make_color(r, g, b, a));
136 void Material::Loader::emission(float r, float g, float b, float a)
138 obj.set_emission(make_color(r, g, b, a));
141 void Material::Loader::shininess(float s)
143 obj.set_shininess(s);
146 void Material::Loader::reflectivity(float r)
148 obj.set_reflectivity(r);