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