]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
Cosmetic fixes
[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                 void material_inline();
35                 void material(const std::string &);
36                 void texunit(unsigned);
37                 void texunit_named(unsigned, const std::string &);
38                 void uniforms();
39                 void uniform_slot(const std::string &);
40                 void uniform_slot2(const std::string &, const std::string &);
41         };
42
43 private:
44         struct TextureLoader: public DataFile::CollectionObjectLoader<Texturing>
45         {
46         private:
47                 unsigned index;
48                 RefPtr<Texture> tex;
49
50         public:
51                 TextureLoader(Texturing &, unsigned, Collection *);
52         private:
53                 virtual void finish();
54
55                 void texture(const std::string &);
56                 void texture2d();
57         };
58
59         const Program *shprog;
60         RefPtr<ProgramData> shdata;
61         std::map<std::string, std::string> uniform_slots;
62         RefPtr<const Material> material;
63         std::string material_slot;
64         Texturing *texturing;
65         std::map<std::string, unsigned> tex_names;
66         bool back_faces;
67
68 public:
69         RenderPass();
70         RenderPass(const RenderPass &);
71         RenderPass &operator=(const RenderPass &);
72         ~RenderPass();
73
74         void set_shader_program(const Program *, const ProgramData *);
75         const Program *get_shader_program() const { return shprog; }
76         const ProgramData *get_shader_data() const { return shdata.get(); }
77         const std::string &get_slotted_uniform_name(const std::string &) const;
78         void set_material(const Material *);
79         const Material *get_material() const { return material.get(); }
80         const std::string &get_material_slot_name() const { return material_slot; }
81         void set_texture(unsigned, const Texture *);
82         const Texturing *get_texturing() const { return texturing; }
83         int get_texture_index(const std::string &) const;
84         void set_back_faces(bool);
85         bool get_back_faces() const { return back_faces; }
86
87         void apply(Renderer &) const;
88 };
89
90 } // namespace GL
91 } // namespace Msp
92
93 #endif