]> git.tdb.fi Git - libs/vr.git/blob - source/stereoview.h
Add classes for stereographic rendering
[libs/vr.git] / source / stereoview.h
1 #ifndef MSP_GL_STEREOVIEW_H_
2 #define MSP_GL_STEREOVIEW_H_
3
4 #include "camera.h"
5 #include "framebuffer.h"
6 #include "renderable.h"
7 #include "renderbuffer.h"
8 #include "texture2d.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class StereoCombiner;
14
15 class StereoView: public Renderable
16 {
17 private:
18         struct RenderTarget
19         {
20                 Framebuffer fbo;
21                 Texture2D color;
22                 Renderbuffer depth;
23
24                 RenderTarget(unsigned, unsigned);
25         };
26
27         struct EyeParams
28         {
29                 float fov;
30                 float aspect;
31                 float near_clip;
32                 float far_clip;
33         };
34
35         struct Eye
36         {
37                 mutable Camera camera;
38                 RenderTarget *target;
39
40                 Eye();
41
42                 void create_target(unsigned, unsigned);
43                 void setup_frame(const Camera &, const Vector3 &, const EyeParams &) const;
44                 void render(const Renderable &, const Tag &) const;
45         };
46
47         unsigned width;
48         unsigned height;
49         const Camera &base_camera;
50         const Renderable &renderable;
51         const StereoCombiner *combiner;
52         Eye left;
53         Eye right;
54         float eye_spacing;
55         mutable Vector3 offset_axis;
56
57 public:
58         StereoView(unsigned, unsigned, const Camera &, const Renderable &, const StereoCombiner &);
59
60         void set_combiner(const StereoCombiner &);
61         void set_eye_spacing(float);
62
63         virtual void setup_frame() const;
64         virtual void finish_frame() const;
65
66         virtual void render(const Tag & = Tag()) const;
67         virtual void render(Renderer &, const Tag & = Tag()) const;
68 };
69
70 } // namespace GL
71 } // namespace Msp
72
73 #endif