]> git.tdb.fi Git - libs/gl.git/blob - source/technique.h
Inherit Loaders from the ObjectLoader classes
[libs/gl.git] / source / technique.h
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 #ifndef TECHNIQUE_H_
9 #define TECHNIQUE_H_
10
11 #include "objectpass.h"
12
13 namespace Msp {
14 namespace GL {
15
16 class Material;
17 class Tag;
18 class Texture;
19
20 /**
21 Stores a complete multipass rendering technique for an Object.  This includes
22 shaders, textures and a material.  A Technique can also specify empty texture
23 slots which Objects must override.
24 */
25 class Technique
26 {
27 public:
28         class Loader: public Msp::DataFile::CollectionObjectLoader<Technique>
29         {
30         public:
31                 Loader(Technique &, Collection &);
32
33         private:
34                 virtual void finish();
35                 void material_inline();
36                 void pass(const std::string &);
37                 void shader(const std::string &);
38                 void shader_texture(const std::string &);
39                 void texture(const std::string &);
40                 void texture_slot(const std::string &);
41         };
42
43 private:
44         struct TextureSlot
45         {
46                 std::string name;
47                 const Texture *texture;
48
49                 TextureSlot(): texture(0) { }
50         };
51
52         typedef std::map<Tag, ObjectPass> PassMap;
53
54         std::vector<TextureSlot> textures;
55         const Texture *main_texture;
56         PassMap passes;
57         ObjectPass *normal_pass;
58         const Material *material;
59
60 public:
61         Technique();
62         ~Technique();
63
64         bool has_pass(const GL::Tag &) const;
65         const ObjectPass &get_pass(const GL::Tag &) const;
66         unsigned get_n_textures() const { return textures.size(); }
67         unsigned get_texture_index(const std::string &) const;
68         const Texture *get_texture(unsigned) const;
69         const Texture *get_main_texture() const { return main_texture; }
70         const Material *get_material() const { return material; }
71 };
72
73 } // namespace GL
74 } // namespace Msp
75
76 #endif