3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/core/refptr.h>
9 #include <msp/datafile/collection.h>
10 #include <msp/strings/formatter.h>
13 #include "programdata.h"
15 #include "technique.h"
23 RenderPass &Technique::add_pass(const GL::Tag &tag)
26 throw KeyError("Duplicate pass");
31 bool Technique::has_pass(const GL::Tag &tag) const
33 return passes.count(tag);
36 const RenderPass &Technique::get_pass(const GL::Tag &tag) const
38 PassMap::const_iterator i = passes.find(tag);
40 throw KeyError("Unknown pass");
45 Technique::Loader::Loader(Technique &t):
46 DataFile::CollectionObjectLoader<Technique>(t, 0)
51 Technique::Loader::Loader(Technique &t, Collection &c):
52 DataFile::CollectionObjectLoader<Technique>(t, &c)
57 void Technique::Loader::init()
59 add("inherit", &Loader::inherit);
60 add("pass", &Loader::pass);
63 void Technique::Loader::inherit(const string &n)
65 obj.passes = get_collection().get<Technique>(n)->get_passes();
66 InheritLoader ldr(obj, get_collection());
70 void Technique::Loader::pass(const string &n)
73 if(obj.passes.count(tag))
74 throw KeyError("Duplicate pass name", n);
78 load_sub(p, get_collection());
81 obj.passes.insert(PassMap::value_type(tag, p));
85 Technique::InheritLoader::InheritLoader(Technique &t, Collection &c):
86 DataFile::CollectionObjectLoader<Technique>(t, &c)
88 add("texture", &InheritLoader::texture);
91 void Technique::InheritLoader::texture(unsigned index, const string &name)
93 Texture *tex = get_collection().get<Texture>(name);
94 for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
98 i->second.set_texture(index, tex);
100 catch(const KeyError &)