]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
Add a texunit statement which automatically determines the unit number
[libs/gl.git] / source / 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 Texture;
15 class Texturing;
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 XXX Does not delete inline texture from datafiles properly
22 */
23 class RenderPass
24 {
25 public:
26         class Loader: public DataFile::CollectionObjectLoader<RenderPass>
27         {
28         public:
29                 Loader(RenderPass &);
30                 Loader(RenderPass &, Collection &);
31
32         private:
33                 void init();
34
35                 void material_inline();
36                 void material(const std::string &);
37                 void texunit(unsigned);
38                 void texunit_auto(const std::string &);
39                 void texunit_named(unsigned, const std::string &);
40                 void uniforms();
41                 void uniform_slot(const std::string &);
42                 void uniform_slot2(const std::string &, const std::string &);
43         };
44
45 private:
46         struct TextureLoader: public DataFile::CollectionObjectLoader<Texturing>
47         {
48         private:
49                 unsigned index;
50                 RefPtr<Texture> tex;
51
52         public:
53                 TextureLoader(Texturing &, unsigned, Collection *);
54         private:
55                 virtual void finish();
56
57                 void texture(const std::string &);
58                 void texture2d();
59         };
60
61         const Program *shprog;
62         RefPtr<ProgramData> shdata;
63         std::map<std::string, std::string> uniform_slots;
64         RefPtr<const Material> material;
65         std::string material_slot;
66         Texturing *texturing;
67         std::map<std::string, unsigned> tex_names;
68         bool back_faces;
69
70 public:
71         RenderPass();
72         RenderPass(const RenderPass &);
73         RenderPass &operator=(const RenderPass &);
74         ~RenderPass();
75
76 private:
77         void ensure_private_shader_data();
78
79 public:
80         void set_shader_program(const Program *, const ProgramData *);
81         const Program *get_shader_program() const { return shprog; }
82         const ProgramData *get_shader_data() const { return shdata.get(); }
83         const std::string &get_slotted_uniform_name(const std::string &) const;
84         void set_material(const Material *);
85         const Material *get_material() const { return material.get(); }
86         const std::string &get_material_slot_name() const { return material_slot; }
87         void set_texture(unsigned, const Texture *);
88         const Texturing *get_texturing() const { return texturing; }
89         int get_texture_index(const std::string &) const;
90         void set_back_faces(bool);
91         bool get_back_faces() const { return back_faces; }
92
93         void apply(Renderer &) const;
94 };
95
96 } // namespace GL
97 } // namespace Msp
98
99 #endif