]> git.tdb.fi Git - libs/vr.git/commitdiff
Add a factory method in DisplayDevice
authorMikko Rasa <tdb@tdb.fi>
Fri, 23 Sep 2016 16:29:20 +0000 (19:29 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 23 Sep 2016 16:39:50 +0000 (19:39 +0300)
This avoids applications from needing a compile-time dependency to the
concrete display device classes, which may not be available due to
library configuration.

source/displaydevice.cpp [new file with mode: 0644]
source/displaydevice.h

diff --git a/source/displaydevice.cpp b/source/displaydevice.cpp
new file mode 100644 (file)
index 0000000..5e11266
--- /dev/null
@@ -0,0 +1,29 @@
+#include <msp/strings/format.h>
+#include "displaydevice.h"
+#ifdef WITH_OPENVR
+#include "openvr/openvrdevice.h"
+#endif
+#ifdef WITH_LIBOVR
+#include "ovr/oculusriftdevice.h"
+#endif
+
+using namespace std;
+
+namespace Msp {
+namespace VR {
+
+DisplayDevice *DisplayDevice::create_device(const string &type)
+{
+#ifdef WITH_OPENVR
+       if(type=="openvr")
+               return new OpenVRDevice;
+#endif
+#ifdef WITH_LIBOVR
+       if(type=="libovr")
+               return new OculusRiftDevice;
+#endif
+       throw invalid_argument(format("device type '%s' not supported", type));
+}
+
+} // namespace VR
+} // namespace Msp
index 665ac85697a2ac4f1aa350719bdc735c3ab8f634..46dfbaeb8dacca32c998f70f7d74c1d62f1d650e 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_VR_DISPLAYDEVICE_H_
 #define MSP_VR_DISPLAYDEVICE_H_
 
+#include <string>
 #include <msp/gl/camera.h>
 #include <msp/gl/view.h>
 
@@ -18,6 +19,8 @@ protected:
 public:
        virtual ~DisplayDevice() { }
 
+       static DisplayDevice *create_device(const std::string &);
+
        virtual void configure_window(Graphics::Window &) const = 0;
        virtual void configure_view(StereoView &) const = 0;
        virtual HeadTrackingCamera *create_camera(const GL::Camera &) = 0;