#ifndef MWVR_OPENRXVIEWER_H #define MWVR_OPENRXVIEWER_H #include #include #include #include #include #include #include "openxrmanager.hpp" #include "openxrsession.hpp" #include "openxrlayer.hpp" #include "openxrworldview.hpp" #include "openxrmenu.hpp" #include struct XrCompositionLayerProjection; struct XrCompositionLayerProjectionView; namespace MWVR { class OpenXRViewer : public osg::Group, public OpenXRLayer { public: class RealizeOperation : public OpenXRManager::RealizeOperation { public: RealizeOperation() {}; void operator()(osg::GraphicsContext* gc) override; bool realized() override; private: }; class SwapBuffersCallback : public osg::GraphicsContext::SwapCallback { public: SwapBuffersCallback(OpenXRViewer* viewer) : mViewer(viewer) {}; void swapBuffersImplementation(osg::GraphicsContext* gc) override; private: OpenXRViewer* mViewer; }; class PredrawCallback : public osg::Camera::DrawCallback { public: PredrawCallback(OpenXRViewer* viewer) : mViewer(viewer) {} void operator()(osg::RenderInfo& info) const override { mViewer->preDrawCallback(info); }; private: OpenXRViewer* mViewer; }; class PostdrawCallback : public osg::Camera::DrawCallback { public: PostdrawCallback(OpenXRViewer* viewer) : mViewer(viewer) {} void operator()(osg::RenderInfo& info) const override { mViewer->postDrawCallback(info); }; private: OpenXRViewer* mViewer; }; public: OpenXRViewer( osg::ref_ptr viewer); ~OpenXRViewer(void); virtual void traverse(osg::NodeVisitor& visitor) override; const XrCompositionLayerBaseHeader* layer() override; void traversals(); void preDrawCallback(osg::RenderInfo& info); void postDrawCallback(osg::RenderInfo& info); void blitEyesToMirrorTexture(osg::GraphicsContext* gc, bool includeMenu = true); void swapBuffers(osg::GraphicsContext* gc) override; void realize(osg::GraphicsContext* gc); bool realized() { return mConfigured; } void updateTransformNode(osg::Object* object, osg::Object* data); public: std::unique_ptr mLayer = nullptr; std::vector mCompositionLayerProjectionViews; osg::ref_ptr mRealizeOperation = nullptr; osg::ref_ptr mViewer = nullptr; std::map > mViews{}; std::map > mCameras{}; PredrawCallback* mPreDraw{ nullptr }; PostdrawCallback* mPostDraw{ nullptr }; std::unique_ptr mMirrorTextureSwapchain{ nullptr }; std::mutex mMutex; bool mConfigured{ false }; }; } #endif