]> git.tdb.fi Git - libs/gl.git/blob - source/materials/rendermethod.h
Move blend state from Sequence::Step to RenderMethod
[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 "blend.h"
7 #include "cullface.h"
8 #include "material.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class Program;
14 class ProgramData;
15 class Renderer;
16 class Sampler;
17 class Texture;
18
19 /**
20 Encapsulates the data that determines the appearance of a rendered surface.
21 This includes shader and data for it, material and texturing.
22 */
23 class RenderMethod
24 {
25 public:
26         class Loader: public DataFile::CollectionObjectLoader<RenderMethod>
27         {
28         private:
29                 std::string inline_base_name;
30
31                 static ActionMap shared_actions;
32
33         public:
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 blend();
45                 void blend_factors(BlendFactor, BlendFactor);
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 = 0;
79         bool shprog_from_material = false;
80         RefPtr<ProgramData> shdata;
81         std::map<Tag, Tag> uniform_slots;
82         const Material *material = 0;
83         std::string material_slot;
84         std::vector<TextureSlot> textures;
85         CullMode face_cull = CULL_BACK;
86         Blend blend;
87         bool receive_shadows = false;
88         bool image_based_lighting = false;
89
90         void maybe_create_material_shader();
91         void set_material_textures();
92
93 public:
94         void set_shader_program(const Program *, const ProgramData *);
95         const Program *get_shader_program() const { return shprog; }
96         const ProgramData *get_shader_data() const { return shdata.get(); }
97         Tag get_slotted_uniform_tag(Tag) const;
98         void set_material(const Material *);
99         const Material *get_material() const { return material; }
100         const std::string &get_material_slot_name() const { return material_slot; }
101         void set_texture(Tag, const Texture *, const Sampler * = 0);
102         Tag get_texture_tag(const std::string &) const;
103         void set_face_cull(CullMode);
104         CullMode get_face_cull() const { return face_cull; }
105         void set_blend(const Blend &);
106         const Blend &get_blend() const { return blend; }
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