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