X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmaterials%2Fbasicmaterial.cpp;h=5ad694b685803e892032b24a0d199cda86befca7;hb=da85eb77172dbd62f764a63b45c79fc059af563b;hp=362fc9db14e6a8636960bec3a746cd8e62715ed8;hpb=7aaec9a70b8d7733429bec043f8e33e02956f266;p=libs%2Fgl.git diff --git a/source/materials/basicmaterial.cpp b/source/materials/basicmaterial.cpp index 362fc9db..5ad694b6 100644 --- a/source/materials/basicmaterial.cpp +++ b/source/materials/basicmaterial.cpp @@ -5,6 +5,17 @@ using namespace std; namespace Msp { namespace GL { +const Tag BasicMaterial::texture_tags[] = +{ + Tag("diffuse_map"), + Tag("specular_map"), + Tag("shininess_map"), + Tag("normal_map"), + Tag("emission_map"), + Tag("reflectivity_map"), + Tag() +}; + BasicMaterial::BasicMaterial(): receive_shadows(false) { @@ -15,38 +26,25 @@ BasicMaterial::BasicMaterial(): set_reflectivity(0.0f); } -string BasicMaterial::create_program_source() const -{ - string source = "import phong;\n"; - if(diffuse.texture) - source += "const bool use_diffuse_map = true;\n"; - if(specular.texture || specular.value.r || specular.value.g || specular.value.b) - { - source += "const bool use_specular = true;\n"; - if(specular.texture) - source += "const bool use_specular_map = true;\n"; - if(shininess.texture) - source += "const bool use_shininess_map = true;\n"; - } - if(normal.texture) - source += "const bool use_normal_map = true;\n"; - if(emission.texture || emission.value.r || emission.value.g || emission.value.b) - { - source += "const bool use_emission = true;\n"; - if(emission.texture) - source += "const bool use_emission_map = true;\n"; - } - if(reflectivity.value || reflectivity.texture) - { - source += "const bool use_reflectivity = true;\n"; - if (reflectivity.texture) - source += "const bool use_reflectivity_map = true;\n"; - } - if(receive_shadows) - source += "const bool use_shadow_map = true;\n"; - return source; +void BasicMaterial::fill_program_info(string &module_name, map &spec_values) const +{ + module_name = "phong.glsl"; + spec_values["use_diffuse_map"] = (diffuse.texture!=0); + bool use_specular = (specular.texture || specular.value.r || specular.value.g || specular.value.b); + spec_values["use_specular"] = use_specular; + spec_values["use_specular_map"] = (specular.texture!=0); + spec_values["use_shininess_map"] = (use_specular && shininess.texture!=0); + spec_values["use_normal_map"] = (normal.texture!=0); + bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b); + spec_values["use_emission"] = use_emission; + spec_values["use_emission_map"] = (emission.texture!=0); + spec_values["use_reflectivity"] = (reflectivity.value!=0 || reflectivity.texture!=0); + spec_values["use_reflectivity_map"] = (reflectivity.texture!=0); + spec_values["use_shadow_map"] = receive_shadows; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" void BasicMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const { attach_texture_to(diffuse.texture, texturing, tex_shdata, "diffuse_map"); @@ -56,6 +54,25 @@ void BasicMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_sh attach_texture_to(shininess.texture, texturing, tex_shdata, "shininess_map"); attach_texture_to(reflectivity.texture, texturing, tex_shdata, "reflectivity_map"); } +#pragma GCC diagnostic pop + +const Texture *BasicMaterial::get_texture(Tag tag) const +{ + if(tag==texture_tags[0]) + return diffuse.texture; + else if(tag==texture_tags[1]) + return specular.texture; + else if(tag==texture_tags[2]) + return shininess.texture; + else if(tag==texture_tags[3]) + return normal.texture; + else if(tag==texture_tags[4]) + return emission.texture; + else if(tag==texture_tags[5]) + return reflectivity.texture; + else + return 0; +} void BasicMaterial::set_diffuse(const Color &color) {