]> git.tdb.fi Git - libs/vr.git/blob - source/stereoview.h
Fix memory leaks
[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                 ~Eye();
46
47                 void create_target(unsigned, unsigned);
48                 void setup_frame(const GL::Camera &, float, const EyeParams &) const;
49                 void render(const GL::Renderable &) const;
50         };
51
52         const StereoCombiner &combiner;
53         const GL::Camera &base_camera;
54         HeadTrackingCamera *head_camera;
55         const GL::Renderable *content;
56         Eye left;
57         Eye right;
58         Geometry::Angle<float> strabismus;
59         std::vector<MotionController *> controllers;
60
61 public:
62         StereoView(const StereoCombiner &, const GL::Camera &);
63         StereoView(const StereoCombiner &, HeadTrackingCamera &);
64 private:
65         void init();
66
67 public:
68         const GL::Camera &get_base_camera() const { return base_camera; }
69         const HeadTrackingCamera *get_head_camera() const { return head_camera; }
70         void set_content(const GL::Renderable *);
71         void set_eye_spacing(float);
72         void set_eye_matrices(const GL::Matrix &, const GL::Matrix &);
73         void set_strabismus(const Geometry::Angle<float> &);
74
75         void add_controller(MotionController &);
76         void remove_controller(MotionController &);
77
78 private:
79         void setup_frame() const;
80 public:
81         void render() const;
82 };
83
84 } // namespace VR
85 } // namespace Msp
86
87 #endif