]> git.tdb.fi Git - libs/gl.git/blob - source/effects/environmentmap.h
Use persistent cameras in effects
[libs/gl.git] / source / effects / environmentmap.h
1 #ifndef MSP_GL_ENVIRONMENTMAP_H_
2 #define MSP_GL_ENVIRONMENTMAP_H_
3
4 #include "camera.h"
5 #include "effect.h"
6 #include "framebuffer.h"
7 #include "matrix.h"
8 #include "programdata.h"
9 #include "renderbuffer.h"
10 #include "texturecube.h"
11 #include "vector.h"
12
13 namespace Msp {
14 namespace GL {
15
16 class Resources;
17
18 /**
19 Creates a cube map texture of the surroundings of the renderable.  This texture
20 can then be used to implement effects such as reflections or refractions.
21
22 If the EnvironmentMap is used in a Sequence, it's worth noting that the cube
23 map will be prepared outside of any rendering pass.  It's recommended to use
24 another Sequence to define which passes should be used to render the
25 environment.
26 */
27 class EnvironmentMap: public Effect
28 {
29 private:
30         struct Face
31         {
32                 Framebuffer fbo;
33                 Camera camera;
34         };
35
36         unsigned size;
37         Renderable &environment;
38         TextureCube env_tex;
39         Renderbuffer depth_buf;
40         Face faces[6];
41         const Sampler &sampler;
42         mutable ProgramData shdata;
43         bool rendered;
44         unsigned update_interval;
45         unsigned update_delay;
46
47 public:
48         EnvironmentMap(Resources &, unsigned size, Renderable &rend, Renderable &env);
49
50         void set_depth_clip(float, float);
51         void set_update_interval(unsigned);
52         void queue_update();
53
54         virtual void setup_frame(Renderer &);
55         virtual void finish_frame();
56
57         virtual void render(Renderer &, Tag = Tag()) const;
58 };
59
60 } // namespace GL
61 } // namespace Msp
62
63 #endif