]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
Support collectionless loading of Technique and RenderPass
[libs/gl.git] / source / renderpass.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007-2008, 2010  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GL_RENDERPASS_H_
9 #define MSP_GL_RENDERPASS_H_
10
11 #include <msp/datafile/objectloader.h>
12
13 namespace Msp {
14 namespace GL {
15
16 class Material;
17 class Program;
18 class ProgramData;
19 class Texture;
20
21 /**
22 Encapsulates the data that determines the appearance of a rendered surface.
23 This includes shader and data for it, material and textures.
24 */
25 class RenderPass
26 {
27 public:
28         class Loader: public DataFile::CollectionObjectLoader<RenderPass>
29         {
30         public:
31                 Loader(RenderPass &);
32                 Loader(RenderPass &, Collection &);
33
34         private:
35                 void init();
36                 virtual void finish();
37                 void material();
38                 void shader(const std::string &);
39                 void texture(const std::string &);
40                 void uniforms();
41         };
42
43 private:
44         struct TextureSlot
45         {
46                 class Loader: public DataFile::ObjectLoader<TextureSlot>
47                 {
48                 public:
49                         Loader(TextureSlot &);
50                 };
51
52                 const Texture *texture;
53                 std::string name;
54
55                 TextureSlot(const Texture *);
56         };
57
58         Program *shprog;
59         ProgramData *shdata;
60         bool own_material;
61         const Material *material;
62         std::vector<TextureSlot> textures;
63
64         static const RenderPass *current;
65
66         RenderPass &operator=(const RenderPass &);
67 public:
68         RenderPass();
69         RenderPass(const RenderPass &);
70         ~RenderPass();
71
72         void set_material(const Material *);
73         unsigned get_texture_index(const std::string &) const;
74         void set_texture(const std::string &, const Texture *);
75
76         void bind() const;
77
78         static void unbind();
79 };
80
81 } // namespace GL
82 } // namespace Msp
83
84 #endif