]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
Remove the deprecated ProgramBuilder class
[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
7 namespace Msp {
8 namespace GL {
9
10 class Material;
11 class Program;
12 class ProgramData;
13 class Renderer;
14 class Sampler;
15 class Texture;
16 class Texturing;
17
18 /**
19 Encapsulates the data that determines the appearance of a rendered surface.
20 This includes shader and data for it, material and texturing.
21 */
22 class RenderPass
23 {
24 public:
25         class Loader: public DataFile::CollectionObjectLoader<RenderPass>
26         {
27         public:
28                 Loader(RenderPass &);
29                 Loader(RenderPass &, Collection &);
30
31         private:
32                 void init();
33
34                 void material_inline();
35                 void material(const std::string &);
36                 void shader(const std::string &);
37                 void texunit(unsigned);
38                 void texunit_auto(const std::string &);
39                 void texunit_named(unsigned, const std::string &);
40                 void uniforms();
41                 void uniform_slot(const std::string &);
42                 void uniform_slot2(const std::string &, const std::string &);
43         };
44
45 private:
46         struct TextureLoader: public DataFile::CollectionObjectLoader<Texturing>
47         {
48         private:
49                 unsigned index;
50                 const Texture *tex;
51                 const Sampler *samp;
52
53         public:
54                 TextureLoader(Texturing &, unsigned, Collection *);
55         private:
56                 virtual void finish();
57
58                 void sampler(const std::string &);
59                 void texture(const std::string &);
60         };
61
62         RefPtr<const Program> shprog;
63         bool shprog_from_material;
64         RefPtr<ProgramData> shdata;
65         std::map<std::string, std::string> uniform_slots;
66         RefPtr<const Material> material;
67         std::string material_slot;
68         Texturing *texturing;
69         std::map<std::string, unsigned> tex_names;
70         bool back_faces;
71
72 public:
73         RenderPass();
74         RenderPass(const RenderPass &);
75         RenderPass &operator=(const RenderPass &);
76         ~RenderPass();
77
78 private:
79         void finalize_material(DataFile::Collection *);
80         void maybe_create_material_shader(DataFile::Collection *);
81         void ensure_private_shader_data();
82
83 public:
84         void set_shader_program(const Program *, const ProgramData *);
85         const Program *get_shader_program() const { return shprog.get(); }
86         const ProgramData *get_shader_data() const { return shdata.get(); }
87         const std::string &get_slotted_uniform_name(const std::string &) const;
88         void set_material(const Material *);
89         const Material *get_material() const { return material.get(); }
90         const std::string &get_material_slot_name() const { return material_slot; }
91         void set_texture(unsigned, const Texture *);
92         const Texturing *get_texturing() const { return texturing; }
93         int get_texture_index(const std::string &) const;
94         void set_back_faces(bool);
95         bool get_back_faces() const { return back_faces; }
96
97         void apply(Renderer &) const;
98 };
99
100 } // namespace GL
101 } // namespace Msp
102
103 #endif