]> git.tdb.fi Git - libs/gl.git/blob - source/technique.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / technique.cpp
1 #include <msp/core/refptr.h>
2 #include <msp/datafile/collection.h>
3 #include <msp/strings/formatter.h>
4 #include "material.h"
5 #include "program.h"
6 #include "programdata.h"
7 #include "tag.h"
8 #include "technique.h"
9 #include "texture.h"
10
11 using namespace std;
12
13 namespace Msp {
14 namespace GL {
15
16 RenderPass &Technique::add_pass(const GL::Tag &tag)
17 {
18         if(passes.count(tag))
19                 throw KeyError("Duplicate pass");
20
21         return passes[tag];
22 }
23
24 bool Technique::has_pass(const GL::Tag &tag) const
25 {
26         return passes.count(tag);
27 }
28
29 const RenderPass &Technique::get_pass(const GL::Tag &tag) const
30 {
31         PassMap::const_iterator i = passes.find(tag);
32         if(i==passes.end())
33                 throw KeyError("Unknown pass");
34         return i->second;
35 }
36
37
38 Technique::Loader::Loader(Technique &t):
39         DataFile::CollectionObjectLoader<Technique>(t, 0)
40 {
41         init();
42 }
43
44 Technique::Loader::Loader(Technique &t, Collection &c):
45         DataFile::CollectionObjectLoader<Technique>(t, &c)
46 {
47         init();
48 }
49
50 void Technique::Loader::init()
51 {
52         add("inherit", &Loader::inherit);
53         add("pass", &Loader::pass);
54 }
55
56 void Technique::Loader::inherit(const string &n)
57 {
58         obj.passes = get_collection().get<Technique>(n)->get_passes();
59         InheritLoader ldr(obj, get_collection());
60         load_sub_with(ldr);
61 }
62
63 void Technique::Loader::pass(const string &n)
64 {
65         Tag tag(n);
66         if(obj.passes.count(tag))
67                 throw KeyError("Duplicate pass name", n);
68
69         RenderPass p;
70         if(coll)
71                 load_sub(p, get_collection());
72         else
73                 load_sub(p);
74         obj.passes.insert(PassMap::value_type(tag, p));
75 }
76
77
78 Technique::InheritLoader::InheritLoader(Technique &t, Collection &c):
79         DataFile::CollectionObjectLoader<Technique>(t, &c)
80 {
81         add("texture", &InheritLoader::texture);
82 }
83
84 void Technique::InheritLoader::texture(const std::string &slot, const string &name)
85 {
86         Texture *tex = get_collection().get<Texture>(name);
87         for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
88         {
89                 int index = i->second.get_texture_index(slot);
90                 if(index<0)
91                         continue;
92                 i->second.set_texture(index, tex);
93         }
94 }
95
96 } // namespace GL
97 } // namespace Msp