1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 10:19:55 +00:00
openmw-tes3mp/apps/openmw/mwvr/vrviewer.hpp

107 lines
2.9 KiB
C++
Raw Normal View History

#ifndef MWVR_VRVIEWER_H
#define MWVR_VRVIEWER_H
#include <memory>
#include <array>
#include <map>
2020-06-28 09:33:01 +00:00
#include <osg/Group>
#include <osg/Camera>
#include <osgViewer/Viewer>
#include "openxrmanager.hpp"
#include "vrshadow.hpp"
2020-06-28 09:33:01 +00:00
2020-02-14 21:11:19 +00:00
#include <components/sceneutil/positionattitudetransform.hpp>
namespace MWVR
{
2020-06-28 09:33:01 +00:00
class VRFramebuffer;
class VRView;
/// \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 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<const char*, 2> sViewNames;
public:
VRViewer(
2020-02-23 10:02:38 +00:00
osg::ref_ptr<osgViewer::Viewer> 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);
2020-07-26 11:12:36 +00:00
VrShadow& vrShadow() { return mVrShadow; }
2020-02-14 21:11:19 +00:00
void enableMainCamera(void);
void disableMainCamera(void);
private:
2020-02-15 19:01:11 +00:00
osg::ref_ptr<osgViewer::Viewer> mViewer = nullptr;
std::map<std::string, osg::ref_ptr<VRView> > mViews{};
std::map<std::string, osg::ref_ptr<osg::Camera> > mCameras{};
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 };
VrShadow mVrShadow;
std::mutex mMutex{};
bool mConfigured{ false };
bool mFlipMirrorTextureOrder{ false };
};
}
#endif