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