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 bool Technique::has_pass(const GL::Tag &tag) const
25 return passes.count(tag);
28 const RenderPass &Technique::get_pass(const GL::Tag &tag) const
30 PassMap::const_iterator i = passes.find(tag);
32 throw KeyError("Unknown pass");
37 Technique::Loader::Loader(Technique &t):
38 DataFile::CollectionObjectLoader<Technique>(t, 0)
43 Technique::Loader::Loader(Technique &t, Collection &c):
44 DataFile::CollectionObjectLoader<Technique>(t, &c)
49 void Technique::Loader::init()
51 add("inherit", &Loader::inherit);
52 add("pass", &Loader::pass);
55 void Technique::Loader::inherit(const string &n)
57 obj.passes = get_collection().get<Technique>(n)->get_passes();
58 InheritLoader ldr(obj, get_collection());
62 void Technique::Loader::pass(const string &n)
65 if(obj.passes.count(tag))
66 throw KeyError("Duplicate pass name", n);
70 load_sub(p, get_collection());
73 obj.passes.insert(PassMap::value_type(tag, p));
77 Technique::InheritLoader::InheritLoader(Technique &t, Collection &c):
78 DataFile::CollectionObjectLoader<Technique>(t, &c)
80 add("texture", &InheritLoader::texture);
83 void Technique::InheritLoader::texture(unsigned index, const string &name)
85 Texture *tex = get_collection().get<Texture>(name);
86 for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
90 i->second.set_texture(index, tex);
92 catch(const KeyError &)