]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
Rework Bind and enable it to restore the old binding
[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 #include "bindable.h"
13
14 namespace Msp {
15 namespace GL {
16
17 class Material;
18 class Program;
19 class ProgramData;
20 class Texture;
21
22 /**
23 Encapsulates the data that determines the appearance of a rendered surface.
24 This includes shader and data for it, material and textures.
25 */
26 class RenderPass: public Bindable<RenderPass>
27 {
28 public:
29         class Loader: public DataFile::CollectionObjectLoader<RenderPass>
30         {
31         public:
32                 Loader(RenderPass &);
33                 Loader(RenderPass &, Collection &);
34
35         private:
36                 void init();
37                 virtual void finish();
38                 void material();
39                 void shader(const std::string &);
40                 void texture(const std::string &);
41                 void uniforms();
42         };
43
44 private:
45         struct TextureSlot
46         {
47                 class Loader: public DataFile::ObjectLoader<TextureSlot>
48                 {
49                 public:
50                         Loader(TextureSlot &);
51                 };
52
53                 const Texture *texture;
54                 std::string name;
55
56                 TextureSlot(const Texture *);
57         };
58
59         Program *shprog;
60         ProgramData *shdata;
61         bool own_material;
62         const Material *material;
63         std::vector<TextureSlot> textures;
64
65         RenderPass &operator=(const RenderPass &);
66 public:
67         RenderPass();
68         RenderPass(const RenderPass &);
69         ~RenderPass();
70
71         void set_material(const Material *);
72         unsigned get_texture_index(const std::string &) const;
73         void set_texture(const std::string &, const Texture *);
74
75         void bind() const;
76
77         static void unbind();
78 };
79
80 } // namespace GL
81 } // namespace Msp
82
83 #endif