#ifndef MWVR_OPENRXVIEWER_H #define MWVR_OPENRXVIEWER_H #include #include #include #include #include #include #include "openxrmanager.hpp" #include "vrgui.hpp" #include namespace MWVR { /// \brief Manages stereo rendering and mirror texturing. /// /// Manipulates the osgViewer by disabling main camera rendering, and instead rendering to /// two slave cameras, each connected to and manipulated by a VRView class. class VRViewer { 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(VRViewer* viewer) : mViewer(viewer) {}; void swapBuffersImplementation(osg::GraphicsContext* gc) override; private: VRViewer* mViewer; }; class PredrawCallback : public osg::Camera::DrawCallback { public: PredrawCallback(VRViewer* viewer) : mViewer(viewer) {} void operator()(osg::RenderInfo& info) const override { mViewer->preDrawCallback(info); }; private: VRViewer* mViewer; }; class PostdrawCallback : public osg::Camera::DrawCallback { public: PostdrawCallback(VRViewer* viewer) : mViewer(viewer) {} void operator()(osg::RenderInfo& info) const override { mViewer->postDrawCallback(info); }; private: VRViewer* mViewer; }; static const std::array sViewNames; public: VRViewer( osg::ref_ptr viewer); ~VRViewer(void); void traversals(); void preDrawCallback(osg::RenderInfo& info); void postDrawCallback(osg::RenderInfo& info); void blitEyesToMirrorTexture(osg::GraphicsContext* gc); void realize(osg::GraphicsContext* gc); bool realized() { return mConfigured; } VRView* getView(std::string name); void enableMainCamera(void); void disableMainCamera(void); private: osg::ref_ptr mRealizeOperation = nullptr; osg::ref_ptr mViewer = nullptr; std::map > mViews{}; std::map > mCameras{}; osg::ref_ptr mPreDraw{ nullptr }; osg::ref_ptr mPostDraw{ nullptr }; osg::GraphicsContext* mMainCameraGC{ nullptr }; std::unique_ptr mMsaaResolveMirrorTexture[2]{ }; std::unique_ptr mMirrorTexture{ nullptr }; std::mutex mMutex; bool mConfigured{ false }; }; } #endif