X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Feffects%2Fshadowmap.cpp;h=27b695443341c860337242d5c2908d0479b502d7;hp=6c49f79fc9a70ba1fc97be427197a6054b24651b;hb=083a8227715fa32c841fc2b8126e4ab8d2840ba0;hpb=54fdd850d1e657bc357d859a532497905ded741a diff --git a/source/effects/shadowmap.cpp b/source/effects/shadowmap.cpp index 6c49f79f..27b69544 100644 --- a/source/effects/shadowmap.cpp +++ b/source/effects/shadowmap.cpp @@ -273,5 +273,89 @@ void ShadowMap::set_debug_name(const string &name) #endif } + +ShadowMap *ShadowMap::Template::create(const map &renderables) const +{ + Renderable *content = get_item(renderables, content_name); + if(!content || !lighting) + throw invalid_operation("ShadowMap::Template::create"); + + RefPtr shadow_map = new ShadowMap(width, height, *content, *lighting); + shadow_map->set_target(target, radius); + shadow_map->set_depth_bias(depth_bias); + shadow_map->set_darkness(darkness); + + for(const ShadowedLight &l: lights) + { + Renderable *shadow_caster = get_item(renderables, l.shadow_caster_name); + if(!l.light || !shadow_caster) + throw invalid_operation("ShadowMap::Template::create"); + if(const DirectionalLight *dir_light = dynamic_cast(l.light)) + shadow_map->add_light(*dir_light, l.size, *shadow_caster); + else if(const PointLight *point_light = dynamic_cast(l.light)) + shadow_map->add_light(*point_light, l.size, *shadow_caster); + else + throw invalid_operation("ShadowMap::Template::create"); + } + + return shadow_map.release(); +} + + +DataFile::Loader::ActionMap ShadowMap::Template::Loader::shared_actions; + +ShadowMap::Template::Loader::Loader(Template &t, Collection &c): + DerivedObjectLoader(t, c) +{ + set_actions(shared_actions); +} + +void ShadowMap::Template::Loader::init_actions() +{ + Effect::Template::Loader::init_actions(); + add("darkness", &Template::darkness); + add("depth_bias", &Template::depth_bias); + add("light", &Loader::light); + add("lighting", &Template::lighting); + add("radius", &Template::radius); + add("size", &Loader::size_square); + add("size", &Template::width, &Template::height); + add("target", &Loader::target); +} + +void ShadowMap::Template::Loader::light(const string &name) +{ + ShadowedLight light; + light.light = &get_collection().get(name); + load_sub(light); + obj.lights.push_back(light); +} + +void ShadowMap::Template::Loader::size_square(unsigned s) +{ + obj.width = s; + obj.height = s; +} + +void ShadowMap::Template::Loader::target(float x, float y, float z) +{ + obj.target = Vector3(x, y, z); +} + + +DataFile::Loader::ActionMap ShadowMap::Template::ShadowedLight::Loader::shared_actions; + +ShadowMap::Template::ShadowedLight::Loader::Loader(ShadowedLight &l): + ObjectLoader(l) +{ + set_actions(shared_actions); +} + +void ShadowMap::Template::ShadowedLight::Loader::init_actions() +{ + add("size", &ShadowedLight::size); + add("shadow_caster", &ShadowedLight::shadow_caster_name); +} + } // namespace GL } // namespace Msp