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

151 lines
4.5 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>
2020-12-16 20:00:21 +00:00
#include <components/misc/stereo.hpp>
namespace MWVR
{
2020-06-28 09:33:01 +00:00
class VRFramebuffer;
class VRView;
class OpenXRSwapchain;
2020-06-28 09:33:01 +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.
class VRViewer
{
public:
2020-12-16 20:00:21 +00:00
struct UpdateViewCallback : public Misc::StereoView::UpdateViewCallback
{
UpdateViewCallback(VRViewer* viewer) : mViewer(viewer) {};
//! Called during the update traversal of every frame to source updated stereo values.
virtual void updateView(Misc::View& left, Misc::View& right) override;
VRViewer* mViewer;
};
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;
};
class InitialDrawCallback : public osg::Camera::DrawCallback
{
public:
InitialDrawCallback(VRViewer* viewer)
: mViewer(viewer)
{}
void operator()(osg::RenderInfo& info) const override { mViewer->initialDrawCallback(info); };
private:
VRViewer* mViewer;
};
static const std::array<const char*, 2> sViewNames;
2020-11-29 12:14:00 +00:00
enum class MirrorTextureEye
{
Left,
Right,
Both
};
public:
VRViewer(
2020-02-23 10:02:38 +00:00
osg::ref_ptr<osgViewer::Viewer> viewer);
~VRViewer(void);
2020-12-20 19:32:32 +00:00
void swapBuffersCallback(osg::GraphicsContext* gc);
void initialDrawCallback(osg::RenderInfo& info);
void preDrawCallback(osg::RenderInfo& info);
void postDrawCallback(osg::RenderInfo& info);
void blit(osg::GraphicsContext* gc);
void configureXR(osg::GraphicsContext* gc);
void configureCallbacks();
2020-11-29 12:14:00 +00:00
void setupMirrorTexture();
void processChangedSettings(const std::set< std::pair<std::string, std::string> >& changed);
2020-12-16 20:00:21 +00:00
void updateView(Misc::View& left, Misc::View& right);
2020-02-14 21:11:19 +00:00
SubImage subImage(Side side);
bool xrConfigured() { return mOpenXRConfigured; };
bool callbacksConfigured() { return mCallbacksConfigured; };
private:
std::mutex mMutex{};
bool mOpenXRConfigured{ false };
bool mCallbacksConfigured{ false };
2020-02-15 19:01:11 +00:00
osg::ref_ptr<osgViewer::Viewer> mViewer = nullptr;
osg::ref_ptr<PredrawCallback> mPreDraw{ nullptr };
osg::ref_ptr<PostdrawCallback> mPostDraw{ nullptr };
std::shared_ptr<UpdateViewCallback> mUpdateViewCallback{ nullptr };
2020-12-20 19:32:32 +00:00
bool mRenderingReady{ false };
std::unique_ptr<VRFramebuffer> mMirrorTexture;
2020-08-07 21:33:21 +00:00
std::vector<std::string> mMirrorTextureViews;
2020-11-29 12:14:00 +00:00
bool mMirrorTextureShouldBeCleanedUp{ false };
bool mMirrorTextureEnabled{ false };
bool mFlipMirrorTextureOrder{ false };
MirrorTextureEye mMirrorTextureEye{ MirrorTextureEye::Both };
std::unique_ptr<VRFramebuffer> mFramebuffer;
std::unique_ptr<VRFramebuffer> mMsaaResolveTexture;
2021-01-16 13:30:59 +00:00
std::unique_ptr<VRFramebuffer> mGammaResolveTexture;
std::array<std::unique_ptr<OpenXRSwapchain>, 2> mSwapchain;
std::array<SubImage, 2> mSubImages;
std::array<SwapchainConfig, 2> mSwapchainConfig;
};
}
#endif