]> git.tdb.fi Git - libs/gl.git/blob - source/effects/environmentmap.h
Access builtin resources through a global instance
[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 /**
17 Creates a cube map texture of the surroundings of the renderable.  This texture
18 can then be used to implement effects such as reflections or refractions.
19
20 If the EnvironmentMap is used in a Sequence, it's worth noting that the cube
21 map will be prepared outside of any rendering pass.  It's recommended to use
22 another Sequence to define which passes should be used to render the
23 environment.
24 */
25 class EnvironmentMap: public Effect
26 {
27 private:
28         struct Face
29         {
30                 Framebuffer fbo;
31                 Camera camera;
32         };
33
34         unsigned size;
35         Renderable &environment;
36         TextureCube env_tex;
37         Renderbuffer depth_buf;
38         Face faces[6];
39         const Sampler &sampler;
40         ProgramData shdata;
41         bool rendered;
42         unsigned update_interval;
43         unsigned update_delay;
44
45 public:
46         EnvironmentMap(unsigned size, Renderable &rend, Renderable &env);
47         EnvironmentMap(unsigned size, PixelFormat, Renderable &rend, Renderable &env);
48 private:
49         void init(unsigned, PixelFormat);
50
51 public:
52         void set_depth_clip(float, float);
53
54         /** Sets the interval in frames between environment map updates.  A value of
55         0 means an update is only done when manually requested. */
56         void set_update_interval(unsigned);
57
58         /** Request that the environment map is updated on the next frame. */
59         void queue_update();
60
61         virtual void setup_frame(Renderer &);
62         virtual void finish_frame();
63
64         virtual void render(Renderer &, Tag = Tag()) const;
65 };
66
67 } // namespace GL
68 } // namespace Msp
69
70 #endif