2020-01-09 23:10:09 +00:00
|
|
|
#ifndef OPENXR_MANAGER_IMPL_HPP
|
|
|
|
#define OPENXR_MANAGER_IMPL_HPP
|
|
|
|
|
|
|
|
#include "openxrmanager.hpp"
|
2020-12-30 14:03:40 +00:00
|
|
|
#include "openxrplatform.hpp"
|
2020-01-09 23:10:09 +00:00
|
|
|
#include "../mwinput/inputmanagerimp.hpp"
|
|
|
|
|
|
|
|
#include <components/debug/debuglog.hpp>
|
|
|
|
#include <components/sdlutil/sdlgraphicswindow.hpp>
|
|
|
|
|
|
|
|
#include <openxr/openxr.h>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <array>
|
|
|
|
#include <map>
|
|
|
|
#include <iostream>
|
2020-01-23 23:14:23 +00:00
|
|
|
#include <thread>
|
2020-01-26 19:06:47 +00:00
|
|
|
#include <chrono>
|
2020-07-21 10:28:39 +00:00
|
|
|
#include <queue>
|
2020-01-23 23:14:23 +00:00
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
namespace MWVR
|
|
|
|
{
|
2020-06-26 21:02:48 +00:00
|
|
|
/// Conversion methods from openxr types to osg/mwvr types. Includes managing the differing conventions.
|
|
|
|
MWVR::Pose fromXR(XrPosef pose);
|
|
|
|
MWVR::FieldOfView fromXR(XrFovf fov);
|
|
|
|
osg::Vec3 fromXR(XrVector3f);
|
|
|
|
osg::Quat fromXR(XrQuaternionf quat);
|
2020-06-21 21:40:07 +00:00
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
/// Conversion methods from osg/mwvr types to openxr types. Includes managing the differing conventions.
|
|
|
|
XrPosef toXR(MWVR::Pose pose);
|
|
|
|
XrFovf toXR(MWVR::FieldOfView fov);
|
|
|
|
XrVector3f toXR(osg::Vec3 v);
|
|
|
|
XrQuaternionf toXR(osg::Quat quat);
|
2020-01-09 23:10:09 +00:00
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
XrCompositionLayerProjectionView toXR(MWVR::CompositionLayerProjectionView layer);
|
2020-12-09 20:11:53 +00:00
|
|
|
XrSwapchainSubImage toXR(MWVR::SubImage, bool depthImage);
|
2020-01-09 23:10:09 +00:00
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
/// \brief Implementation of OpenXRManager
|
2021-01-01 18:50:52 +00:00
|
|
|
class OpenXRManagerImpl
|
2020-06-26 21:02:48 +00:00
|
|
|
{
|
2021-01-01 18:50:52 +00:00
|
|
|
public:
|
2020-12-30 14:03:40 +00:00
|
|
|
OpenXRManagerImpl(osg::GraphicsContext* gc);
|
2020-06-26 21:02:48 +00:00
|
|
|
~OpenXRManagerImpl(void);
|
2020-06-24 19:26:11 +00:00
|
|
|
|
2020-08-02 10:34:46 +00:00
|
|
|
FrameInfo waitFrame();
|
2020-06-26 21:02:48 +00:00
|
|
|
void beginFrame();
|
2020-10-18 12:22:03 +00:00
|
|
|
void endFrame(FrameInfo frameInfo, const std::array<CompositionLayerProjectionView, 2>* layerStack);
|
|
|
|
bool appShouldSyncFrameLoop() const { return mAppShouldSyncFrameLoop; }
|
|
|
|
bool appShouldRender() const { return mAppShouldRender; }
|
|
|
|
bool appShouldReadInput() const { return mAppShouldReadInput; }
|
2020-06-26 21:02:48 +00:00
|
|
|
std::array<View, 2> getPredictedViews(int64_t predictedDisplayTime, ReferenceSpace space);
|
|
|
|
MWVR::Pose getPredictedHeadPose(int64_t predictedDisplayTime, ReferenceSpace space);
|
|
|
|
void handleEvents();
|
|
|
|
void enablePredictions();
|
|
|
|
void disablePredictions();
|
|
|
|
long long getLastPredictedDisplayTime();
|
|
|
|
long long getLastPredictedDisplayPeriod();
|
|
|
|
std::array<SwapchainConfig, 2> getRecommendedSwapchainConfig() const;
|
|
|
|
XrSpace getReferenceSpace(ReferenceSpace space);
|
|
|
|
XrSession xrSession() const { return mSession; };
|
|
|
|
XrInstance xrInstance() const { return mInstance; };
|
2020-07-15 21:17:16 +00:00
|
|
|
bool xrExtensionIsEnabled(const char* extensionName) const;
|
2020-07-21 10:28:39 +00:00
|
|
|
void xrResourceAcquired();
|
|
|
|
void xrResourceReleased();
|
2020-10-17 19:11:31 +00:00
|
|
|
void xrUpdateNames();
|
|
|
|
PFN_xrVoidFunction xrGetFunction(const std::string& name);
|
2020-12-30 14:03:40 +00:00
|
|
|
int64_t selectColorFormat();
|
|
|
|
int64_t selectDepthFormat();
|
|
|
|
OpenXRPlatform& platform() { return mPlatform; };
|
2020-06-24 19:26:11 +00:00
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
protected:
|
2020-10-17 10:33:46 +00:00
|
|
|
void setupExtensionsAndLayers();
|
2020-10-17 19:11:31 +00:00
|
|
|
void setupDebugMessenger(void);
|
2020-06-26 21:02:48 +00:00
|
|
|
void LogInstanceInfo();
|
|
|
|
void LogReferenceSpaces();
|
2020-07-21 10:28:39 +00:00
|
|
|
bool xrNextEvent(XrEventDataBuffer& eventBuffer);
|
|
|
|
void xrQueueEvents();
|
2020-06-26 21:02:48 +00:00
|
|
|
const XrEventDataBaseHeader* nextEvent();
|
2020-07-21 10:28:39 +00:00
|
|
|
bool processEvent(const XrEventDataBaseHeader* header);
|
|
|
|
void popEvent();
|
|
|
|
bool handleSessionStateChanged(const XrEventDataSessionStateChanged& stateChangedEvent);
|
|
|
|
bool checkStopCondition();
|
2020-06-24 19:26:11 +00:00
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
private:
|
2020-07-15 21:17:16 +00:00
|
|
|
|
2020-06-26 21:02:48 +00:00
|
|
|
bool initialized = false;
|
|
|
|
bool mPredictionsEnabled = false;
|
|
|
|
XrInstance mInstance = XR_NULL_HANDLE;
|
|
|
|
XrSession mSession = XR_NULL_HANDLE;
|
|
|
|
XrSpace mSpace = XR_NULL_HANDLE;
|
|
|
|
XrFormFactor mFormFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;
|
|
|
|
XrViewConfigurationType mViewConfigType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
|
|
|
|
XrEnvironmentBlendMode mEnvironmentBlendMode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
|
|
|
|
XrSystemId mSystemId = XR_NULL_SYSTEM_ID;
|
|
|
|
XrSystemProperties mSystemProperties{ XR_TYPE_SYSTEM_PROPERTIES };
|
|
|
|
std::array<XrViewConfigurationView, 2> mConfigViews{ { {XR_TYPE_VIEW_CONFIGURATION_VIEW}, {XR_TYPE_VIEW_CONFIGURATION_VIEW} } };
|
|
|
|
XrSpace mReferenceSpaceView = XR_NULL_HANDLE;
|
|
|
|
XrSpace mReferenceSpaceStage = XR_NULL_HANDLE;
|
|
|
|
XrFrameState mFrameState{};
|
|
|
|
XrSessionState mSessionState = XR_SESSION_STATE_UNKNOWN;
|
2020-10-17 19:11:31 +00:00
|
|
|
XrDebugUtilsMessengerEXT mDebugMessenger{ nullptr };
|
2020-10-18 12:22:03 +00:00
|
|
|
|
2020-12-30 14:03:40 +00:00
|
|
|
OpenXRPlatform mPlatform;
|
|
|
|
|
2020-10-18 12:22:03 +00:00
|
|
|
bool mXrSessionShouldStop = false;
|
|
|
|
bool mAppShouldSyncFrameLoop = false;
|
|
|
|
bool mAppShouldRender = false;
|
|
|
|
bool mAppShouldReadInput = false;
|
|
|
|
|
2020-07-21 10:28:39 +00:00
|
|
|
uint32_t mAcquiredResources = 0;
|
2020-10-22 18:39:53 +00:00
|
|
|
std::mutex mMutex{};
|
2020-07-21 10:28:39 +00:00
|
|
|
std::queue<XrEventDataBuffer> mEventQueue;
|
2020-07-15 21:17:16 +00:00
|
|
|
|
|
|
|
std::array<XrCompositionLayerDepthInfoKHR, 2> mLayerDepth;
|
2020-06-26 21:02:48 +00:00
|
|
|
};
|
2020-01-09 23:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|