]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
Bind ProgramData to a Program upon construction
[libs/gl.git] / source / renderpass.h
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2007-2008, 2010-2011  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GL_RENDERPASS_H_
9 #define MSP_GL_RENDERPASS_H_
10
11 #include <msp/core/refptr.h>
12 #include <msp/datafile/objectloader.h>
13 #include "bindable.h"
14
15 namespace Msp {
16 namespace GL {
17
18 class Material;
19 class Program;
20 class ProgramData;
21 class TexEnv;
22 class Texture;
23 class Texturing;
24
25 /**
26 Encapsulates the data that determines the appearance of a rendered surface.
27 This includes shader and data for it, material and texturing.
28
29 XXX Does not delete inline texture from datafiles properly
30 */
31 class RenderPass
32 {
33 public:
34         class Loader: public DataFile::CollectionObjectLoader<RenderPass>
35         {
36         public:
37                 Loader(RenderPass &);
38                 Loader(RenderPass &, Collection &);
39
40         private:
41                 void init();
42                 void material_inline();
43                 void material(const std::string &);
44                 void texunit(unsigned);
45                 void uniforms();
46         };
47
48 private:
49         struct TextureLoader: public DataFile::CollectionObjectLoader<Texturing>
50         {
51         private:
52                 unsigned index;
53                 RefPtr<Texture> tex;
54                 RefPtr<TexEnv> env;
55
56         public:
57                 TextureLoader(Texturing &, unsigned, Collection *);
58         private:
59                 virtual void finish();
60
61                 void texenv();
62                 void texture(const std::string &);
63                 void texture2d();
64         };
65
66         Program *shprog;
67         ProgramData *shdata;
68         RefPtr<const Material> material;
69         Texturing *texturing;
70
71         RenderPass &operator=(const RenderPass &);
72 public:
73         RenderPass();
74         RenderPass(const RenderPass &);
75         ~RenderPass();
76
77         const Program *get_shader_program() const { return shprog; }
78         const ProgramData *get_shader_data() const { return shdata; }
79         void set_material(const Material *);
80         const Material *get_material() const { return material.get(); }
81         void set_texture(unsigned, const Texture *);
82         const Texturing *get_texturing() const { return texturing; }
83 };
84
85 } // namespace GL
86 } // namespace Msp
87
88 #endif