X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbasicmaterial.cpp;fp=source%2Fbasicmaterial.cpp;h=7ba8380c1b47b62db0dad9746d19db1a1ec5413b;hp=0000000000000000000000000000000000000000;hb=3500f13f51dabadd2e7f06b81820936520cc8115;hpb=5ee6399ae7d274a9c78701d79c730f3dd7145812 diff --git a/source/basicmaterial.cpp b/source/basicmaterial.cpp new file mode 100644 index 00000000..7ba8380c --- /dev/null +++ b/source/basicmaterial.cpp @@ -0,0 +1,113 @@ +#include "basicmaterial.h" + +using namespace std; + +namespace Msp { +namespace GL { + +BasicMaterial::BasicMaterial() +{ + set_diffuse(Color(1.0f)); + set_specular(Color(0.0f)); + set_emission(Color(0.0f)); + set_shininess(50.0f); + set_reflectivity(0.0f); +} + +void BasicMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const +{ + attach_texture_to(diffuse.texture, texturing, tex_shdata, "diffuse_map"); + attach_texture_to(specular.texture, texturing, tex_shdata, "specular_map"); + attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map"); + attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map"); + attach_texture_to(shininess.texture, texturing, tex_shdata, "shininess_map"); + attach_texture_to(reflectivity.texture, texturing, tex_shdata, "reflectivity_map"); +} + +void BasicMaterial::set_diffuse(const Color &color) +{ + diffuse.value = color; + shdata.uniform("basic_material.diffuse", color); +} + +void BasicMaterial::set_diffuse_map(const Texture *tex) +{ + diffuse.texture = tex; +} + +void BasicMaterial::set_specular(const Color &color) +{ + specular.value = color; + shdata.uniform("basic_material.specular", color); +} + +void BasicMaterial::set_specular_map(const Texture *tex) +{ + specular.texture = tex; +} + +void BasicMaterial::set_normal_map(const Texture *tex) +{ + normal.texture = tex; +} + +void BasicMaterial::set_emission(const Color &color) +{ + emission.value = color; + shdata.uniform("basic_material.emission", color); +} + +void BasicMaterial::set_emission_map(const Texture *tex) +{ + emission.texture = tex; +} + +void BasicMaterial::set_shininess(float value) +{ + shininess.value = value; + shdata.uniform("basic_material.shininess", value); +} + +void BasicMaterial::set_shininess_map(const Texture *tex) +{ + shininess.texture = tex; +} + +void BasicMaterial::set_reflectivity(float value) +{ + reflectivity.value = value; + shdata.uniform("basic_material.reflectivity", value); +} + +void BasicMaterial::set_reflectivity_map(const Texture *tex) +{ + reflectivity.texture = tex; +} + + +DataFile::Loader::ActionMap BasicMaterial::Loader::shared_actions; + +BasicMaterial::Loader::Loader(BasicMaterial &m): + DerivedObjectLoader >(m) +{ + set_actions(shared_actions); +} + +BasicMaterial::Loader::Loader(BasicMaterial &m, Collection &c): + DerivedObjectLoader >(m, c) +{ + set_actions(shared_actions); +} + +void BasicMaterial::Loader::init_actions() +{ + add_property("diffuse", &BasicMaterial::set_diffuse, &BasicMaterial::set_diffuse_map, true); + add_property("specular", &BasicMaterial::set_specular, &BasicMaterial::set_specular_map, false); + add_property("normal", &BasicMaterial::set_normal_map); + add_property("emission", &BasicMaterial::set_emission, &BasicMaterial::set_emission_map, false); + add_property("shininess", &BasicMaterial::set_shininess, &BasicMaterial::set_shininess_map); + add_property("reflectivity", &BasicMaterial::set_reflectivity, &BasicMaterial::set_reflectivity_map); +} + +} // namespace GL +} // namespace Msp