// SPDX-License-Identifier: LGPL-2.1-only // Copyright (C) 2021 James Hogan #include "GraphicsBinding.h" #include "GraphicsBindingWin32.h" #include "GraphicsBindingX11.h" #include using namespace osgXR::OpenXR; namespace osgXR { namespace OpenXR { class GraphicsBindingProxy : public osg::Referenced { public: virtual ~GraphicsBindingProxy() {} virtual GraphicsBinding *create(osgViewer::GraphicsWindow *window) = 0; }; template class GraphicsBindingProxyImpl : public GraphicsBindingProxy { protected: typedef GRAPHICS_BINDING Binding; typedef typename Binding::GraphicsWindow Window; virtual ~GraphicsBindingProxyImpl() {} public: GraphicsBinding *create(osgViewer::GraphicsWindow *window) override { Window *win = dynamic_cast(window); if (!win) return nullptr; return new Binding(win); } }; } // osgXR::OpenXR } // osgXR typedef std::vector > ProxyList; static ProxyList proxies = { #ifdef OSGXR_USE_WIN32 new GraphicsBindingProxyImpl(), #endif #ifdef OSGXR_USE_X11 new GraphicsBindingProxyImpl(), #endif }; osg::ref_ptr osgXR::OpenXR::createGraphicsBinding(osgViewer::GraphicsWindow *window) { GraphicsBinding *ret = nullptr; for (GraphicsBindingProxy *proxy: proxies) { ret = proxy->create(window); if (ret) break; } return ret; }