2020-07-20 13:03:48 +00:00
|
|
|
#ifndef MWVR_VRVIEWER_H
|
|
|
|
#define MWVR_VRVIEWER_H
|
2020-01-09 23:10:09 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <array>
|
2020-02-02 12:12:53 +00:00
|
|
|
#include <map>
|
2020-06-28 09:33:01 +00:00
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
#include <osg/Group>
|
|
|
|
#include <osg/Camera>
|
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
|
|
|
|
#include "openxrmanager.hpp"
|
2020-07-20 13:03:48 +00:00
|
|
|
#include "vrshadow.hpp"
|
2020-06-28 09:33:01 +00:00
|
|
|
|
2020-02-14 21:11:19 +00:00
|
|
|
#include <components/sceneutil/positionattitudetransform.hpp>
|
2020-01-09 23:10:09 +00:00
|
|
|
|
|
|
|
namespace MWVR
|
|
|
|
{
|
2020-06-28 09:33:01 +00:00
|
|
|
class VRFramebuffer;
|
|
|
|
class VRView;
|
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
/// \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.
|
2020-05-24 16:00:42 +00:00
|
|
|
class VRViewer
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-01-23 23:14:23 +00:00
|
|
|
class SwapBuffersCallback : public osg::GraphicsContext::SwapCallback
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
2020-01-23 23:14:23 +00:00
|
|
|
public:
|
2020-05-24 16:00:42 +00:00
|
|
|
SwapBuffersCallback(VRViewer* viewer) : mViewer(viewer) {};
|
2020-01-23 23:14:23 +00:00
|
|
|
void swapBuffersImplementation(osg::GraphicsContext* gc) override;
|
|
|
|
|
|
|
|
private:
|
2020-05-24 16:00:42 +00:00
|
|
|
VRViewer* mViewer;
|
2020-01-09 23:10:09 +00:00
|
|
|
};
|
|
|
|
|
2020-02-02 12:12:53 +00:00
|
|
|
class PredrawCallback : public osg::Camera::DrawCallback
|
|
|
|
{
|
|
|
|
public:
|
2020-05-24 16:00:42 +00:00
|
|
|
PredrawCallback(VRViewer* viewer)
|
2020-02-02 12:12:53 +00:00
|
|
|
: mViewer(viewer)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void operator()(osg::RenderInfo& info) const override { mViewer->preDrawCallback(info); };
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2020-05-24 16:00:42 +00:00
|
|
|
VRViewer* mViewer;
|
2020-02-02 12:12:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PostdrawCallback : public osg::Camera::DrawCallback
|
|
|
|
{
|
|
|
|
public:
|
2020-05-24 16:00:42 +00:00
|
|
|
PostdrawCallback(VRViewer* viewer)
|
2020-02-02 12:12:53 +00:00
|
|
|
: mViewer(viewer)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void operator()(osg::RenderInfo& info) const override { mViewer->postDrawCallback(info); };
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2020-05-24 16:00:42 +00:00
|
|
|
VRViewer* mViewer;
|
2020-02-02 12:12:53 +00:00
|
|
|
};
|
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
|
|
|
|
static const std::array<const char*, 2> sViewNames;
|
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
public:
|
2020-05-24 16:00:42 +00:00
|
|
|
VRViewer(
|
2020-02-23 10:02:38 +00:00
|
|
|
osg::ref_ptr<osgViewer::Viewer> viewer);
|
2020-01-09 23:10:09 +00:00
|
|
|
|
2020-05-24 16:00:42 +00:00
|
|
|
~VRViewer(void);
|
2020-01-09 23:10:09 +00:00
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
void traversals();
|
2020-02-02 12:12:53 +00:00
|
|
|
void preDrawCallback(osg::RenderInfo& info);
|
|
|
|
void postDrawCallback(osg::RenderInfo& info);
|
2020-05-01 19:37:01 +00:00
|
|
|
void blitEyesToMirrorTexture(osg::GraphicsContext* gc);
|
2020-01-23 23:14:23 +00:00
|
|
|
void realize(osg::GraphicsContext* gc);
|
|
|
|
bool realized() { return mConfigured; }
|
2020-06-26 21:02:48 +00:00
|
|
|
VRView* getView(std::string name);
|
2020-07-26 11:12:36 +00:00
|
|
|
VrShadow& vrShadow() { return mVrShadow; }
|
2020-02-14 21:11:19 +00:00
|
|
|
|
2020-05-20 23:01:15 +00:00
|
|
|
void enableMainCamera(void);
|
|
|
|
void disableMainCamera(void);
|
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
private:
|
2020-02-15 19:01:11 +00:00
|
|
|
osg::ref_ptr<osgViewer::Viewer> mViewer = nullptr;
|
2020-05-24 16:00:42 +00:00
|
|
|
std::map<std::string, osg::ref_ptr<VRView> > mViews{};
|
2020-02-02 12:12:53 +00:00
|
|
|
std::map<std::string, osg::ref_ptr<osg::Camera> > mCameras{};
|
2020-05-20 23:01:15 +00:00
|
|
|
osg::ref_ptr<PredrawCallback> mPreDraw{ nullptr };
|
|
|
|
osg::ref_ptr<PostdrawCallback> mPostDraw{ nullptr };
|
|
|
|
osg::GraphicsContext* mMainCameraGC{ nullptr };
|
2020-06-28 09:33:01 +00:00
|
|
|
std::unique_ptr<VRFramebuffer> mMsaaResolveMirrorTexture[2]{ };
|
|
|
|
std::unique_ptr<VRFramebuffer> mMirrorTexture{ nullptr };
|
2020-07-20 13:03:48 +00:00
|
|
|
VrShadow mVrShadow;
|
2020-01-23 23:14:23 +00:00
|
|
|
|
2020-07-20 13:03:48 +00:00
|
|
|
std::mutex mMutex{};
|
2020-01-23 23:14:23 +00:00
|
|
|
|
2020-02-29 13:12:38 +00:00
|
|
|
bool mConfigured{ false };
|
2020-08-07 21:33:21 +00:00
|
|
|
std::vector<std::string> mMirrorTextureViews;
|
2020-01-09 23:10:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|