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