]> git.tdb.fi Git - libs/gl.git/blob - source/materials/renderpass.h
Remove some deprecated stuff that's getting in the way
[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
17 /**
18 Encapsulates the data that determines the appearance of a rendered surface.
19 This includes shader and data for it, material and texturing.
20 */
21 class RenderPass
22 {
23 public:
24         class Loader: public DataFile::CollectionObjectLoader<RenderPass>
25         {
26         private:
27                 std::string inline_base_name;
28
29                 static ActionMap shared_actions;
30
31         public:
32                 Loader(RenderPass &);
33                 Loader(RenderPass &, Collection &);
34         private:
35                 virtual void init_actions();
36         
37         public:
38                 void set_inline_base_name(const std::string &);
39
40         private:
41                 virtual void finish();
42
43                 static std::string get_shader_name(const std::string &);
44
45                 void material_inline();
46                 void material(const std::string &);
47                 void shader(const std::string &);
48                 void texture(const std::string &);
49                 void texunit(unsigned);
50                 void texunit_named(unsigned, const std::string &);
51                 void uniforms();
52                 void uniform_slot(const std::string &);
53                 void uniform_slot2(const std::string &, const std::string &);
54         };
55
56 private:
57         struct TextureSlot
58         {
59                 class Loader: public DataFile::CollectionObjectLoader<TextureSlot>
60                 {
61                 private:
62                         std::string auto_slot_name;
63
64                 public:
65                         Loader(TextureSlot &, const std::string &, Collection *);
66
67                 private:
68                         void slot_auto();
69                 };
70
71                 Tag tag;
72                 std::string slot_name;
73                 const Texture *texture;
74                 const Sampler *sampler;
75
76                 TextureSlot(Tag t): tag(t), texture(0), sampler(0) { }
77         };
78
79         const Program *shprog;
80         bool shprog_from_material;
81         RefPtr<ProgramData> shdata;
82         std::map<Tag, Tag> uniform_slots;
83         const Material *material;
84         std::string material_slot;
85         std::vector<TextureSlot> textures;
86         bool back_faces;
87         bool receive_shadows;
88         bool image_based_lighting;
89
90 public:
91         RenderPass();
92
93 private:
94         void maybe_create_material_shader();
95         void set_material_textures();
96
97 public:
98         void set_shader_program(const Program *, const ProgramData *);
99         const Program *get_shader_program() const { return shprog; }
100         const ProgramData *get_shader_data() const { return shdata.get(); }
101         Tag get_slotted_uniform_tag(Tag) const;
102         void set_material(const Material *);
103         const Material *get_material() const { return material; }
104         const std::string &get_material_slot_name() const { return material_slot; }
105         void set_texture(Tag, const Texture *, const Sampler * = 0);
106         Tag get_texture_tag(const std::string &) const;
107         DEPRECATED void set_texture(unsigned, const Texture *, const Sampler * = 0);
108         DEPRECATED int get_texture_index(const std::string &) const;
109         void set_back_faces(bool);
110         bool get_back_faces() const { return back_faces; }
111         void set_receive_shadows(bool);
112         bool get_receive_shadows() const { return receive_shadows; }
113         void set_image_based_lighting(bool);
114         bool get_image_based_lighting() const { return image_based_lighting; }
115
116         void apply(Renderer &) const;
117
118         void set_debug_name(const std::string &);
119 };
120
121 } // namespace GL
122 } // namespace Msp
123
124 #endif