2020-01-09 23:10:09 +00:00
|
|
|
#include "openxrmanager.hpp"
|
2020-06-26 21:02:48 +00:00
|
|
|
#include "vrenvironment.hpp"
|
2020-01-09 23:10:09 +00:00
|
|
|
#include "openxrmanagerimpl.hpp"
|
|
|
|
#include "../mwinput/inputmanagerimp.hpp"
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
|
|
|
|
namespace MWVR
|
|
|
|
{
|
|
|
|
OpenXRManager::OpenXRManager()
|
|
|
|
: mPrivate(nullptr)
|
|
|
|
, mMutex()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenXRManager::~OpenXRManager()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-02 12:12:53 +00:00
|
|
|
bool
|
2020-01-09 23:10:09 +00:00
|
|
|
OpenXRManager::realized()
|
|
|
|
{
|
|
|
|
return !!mPrivate;
|
|
|
|
}
|
|
|
|
|
2020-06-24 19:26:11 +00:00
|
|
|
bool OpenXRManager::xrSessionRunning()
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
|
|
|
if (realized())
|
2020-06-24 19:26:11 +00:00
|
|
|
return impl().xrSessionRunning();
|
2020-01-09 23:10:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-21 10:28:39 +00:00
|
|
|
bool OpenXRManager::frameShouldRender()
|
|
|
|
{
|
|
|
|
if (realized())
|
|
|
|
return impl().frameShouldRender();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
void OpenXRManager::handleEvents()
|
|
|
|
{
|
|
|
|
if (realized())
|
2020-01-23 23:14:23 +00:00
|
|
|
return impl().handleEvents();
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenXRManager::waitFrame()
|
|
|
|
{
|
|
|
|
if (realized())
|
2020-01-23 23:14:23 +00:00
|
|
|
return impl().waitFrame();
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-26 19:06:47 +00:00
|
|
|
void OpenXRManager::beginFrame()
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
|
|
|
if (realized())
|
2020-01-26 19:06:47 +00:00
|
|
|
return impl().beginFrame();
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 21:40:07 +00:00
|
|
|
void OpenXRManager::endFrame(int64_t displayTime, int layerCount, const std::array<CompositionLayerProjectionView, 2>& layerStack)
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
|
|
|
if (realized())
|
2020-05-24 16:00:42 +00:00
|
|
|
return impl().endFrame(displayTime, layerCount, layerStack);
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OpenXRManager::realize(
|
|
|
|
osg::GraphicsContext* gc)
|
|
|
|
{
|
|
|
|
lock_guard lock(mMutex);
|
|
|
|
if (!realized())
|
|
|
|
{
|
|
|
|
gc->makeCurrent();
|
|
|
|
try {
|
|
|
|
mPrivate = std::make_shared<OpenXRManagerImpl>();
|
|
|
|
}
|
2020-06-26 21:02:48 +00:00
|
|
|
catch (std::exception& e)
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
|
|
|
Log(Debug::Error) << "Exception thrown by OpenXR: " << e.what();
|
|
|
|
osg::ref_ptr<osg::State> state = gc->getState();
|
2020-02-02 12:12:53 +00:00
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 21:40:07 +00:00
|
|
|
void OpenXRManager::enablePredictions()
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
2020-06-21 21:40:07 +00:00
|
|
|
return impl().enablePredictions();
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 21:40:07 +00:00
|
|
|
void OpenXRManager::disablePredictions()
|
2020-01-09 23:10:09 +00:00
|
|
|
{
|
2020-06-21 21:40:07 +00:00
|
|
|
return impl().disablePredictions();
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
2020-02-14 21:11:19 +00:00
|
|
|
|
2020-07-21 10:28:39 +00:00
|
|
|
void OpenXRManager::xrResourceAcquired()
|
|
|
|
{
|
|
|
|
return impl().xrResourceAcquired();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenXRManager::xrResourceReleased()
|
|
|
|
{
|
|
|
|
return impl().xrResourceReleased();
|
|
|
|
}
|
|
|
|
|
2020-06-24 19:26:11 +00:00
|
|
|
std::array<View, 2> OpenXRManager::getPredictedViews(int64_t predictedDisplayTime, ReferenceSpace space)
|
2020-05-01 19:37:01 +00:00
|
|
|
{
|
2020-06-21 21:40:07 +00:00
|
|
|
return impl().getPredictedViews(predictedDisplayTime, space);
|
2020-05-01 19:37:01 +00:00
|
|
|
}
|
2020-05-24 16:00:42 +00:00
|
|
|
|
2020-06-24 19:26:11 +00:00
|
|
|
MWVR::Pose OpenXRManager::getPredictedHeadPose(int64_t predictedDisplayTime, ReferenceSpace space)
|
2020-05-01 19:37:01 +00:00
|
|
|
{
|
2020-06-21 21:40:07 +00:00
|
|
|
return impl().getPredictedHeadPose(predictedDisplayTime, space);
|
2020-05-01 19:37:01 +00:00
|
|
|
}
|
2020-05-24 16:00:42 +00:00
|
|
|
|
2020-06-24 19:26:11 +00:00
|
|
|
long long OpenXRManager::getLastPredictedDisplayTime()
|
|
|
|
{
|
|
|
|
return impl().getLastPredictedDisplayTime();
|
|
|
|
}
|
|
|
|
|
2020-06-21 21:40:07 +00:00
|
|
|
long long OpenXRManager::getLastPredictedDisplayPeriod()
|
2020-05-24 16:00:42 +00:00
|
|
|
{
|
2020-06-21 21:40:07 +00:00
|
|
|
return impl().getLastPredictedDisplayPeriod();
|
2020-05-24 16:00:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 19:26:11 +00:00
|
|
|
std::array<SwapchainConfig, 2> OpenXRManager::getRecommendedSwapchainConfig() const
|
|
|
|
{
|
|
|
|
return impl().getRecommendedSwapchainConfig();
|
|
|
|
}
|
|
|
|
|
2020-07-15 21:17:16 +00:00
|
|
|
bool OpenXRManager::xrExtensionIsEnabled(const char* extensionName) const
|
|
|
|
{
|
|
|
|
return impl().xrExtensionIsEnabled(extensionName);
|
|
|
|
}
|
|
|
|
|
2020-06-21 21:40:07 +00:00
|
|
|
void
|
|
|
|
OpenXRManager::CleanupOperation::operator()(
|
|
|
|
osg::GraphicsContext* gc)
|
2020-06-02 19:45:18 +00:00
|
|
|
{
|
2020-06-28 09:33:01 +00:00
|
|
|
// TODO: Use this to make proper cleanup such as cleaning up VRFramebuffers.
|
2020-06-02 19:45:18 +00:00
|
|
|
}
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
2020-01-23 23:14:23 +00:00
|
|
|
|