]> git.tdb.fi Git - libs/gl.git/blob - source/materials/renderpass.h
Convert Technique and RenderPass loaders to use shared actions
[libs/gl.git] / source / materials / 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 "material.h"
7
8 namespace Msp {
9 namespace GL {
10
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         private:
28                 static ActionMap shared_actions;
29
30         public:
31                 Loader(RenderPass &);
32                 Loader(RenderPass &, Collection &);
33
34         private:
35                 virtual void init_actions();
36
37                 static std::string get_shader_name(const std::string &);
38
39                 void material_inline();
40                 void material(const std::string &);
41                 void shader(const std::string &);
42                 void texture(const std::string &);
43                 void texunit(unsigned);
44                 void texunit_named(unsigned, const std::string &);
45                 void uniforms();
46                 void uniform_slot(const std::string &);
47                 void uniform_slot2(const std::string &, const std::string &);
48         };
49
50 private:
51         struct TextureSlot
52         {
53                 class Loader: public DataFile::CollectionObjectLoader<TextureSlot>
54                 {
55                 private:
56                         std::string auto_slot_name;
57
58                 public:
59                         Loader(TextureSlot &, const std::string &, Collection *);
60
61                 private:
62                         void slot_auto();
63                 };
64
65                 Tag tag;
66                 std::string slot_name;
67                 const Texture *texture;
68                 const Sampler *sampler;
69
70                 TextureSlot(Tag t): tag(t), texture(0), sampler(0) { }
71         };
72
73         RefPtr<const Program> shprog;
74         bool shprog_from_material;
75         RefPtr<ProgramData> shdata;
76         std::map<Tag, Tag> uniform_slots;
77         RefPtr<const Material> material;
78         std::string material_slot;
79         std::vector<TextureSlot> textures;
80         bool back_faces;
81
82 public:
83         RenderPass();
84
85 private:
86         void finalize_material(DataFile::Collection *);
87         void maybe_create_material_shader(DataFile::Collection *);
88         void ensure_private_shader_data();
89
90 public:
91         void set_shader_program(const Program *, const ProgramData *);
92         const Program *get_shader_program() const { return shprog.get(); }
93         const ProgramData *get_shader_data() const { return shdata.get(); }
94         Tag get_slotted_uniform_tag(Tag) const;
95         void set_material(const Material *, DataFile::Collection * = 0);
96         const Material *get_material() const { return material.get(); }
97         const std::string &get_material_slot_name() const { return material_slot; }
98         void set_texture(Tag, const Texture *, const Sampler * = 0);
99         Tag get_texture_tag(const std::string &) const;
100         DEPRECATED void set_texture(unsigned, const Texture *, const Sampler * = 0);
101         DEPRECATED const Texturing *get_texturing() const { return 0; }
102         DEPRECATED int get_texture_index(const std::string &) const;
103         void set_back_faces(bool);
104         bool get_back_faces() const { return back_faces; }
105
106         void apply(Renderer &) const;
107 };
108
109 } // namespace GL
110 } // namespace Msp
111
112 #endif