This avoids applications from needing a compile-time dependency to the
concrete display device classes, which may not be available due to
library configuration.
--- /dev/null
+#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
#ifndef MSP_VR_DISPLAYDEVICE_H_
#define MSP_VR_DISPLAYDEVICE_H_
+#include <string>
#include <msp/gl/camera.h>
#include <msp/gl/view.h>
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;