]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
Allow copying of Uniforms and ProgramData
[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 &, Collection &);
32
33         private:
34                 virtual void finish();
35                 void material();
36                 void shader(const std::string &);
37                 void texture(const std::string &);
38                 void uniforms();
39         };
40
41 private:
42         struct TextureSlot
43         {
44                 class Loader: public DataFile::ObjectLoader<TextureSlot>
45                 {
46                 public:
47                         Loader(TextureSlot &);
48                 };
49
50                 const Texture *texture;
51                 std::string name;
52
53                 TextureSlot(const Texture *);
54         };
55
56         Program *shprog;
57         ProgramData *shdata;
58         bool own_material;
59         const Material *material;
60         std::vector<TextureSlot> textures;
61
62         static const RenderPass *current;
63
64         RenderPass &operator=(const RenderPass &);
65 public:
66         RenderPass();
67         RenderPass(const RenderPass &);
68         ~RenderPass();
69
70         void set_material(const Material *);
71         unsigned get_texture_index(const std::string &) const;
72         void set_texture(const std::string &, const Texture *);
73
74         void bind() const;
75
76         static void unbind();
77 };
78
79 } // namespace GL
80 } // namespace Msp
81
82 #endif