1 #include <msp/core/refptr.h>
2 #include <msp/datafile/collection.h>
3 #include <msp/strings/formatter.h>
6 #include "programdata.h"
16 RenderPass &Technique::add_pass(const GL::Tag &tag)
19 throw KeyError("Duplicate pass");
24 bool Technique::has_pass(const GL::Tag &tag) const
26 return passes.count(tag);
29 const RenderPass &Technique::get_pass(const GL::Tag &tag) const
31 PassMap::const_iterator i = passes.find(tag);
33 throw KeyError("Unknown pass");
38 Technique::Loader::Loader(Technique &t):
39 DataFile::CollectionObjectLoader<Technique>(t, 0)
44 Technique::Loader::Loader(Technique &t, Collection &c):
45 DataFile::CollectionObjectLoader<Technique>(t, &c)
50 void Technique::Loader::init()
52 add("inherit", &Loader::inherit);
53 add("pass", &Loader::pass);
56 void Technique::Loader::inherit(const string &n)
58 obj.passes = get_collection().get<Technique>(n)->get_passes();
59 InheritLoader ldr(obj, get_collection());
63 void Technique::Loader::pass(const string &n)
66 if(obj.passes.count(tag))
67 throw KeyError("Duplicate pass name", n);
71 load_sub(p, get_collection());
74 obj.passes.insert(PassMap::value_type(tag, p));
78 Technique::InheritLoader::InheritLoader(Technique &t, Collection &c):
79 DataFile::CollectionObjectLoader<Technique>(t, &c)
81 add("texture", &InheritLoader::texture);
84 void Technique::InheritLoader::texture(const std::string &slot, const string &name)
86 Texture *tex = get_collection().get<Texture>(name);
87 for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
89 int index = i->second.get_texture_index(slot);
92 i->second.set_texture(index, tex);