From: Mikko Rasa Date: Fri, 23 Sep 2016 16:29:20 +0000 (+0300) Subject: Add a factory method in DisplayDevice X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=7c168688178a2a541d25e559c782bf75f50b6207;p=libs%2Fvr.git Add a factory method in DisplayDevice This avoids applications from needing a compile-time dependency to the concrete display device classes, which may not be available due to library configuration. --- diff --git a/source/displaydevice.cpp b/source/displaydevice.cpp new file mode 100644 index 0000000..5e11266 --- /dev/null +++ b/source/displaydevice.cpp @@ -0,0 +1,29 @@ +#include +#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 diff --git a/source/displaydevice.h b/source/displaydevice.h index 665ac85..46dfbae 100644 --- a/source/displaydevice.h +++ b/source/displaydevice.h @@ -1,6 +1,7 @@ #ifndef MSP_VR_DISPLAYDEVICE_H_ #define MSP_VR_DISPLAYDEVICE_H_ +#include #include #include @@ -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;