]> git.tdb.fi Git - libs/gl.git/blob - source/materials/renderpass.h
Add sampler parameter to RenderPass::set_texture
[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
7 namespace Msp {
8 namespace GL {
9
10 class Material;
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         public:
28                 Loader(RenderPass &);
29                 Loader(RenderPass &, Collection &);
30
31         private:
32                 void init();
33
34                 static std::string get_shader_name(const std::string &);
35
36                 void material_inline();
37                 void material(const std::string &);
38                 void shader(const std::string &);
39                 void texunit(unsigned);
40                 void texunit_auto(const std::string &);
41                 void texunit_named(unsigned, const std::string &);
42                 void uniforms();
43                 void uniform_slot(const std::string &);
44                 void uniform_slot2(const std::string &, const std::string &);
45         };
46
47 private:
48         struct TextureLoader: public DataFile::CollectionObjectLoader<Texturing>
49         {
50         private:
51                 unsigned index;
52                 const Texture *tex;
53                 const Sampler *samp;
54
55         public:
56                 TextureLoader(Texturing &, unsigned, Collection *);
57         private:
58                 virtual void finish();
59
60                 void sampler(const std::string &);
61                 void texture(const std::string &);
62         };
63
64         RefPtr<const Program> shprog;
65         bool shprog_from_material;
66         RefPtr<ProgramData> shdata;
67         std::map<std::string, std::string> uniform_slots;
68         RefPtr<const Material> material;
69         std::string material_slot;
70         Texturing *texturing;
71         std::map<std::string, unsigned> tex_names;
72         bool back_faces;
73
74 public:
75         RenderPass();
76         RenderPass(const RenderPass &);
77         RenderPass &operator=(const RenderPass &);
78         ~RenderPass();
79
80 private:
81         void finalize_material(DataFile::Collection *);
82         void maybe_create_material_shader(DataFile::Collection *);
83         void ensure_private_shader_data();
84
85 public:
86         void set_shader_program(const Program *, const ProgramData *);
87         const Program *get_shader_program() const { return shprog.get(); }
88         const ProgramData *get_shader_data() const { return shdata.get(); }
89         const std::string &get_slotted_uniform_name(const std::string &) const;
90         void set_material(const Material *);
91         const Material *get_material() const { return material.get(); }
92         const std::string &get_material_slot_name() const { return material_slot; }
93         void set_texture(unsigned, const Texture *, const Sampler * = 0);
94         const Texturing *get_texturing() const { return texturing; }
95         int get_texture_index(const std::string &) const;
96         void set_back_faces(bool);
97         bool get_back_faces() const { return back_faces; }
98
99         void apply(Renderer &) const;
100 };
101
102 } // namespace GL
103 } // namespace Msp
104
105 #endif