]> git.tdb.fi Git - libs/gl.git/blob - source/effects/environmentmap.h
4936d162781aac4087fcfdf26eb318abdac69ec5
[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 Mesh;
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
42         TextureCube irradiance;
43         const Program &irradiance_shprog;
44         Framebuffer irradiance_fbo;
45         const Program &specular_shprog;
46         std::vector<Framebuffer> specular_fbos;
47         ProgramData prefilter_shdata;
48         const Mesh &fullscreen_mesh;
49
50         const Sampler &sampler;
51         const Sampler &mip_sampler;
52         ProgramData shdata;
53         bool rendered;
54         unsigned update_interval;
55         unsigned update_delay;
56
57 public:
58         EnvironmentMap(unsigned size, Renderable &rend, Renderable &env);
59         EnvironmentMap(unsigned size, PixelFormat, Renderable &rend, Renderable &env);
60         EnvironmentMap(unsigned size, PixelFormat, unsigned, Renderable &rend, Renderable &env);
61 private:
62         void init(unsigned, PixelFormat, unsigned);
63
64 public:
65         void set_depth_clip(float, float);
66
67         /** Sets the interval in frames between environment map updates.  A value of
68         0 means an update is only done when manually requested. */
69         void set_update_interval(unsigned);
70
71         /** Request that the environment map is updated on the next frame. */
72         void queue_update();
73
74         virtual void setup_frame(Renderer &);
75         virtual void finish_frame();
76
77         virtual void render(Renderer &, Tag = Tag()) const;
78
79         virtual void set_debug_name(const std::string &);
80 };
81
82 } // namespace GL
83 } // namespace Msp
84
85 #endif