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