]> git.tdb.fi Git - libs/vr.git/blob - source/openvr/openvrsystem.h
Fix memory leaks
[libs/vr.git] / source / openvr / openvrsystem.h
1 #ifndef MSP_VR_OPENVRSYSTEM_H_
2 #define MSP_VR_OPENVRSYSTEM_H_
3
4 #include <msp/gl/material.h>
5 #include <msp/gl/matrix.h>
6 #include <msp/gl/object.h>
7 #include <msp/gl/technique.h>
8 #include <msp/vr/system.h>
9 #include "openvrcamera.h"
10 #include "openvrcombiner.h"
11 #include "openvrcontroller.h"
12
13 namespace Msp {
14 namespace VR {
15
16 class OpenVRSystem: public System
17 {
18 private:
19         struct RenderModel;
20
21         unsigned n_tracked_devices;
22         std::vector<GL::Matrix> tracking_matrices;
23         std::vector<OpenVRController *> controllers;
24         std::vector<unsigned> unclaimed_controllers;
25
26         GL::Program render_shprog;
27         GL::Program render_shprog_textured;
28         GL::Material render_material;
29         std::map<std::string, RenderModel *> render_models;
30         std::map<unsigned, GL::Texture2D *> render_textures;
31         std::list<std::string> loading_render_models;
32         std::list<unsigned> loading_textures;
33
34         static unsigned n_instances;
35
36 public:
37         OpenVRSystem();
38         ~OpenVRSystem();
39
40         static bool is_maybe_available();
41
42         virtual void configure_window(Graphics::Window &) const { }
43         virtual void configure_view(StereoView &) const;
44         virtual bool is_absolute_tracking_supported() const { return true; }
45         virtual void set_absolute_tracking(bool);
46         virtual bool get_absolute_tracking() const;
47         virtual OpenVRCamera *create_camera(const GL::Camera &);
48         virtual OpenVRCombiner *create_combiner(GL::View &);
49         virtual OpenVRController *create_controller();
50
51         virtual void tick();
52
53         void update_pose_matrices();
54         const GL::Matrix &get_tracking_matrix(unsigned) const;
55         const GL::Matrix &get_hmd_matrix() const;
56         void add_controller(OpenVRController &);
57         void remove_controller(OpenVRController &);
58
59         const GL::Object *get_render_model(const std::string &);
60 private:
61         bool check_loading_render_model(const std::string &);
62         const GL::Texture2D *get_texture(unsigned);
63         bool check_loading_texture(unsigned);
64 };
65
66 } // namespace VR
67 } // namespace Msp
68
69 #endif