]> git.tdb.fi Git - libs/vr.git/commitdiff
Add a system creation function with automatic backend detection
authorMikko Rasa <tdb@tdb.fi>
Mon, 3 Oct 2016 14:00:11 +0000 (17:00 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 3 Oct 2016 14:00:11 +0000 (17:00 +0300)
source/openvr/openvrsystem.cpp
source/openvr/openvrsystem.h
source/system.cpp
source/system.h

index e71ba33b45346935d22eb48fc54b22724f4f4888..c137400542448b42fd12b5b7dccf84cef341e46f 100644 (file)
@@ -47,6 +47,11 @@ OpenVRSystem::~OpenVRSystem()
                vr::VR_Shutdown();
 }
 
+bool OpenVRSystem::is_maybe_available()
+{
+       return vr::VR_IsHmdPresent();
+}
+
 void OpenVRSystem::configure_view(StereoView &view) const
 {
        vr::IVRSystem *vr_sys = vr::VRSystem();
index 3e401edb18f3f1e0c8b6ba9b1f4d99c732635440..498865992fdaa8c5a886e3f3e2bb8bdb1d3f128d 100644 (file)
@@ -20,6 +20,8 @@ public:
        OpenVRSystem();
        ~OpenVRSystem();
 
+       static bool is_maybe_available();
+
        virtual void configure_window(Graphics::Window &) const { }
        virtual void configure_view(StereoView &) const;
        virtual void set_absolute_tracking(bool);
index 99a6d4871ece2486b7658eb2c1234d9ecbf6f62c..c8354561489ffba0bf1b1711c7ed38db97264eb8 100644 (file)
@@ -25,5 +25,31 @@ System *System::create(const string &type)
        throw invalid_argument(format("system '%s' not supported", type));
 }
 
+System *System::create_autodetect()
+{
+#ifdef WITH_OPENVR
+       if(OpenVRSystem::is_maybe_available())
+       {
+               try
+               {
+                       return new OpenVRSystem;
+               }
+               catch(const runtime_error &)
+               { }
+       }
+#endif
+
+#ifdef WITH_LIBOVR
+       try
+       {
+               return new LibOVRSystem;
+       }
+       catch(const runtime_error &)
+       { }
+#endif
+
+       return 0;
+}
+
 } // namespace VR
 } // namespace Msp
index 46c65d9b912ac53d1fb0960a29d9381fa856c194..f7e28b587ec7f1cfd869864b136e059ee658d9c2 100644 (file)
@@ -20,6 +20,7 @@ public:
        virtual ~System() { }
 
        static System *create(const std::string &);
+       static System *create_autodetect();
 
        virtual void configure_window(Graphics::Window &) const = 0;
        virtual void configure_view(StereoView &) const = 0;