]> git.tdb.fi Git - libs/gl.git/blob - source/effects/environmentmap.h
Move lighting calculations to world space
[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         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         EnvironmentMap(Resources &, unsigned size, PixelFormat, Renderable &rend, Renderable &env);
50 private:
51         void init(unsigned, PixelFormat, unsigned);
52
53 public:
54         void set_depth_clip(float, float);
55
56         /** Sets the interval in frames between environment map updates.  A value of
57         0 means an update is only done when manually requested. */
58         void set_update_interval(unsigned);
59
60         /** Request that the environment map is updated on the next frame. */
61         void queue_update();
62
63         virtual void setup_frame(Renderer &);
64         virtual void finish_frame();
65
66         virtual void render(Renderer &, Tag = Tag()) const;
67 };
68
69 } // namespace GL
70 } // namespace Msp
71
72 #endif