]> git.tdb.fi Git - libs/vr.git/blob - source/stereoview.h
e31fa3d561b9adaa51f81a916b30d5c66f3483e5
[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 HeadTrackingCamera;
15 class MotionController;
16 class StereoCombiner;
17
18 class StereoView
19 {
20 private:
21         struct RenderTarget
22         {
23                 GL::Framebuffer fbo;
24                 GL::Texture2D color;
25                 GL::Renderbuffer depth;
26
27                 RenderTarget(unsigned, unsigned);
28         };
29
30         struct EyeParams
31         {
32                 Geometry::Angle<float> fov;
33                 float aspect;
34                 float near_clip;
35                 float far_clip;
36         };
37
38         struct Eye
39         {
40                 mutable GL::Camera camera;
41                 GL::Matrix offset_matrix;
42                 RenderTarget *target;
43
44                 Eye();
45
46                 void create_target(unsigned, unsigned);
47                 void setup_frame(const GL::Camera &, float, const EyeParams &) const;
48                 void render(const GL::Renderable &) const;
49         };
50
51         const StereoCombiner &combiner;
52         const GL::Camera &base_camera;
53         HeadTrackingCamera *head_camera;
54         const GL::Renderable *content;
55         Eye left;
56         Eye right;
57         Geometry::Angle<float> strabismus;
58         std::vector<MotionController *> controllers;
59
60 public:
61         StereoView(const StereoCombiner &, const GL::Camera &);
62         StereoView(const StereoCombiner &, HeadTrackingCamera &);
63 private:
64         void init();
65
66 public:
67         const GL::Camera &get_base_camera() const { return base_camera; }
68         const HeadTrackingCamera *get_head_camera() const { return head_camera; }
69         void set_content(const GL::Renderable *);
70         void set_eye_spacing(float);
71         void set_eye_matrices(const GL::Matrix &, const GL::Matrix &);
72         void set_strabismus(const Geometry::Angle<float> &);
73
74         void add_controller(MotionController &);
75         void remove_controller(MotionController &);
76
77 private:
78         void setup_frame() const;
79 public:
80         void render() const;
81 };
82
83 } // namespace VR
84 } // namespace Msp
85
86 #endif