]> git.tdb.fi Git - libs/gl.git/blob - source/technique.cpp
Allow copying of Uniforms and ProgramData
[libs/gl.git] / source / technique.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <msp/core/refptr.h>
9 #include <msp/datafile/collection.h>
10 #include <msp/strings/formatter.h>
11 #include "material.h"
12 #include "program.h"
13 #include "programdata.h"
14 #include "tag.h"
15 #include "technique.h"
16 #include "texture.h"
17
18 using namespace std;
19
20 namespace Msp {
21 namespace GL {
22
23 bool Technique::has_pass(const GL::Tag &tag) const
24 {
25         return passes.count(tag);
26 }
27
28 const RenderPass &Technique::get_pass(const GL::Tag &tag) const
29 {
30         PassMap::const_iterator i=passes.find(tag);
31         if(i==passes.end())
32                 throw KeyError("Unknown pass");
33         return i->second;
34 }
35
36
37 Technique::Loader::Loader(Technique &t, Collection &c):
38         DataFile::CollectionObjectLoader<Technique>(t, &c)
39 {
40         add("inherit", &Loader::inherit);
41         add("pass", &Loader::pass);
42 }
43
44 void Technique::Loader::inherit(const string &n)
45 {
46         obj.passes=get_collection().get<Technique>(n)->get_passes();
47         InheritLoader ldr(obj, get_collection());
48         load_sub_with(ldr);
49 }
50
51 void Technique::Loader::pass(const string &n)
52 {
53         Tag tag(n);
54         if(obj.passes.count(tag))
55                 throw KeyError("Duplicate pass name", n);
56
57         RenderPass p;
58         load_sub(p, *coll);
59         obj.passes.insert(PassMap::value_type(tag, p));
60 }
61
62
63 Technique::InheritLoader::InheritLoader(Technique &t, Collection &c):
64         DataFile::CollectionObjectLoader<Technique>(t, &c)
65 {
66         add("texture", &InheritLoader::texture);
67 }
68
69 void Technique::InheritLoader::texture(const string &slot, const string &name)
70 {
71         Texture *tex=get_collection().get<Texture>(name);
72         for(PassMap::iterator i=obj.passes.begin(); i!=obj.passes.end(); ++i)
73         {
74                 try
75                 {
76                         i->second.set_texture(slot, tex);
77                 }
78                 catch(const KeyError &)
79                 { }
80         }
81 }
82
83 } // namespace GL
84 } // namespace Msp