]> git.tdb.fi Git - libs/gl.git/blob - source/technique.h
Make Tag directly comparable and use it as a key in relevant maps
[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::Loader
29         {
30         public:
31                 typedef DataFile::Collection Collection;
32
33         protected:
34                 Technique &tech;
35                 Collection &coll;
36         
37         public:
38                 Loader(Technique &, Collection &);
39
40                 Technique &get_object() const { return tech; }
41                 Collection &get_collection() const { return coll; }
42         private:
43                 virtual void finish();
44                 void material_inline();
45                 void pass(const std::string &);
46                 void shader(const std::string &);
47                 void shader_texture(const std::string &);
48                 void texture(const std::string &);
49                 void texture_slot(const std::string &);
50         };
51
52 private:
53         struct TextureSlot
54         {
55                 std::string name;
56                 const Texture *texture;
57
58                 TextureSlot(): texture(0) { }
59         };
60
61         typedef std::map<Tag, ObjectPass> PassMap;
62
63         std::vector<TextureSlot> textures;
64         const Texture *main_texture;
65         PassMap passes;
66         ObjectPass *normal_pass;
67         const Material *material;
68
69 public:
70         Technique();
71         ~Technique();
72
73         bool has_pass(const GL::Tag &) const;
74         const ObjectPass &get_pass(const GL::Tag &) const;
75         unsigned get_n_textures() const { return textures.size(); }
76         unsigned get_texture_index(const std::string &) const;
77         const Texture *get_texture(unsigned) const;
78         const Texture *get_main_texture() const { return main_texture; }
79         const Material *get_material() const { return material; }
80 };
81
82 } // namespace GL
83 } // namespace Msp
84
85 #endif