2020-01-09 23:10:09 +00:00
|
|
|
#include "openxrview.hpp"
|
|
|
|
#include "openxrmanager.hpp"
|
|
|
|
#include "openxrmanagerimpl.hpp"
|
|
|
|
#include "../mwinput/inputmanagerimp.hpp"
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
#include <components/sdlutil/sdlgraphicswindow.hpp>
|
|
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
#include <openxr/openxr.h>
|
|
|
|
#include <openxr/openxr_platform.h>
|
|
|
|
#include <openxr/openxr_platform_defines.h>
|
|
|
|
#include <openxr/openxr_reflection.h>
|
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
namespace MWVR {
|
2020-01-09 23:10:09 +00:00
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
OpenXRView::OpenXRView(
|
2020-01-26 19:06:47 +00:00
|
|
|
osg::ref_ptr<OpenXRManager> XR,
|
2020-02-02 12:12:53 +00:00
|
|
|
std::string name,
|
|
|
|
OpenXRSwapchain::Config config,
|
|
|
|
osg::ref_ptr<osg::State> state)
|
2020-01-09 23:10:09 +00:00
|
|
|
: mXR(XR)
|
2020-02-02 12:12:53 +00:00
|
|
|
, mSwapchainConfig{ config }
|
|
|
|
, mSwapchain(new OpenXRSwapchain(mXR, state, mSwapchainConfig))
|
2020-01-26 19:06:47 +00:00
|
|
|
, mName(name)
|
2020-02-02 12:12:53 +00:00
|
|
|
, mTimer(mName.c_str())
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
OpenXRView::~OpenXRView()
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
osg::Camera* OpenXRView::createCamera(int eye, const osg::Vec4& clearColor, osg::GraphicsContext* gc)
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
|
|
|
osg::ref_ptr<osg::Camera> camera = new osg::Camera();
|
|
|
|
camera->setClearColor(clearColor);
|
|
|
|
camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
|
|
|
|
camera->setRenderOrder(osg::Camera::PRE_RENDER, eye);
|
|
|
|
camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
|
|
|
camera->setAllowEventFocus(false);
|
|
|
|
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
2020-01-23 23:14:23 +00:00
|
|
|
camera->setViewport(0, 0, mSwapchain->width(), mSwapchain->height());
|
2020-01-09 23:10:09 +00:00
|
|
|
camera->setGraphicsContext(gc);
|
|
|
|
|
|
|
|
camera->setInitialDrawCallback(new OpenXRView::InitialDrawCallback());
|
2020-01-26 19:06:47 +00:00
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
return camera.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenXRView::prerenderCallback(osg::RenderInfo& renderInfo)
|
|
|
|
{
|
2020-01-26 19:06:47 +00:00
|
|
|
if (mSwapchain)
|
|
|
|
{
|
2020-01-23 23:14:23 +00:00
|
|
|
mSwapchain->beginFrame(renderInfo.getState()->getGraphicsContext());
|
2020-01-26 19:06:47 +00:00
|
|
|
}
|
2020-02-02 12:12:53 +00:00
|
|
|
mTimer.checkpoint("Prerender");
|
2020-03-01 11:54:32 +00:00
|
|
|
Log(Debug::Verbose) << "XRView: PreRender";
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenXRView::postrenderCallback(osg::RenderInfo& renderInfo)
|
|
|
|
{
|
2020-01-26 19:06:47 +00:00
|
|
|
// mSwapchain->endFrame(renderInfo.getState()->getGraphicsContext());
|
|
|
|
|
2020-02-02 12:12:53 +00:00
|
|
|
mTimer.checkpoint("Postrender");
|
2020-03-01 11:54:32 +00:00
|
|
|
Log(Debug::Verbose) << "XRView: PostRender";
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 12:12:53 +00:00
|
|
|
void OpenXRView::swapBuffers(osg::GraphicsContext* gc)
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
2020-02-02 12:12:53 +00:00
|
|
|
swapchain().endFrame(gc);
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 12:12:53 +00:00
|
|
|
void OpenXRView::setPredictedPose(const Pose& pose)
|
|
|
|
{
|
|
|
|
mPredictedPose = pose;
|
|
|
|
//Log(Debug::Verbose) << mName << " predicted pose updated to " << pose;
|
|
|
|
};
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|