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