]> git.tdb.fi Git - libs/gl.git/blob - source/renderpass.h
c201eb07c807564a58c1edaa8446d0e83af2e9f6
[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 texunit_named(unsigned, const std::string &);
46                 void uniforms();
47         };
48
49 private:
50         struct TextureLoader: public DataFile::CollectionObjectLoader<Texturing>
51         {
52         private:
53                 unsigned index;
54                 RefPtr<Texture> tex;
55                 RefPtr<TexEnv> env;
56
57         public:
58                 TextureLoader(Texturing &, unsigned, Collection *);
59         private:
60                 virtual void finish();
61
62                 void texenv();
63                 void texture(const std::string &);
64                 void texture2d();
65         };
66
67         Program *shprog;
68         ProgramData *shdata;
69         RefPtr<const Material> material;
70         Texturing *texturing;
71         std::map<std::string, unsigned> tex_names;
72
73         RenderPass &operator=(const RenderPass &);
74 public:
75         RenderPass();
76         RenderPass(const RenderPass &);
77         ~RenderPass();
78
79         const Program *get_shader_program() const { return shprog; }
80         const ProgramData *get_shader_data() const { return shdata; }
81         void set_material(const Material *);
82         const Material *get_material() const { return material.get(); }
83         void set_texture(unsigned, const Texture *);
84         const Texturing *get_texturing() const { return texturing; }
85         int get_texture_index(const std::string &) const;
86 };
87
88 } // namespace GL
89 } // namespace Msp
90
91 #endif