]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
Make RenderPass easier to use
[libs/gl.git] / source / renderpass.h
1 #ifndef MSP_GL_RENDERPASS_H_
2 #define MSP_GL_RENDERPASS_H_
3
4 #include <msp/core/refptr.h>
5 #include <msp/datafile/objectloader.h>
6 #include "bindable.h"
7
8 namespace Msp {
9 namespace GL {
10
11 class Material;
12 class Program;
13 class ProgramData;
14 class Renderer;
15 class TexEnv;
16 class Texture;
17 class Texturing;
18
19 /**
20 Encapsulates the data that determines the appearance of a rendered surface.
21 This includes shader and data for it, material and texturing.
22
23 XXX Does not delete inline texture from datafiles properly
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                 void material_inline();
37                 void material(const std::string &);
38                 void texunit(unsigned);
39                 void texunit_named(unsigned, const std::string &);
40                 void uniforms();
41         };
42
43 private:
44         struct TextureLoader: public DataFile::CollectionObjectLoader<Texturing>
45         {
46         private:
47                 unsigned index;
48                 RefPtr<Texture> tex;
49                 RefPtr<TexEnv> env;
50
51         public:
52                 TextureLoader(Texturing &, unsigned, Collection *);
53         private:
54                 virtual void finish();
55
56                 void texenv();
57                 void texture(const std::string &);
58                 void texture2d();
59         };
60
61         const Program *shprog;
62         RefPtr<const ProgramData> shdata;
63         RefPtr<const Material> material;
64         Texturing *texturing;
65         std::map<std::string, unsigned> tex_names;
66
67         RenderPass &operator=(const RenderPass &);
68 public:
69         RenderPass();
70         RenderPass(const RenderPass &);
71         ~RenderPass();
72
73         void set_shader_program(const Program *, const ProgramData *);
74         const Program *get_shader_program() const { return shprog; }
75         const ProgramData *get_shader_data() const { return shdata.get(); }
76         void set_material(const Material *);
77         const Material *get_material() const { return material.get(); }
78         void set_texture(unsigned, const Texture *);
79         const Texturing *get_texturing() const { return texturing; }
80         int get_texture_index(const std::string &) const;
81
82         void apply(Renderer &) const;
83 };
84
85 } // namespace GL
86 } // namespace Msp
87
88 #endif