]> git.tdb.fi Git - libs/gl.git/blob - source/technique.cpp
Use maputils functions
[libs/gl.git] / source / technique.cpp
1 #include <msp/core/refptr.h>
2 #include <msp/datafile/collection.h>
3 #include <msp/strings/format.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         return insert_unique(passes, tag, RenderPass())->second;
19 }
20
21 bool Technique::has_pass(const GL::Tag &tag) const
22 {
23         return passes.count(tag);
24 }
25
26 const RenderPass &Technique::get_pass(const GL::Tag &tag) const
27 {
28         return get_item(passes, tag);
29 }
30
31
32 Technique::Loader::Loader(Technique &t):
33         DataFile::CollectionObjectLoader<Technique>(t, 0)
34 {
35         init();
36 }
37
38 Technique::Loader::Loader(Technique &t, Collection &c):
39         DataFile::CollectionObjectLoader<Technique>(t, &c)
40 {
41         init();
42 }
43
44 void Technique::Loader::init()
45 {
46         add("inherit", &Loader::inherit);
47         add("pass", &Loader::pass);
48 }
49
50 void Technique::Loader::inherit(const string &n)
51 {
52         obj.passes = get_collection().get<Technique>(n)->get_passes();
53         InheritLoader ldr(obj, get_collection());
54         load_sub_with(ldr);
55 }
56
57 void Technique::Loader::pass(const string &n)
58 {
59         RenderPass p;
60         if(coll)
61                 load_sub(p, get_collection());
62         else
63                 load_sub(p);
64
65         insert_unique(obj.passes, n, p);
66 }
67
68
69 Technique::InheritLoader::InheritLoader(Technique &t, Collection &c):
70         DataFile::CollectionObjectLoader<Technique>(t, &c)
71 {
72         add("texture", &InheritLoader::texture);
73 }
74
75 void Technique::InheritLoader::texture(const std::string &slot, const string &name)
76 {
77         Texture *tex = get_collection().get<Texture>(name);
78         for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
79         {
80                 int index = i->second.get_texture_index(slot);
81                 if(index<0)
82                         continue;
83                 i->second.set_texture(index, tex);
84         }
85 }
86
87 } // namespace GL
88 } // namespace Msp