1 #include <msp/core/refptr.h>
2 #include <msp/datafile/collection.h>
3 #include <msp/strings/format.h>
6 #include "programdata.h"
16 RenderPass &Technique::add_pass(const GL::Tag &tag)
18 return insert_unique(passes, tag, RenderPass())->second;
21 bool Technique::has_pass(const GL::Tag &tag) const
23 return passes.count(tag);
26 const RenderPass &Technique::get_pass(const GL::Tag &tag) const
28 return get_item(passes, tag);
31 void Technique::replace_texture(const string &slot, const Texture &tex)
33 for(PassMap::iterator i=passes.begin(); i!=passes.end(); ++i)
35 int index = i->second.get_texture_index(slot);
38 i->second.set_texture(index, &tex);
42 bool Technique::has_shaders() const
44 for(PassMap::const_iterator i=passes.begin(); i!=passes.end(); ++i)
45 if(i->second.get_shader_program())
51 Technique::Loader::Loader(Technique &t):
52 DataFile::CollectionObjectLoader<Technique>(t, 0)
57 Technique::Loader::Loader(Technique &t, Collection &c):
58 DataFile::CollectionObjectLoader<Technique>(t, &c)
63 void Technique::Loader::init()
65 add("inherit", &Loader::inherit);
66 add("pass", &Loader::pass);
69 void Technique::Loader::inherit(const string &n)
71 obj.passes = get_collection().get<Technique>(n).get_passes();
72 InheritLoader ldr(obj, get_collection());
76 void Technique::Loader::pass(const string &n)
80 load_sub(p, get_collection());
84 insert_unique(obj.passes, n, p);
88 Technique::InheritLoader::InheritLoader(Technique &t, Collection &c):
89 DataFile::CollectionObjectLoader<Technique>(t, &c)
91 add("material", &InheritLoader::material);
92 add("texture", &InheritLoader::texture);
95 void Technique::InheritLoader::material(const string &pass_tag, const string &name)
97 RenderPass &pass = get_item(obj.passes, pass_tag);
98 const Material &mat = get_collection().get<Material>(name);
99 if(const Material *base_mat = pass.get_material())
101 for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
102 if(i->second.get_material()==base_mat)
103 i->second.set_material(&mat);
106 pass.set_material(&mat);
109 void Technique::InheritLoader::texture(const string &slot, const string &name)
111 obj.replace_texture(slot, get_collection().get<Texture>(name));