mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-26 20:39:41 +00:00
Separate GLRC for OpenXR to ensure uncontested access.
Safety check on predictions to police that they are made only once per frame.
This commit is contained in:
parent
9ad910a8e7
commit
8f38f0536c
2 changed files with 30 additions and 3 deletions
|
@ -93,10 +93,16 @@ namespace MWVR
|
||||||
|
|
||||||
{ // Create Session
|
{ // Create Session
|
||||||
// TODO: Platform dependent
|
// TODO: Platform dependent
|
||||||
|
auto DC = wglGetCurrentDC();
|
||||||
|
auto GLRC = wglGetCurrentContext();
|
||||||
|
auto XRGLRC = wglCreateContext(DC);
|
||||||
|
wglShareLists(GLRC, XRGLRC);
|
||||||
|
wglMakeCurrent(DC, XRGLRC);
|
||||||
|
|
||||||
mGraphicsBinding.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR;
|
mGraphicsBinding.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR;
|
||||||
mGraphicsBinding.next = nullptr;
|
mGraphicsBinding.next = nullptr;
|
||||||
mGraphicsBinding.hDC = wglGetCurrentDC();
|
mGraphicsBinding.hDC = DC;
|
||||||
mGraphicsBinding.hGLRC = wglGetCurrentContext();
|
mGraphicsBinding.hGLRC = XRGLRC;
|
||||||
|
|
||||||
if (!mGraphicsBinding.hDC)
|
if (!mGraphicsBinding.hDC)
|
||||||
std::cout << "Missing DC" << std::endl;
|
std::cout << "Missing DC" << std::endl;
|
||||||
|
@ -108,6 +114,7 @@ namespace MWVR
|
||||||
createInfo.systemId = mSystemId;
|
createInfo.systemId = mSystemId;
|
||||||
CHECK_XRCMD(xrCreateSession(mInstance, &createInfo, &mSession));
|
CHECK_XRCMD(xrCreateSession(mInstance, &createInfo, &mSession));
|
||||||
assert(mSession);
|
assert(mSession);
|
||||||
|
wglMakeCurrent(DC, GLRC);
|
||||||
}
|
}
|
||||||
|
|
||||||
LogLayersAndExtensions();
|
LogLayersAndExtensions();
|
||||||
|
@ -315,7 +322,11 @@ namespace MWVR
|
||||||
int64_t predictedDisplayTime,
|
int64_t predictedDisplayTime,
|
||||||
TrackedSpace space)
|
TrackedSpace space)
|
||||||
{
|
{
|
||||||
|
if (!mPredictionsEnabled)
|
||||||
|
{
|
||||||
|
Log(Debug::Error) << "Prediction out of order";
|
||||||
|
throw std::logic_error("Prediction out of order");
|
||||||
|
}
|
||||||
std::array<XrView, 2> views{ {{XR_TYPE_VIEW}, {XR_TYPE_VIEW}} };
|
std::array<XrView, 2> views{ {{XR_TYPE_VIEW}, {XR_TYPE_VIEW}} };
|
||||||
XrViewState viewState{ XR_TYPE_VIEW_STATE };
|
XrViewState viewState{ XR_TYPE_VIEW_STATE };
|
||||||
uint32_t viewCount = 2;
|
uint32_t viewCount = 2;
|
||||||
|
@ -339,6 +350,11 @@ namespace MWVR
|
||||||
|
|
||||||
MWVR::Pose OpenXRManagerImpl::getPredictedLimbPose(int64_t predictedDisplayTime, TrackedLimb limb, TrackedSpace space)
|
MWVR::Pose OpenXRManagerImpl::getPredictedLimbPose(int64_t predictedDisplayTime, TrackedLimb limb, TrackedSpace space)
|
||||||
{
|
{
|
||||||
|
if (!mPredictionsEnabled)
|
||||||
|
{
|
||||||
|
Log(Debug::Error) << "Prediction out of order";
|
||||||
|
throw std::logic_error("Prediction out of order");
|
||||||
|
}
|
||||||
XrSpaceLocation location{ XR_TYPE_SPACE_LOCATION };
|
XrSpaceLocation location{ XR_TYPE_SPACE_LOCATION };
|
||||||
XrSpaceVelocity velocity{ XR_TYPE_SPACE_VELOCITY };
|
XrSpaceVelocity velocity{ XR_TYPE_SPACE_VELOCITY };
|
||||||
location.next = &velocity;
|
location.next = &velocity;
|
||||||
|
@ -500,6 +516,14 @@ namespace MWVR
|
||||||
referenceSpace = mReferenceSpaceView;
|
referenceSpace = mReferenceSpaceView;
|
||||||
return referenceSpace;
|
return referenceSpace;
|
||||||
}
|
}
|
||||||
|
void OpenXRManagerImpl::enablePredictions()
|
||||||
|
{
|
||||||
|
mPredictionsEnabled = true;
|
||||||
|
}
|
||||||
|
void OpenXRManagerImpl::disablePredictions()
|
||||||
|
{
|
||||||
|
mPredictionsEnabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace osg
|
namespace osg
|
||||||
|
|
|
@ -65,8 +65,11 @@ namespace MWVR
|
||||||
void HandleSessionStateChanged(const XrEventDataSessionStateChanged& stateChangedEvent);
|
void HandleSessionStateChanged(const XrEventDataSessionStateChanged& stateChangedEvent);
|
||||||
XrFrameState frameState();
|
XrFrameState frameState();
|
||||||
XrSpace getReferenceSpace(TrackedSpace space);
|
XrSpace getReferenceSpace(TrackedSpace space);
|
||||||
|
void enablePredictions();
|
||||||
|
void disablePredictions();
|
||||||
|
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
|
bool mPredictionsEnabled = false;
|
||||||
long long mFrameIndex = 0;
|
long long mFrameIndex = 0;
|
||||||
XrInstance mInstance = XR_NULL_HANDLE;
|
XrInstance mInstance = XR_NULL_HANDLE;
|
||||||
XrSession mSession = XR_NULL_HANDLE;
|
XrSession mSession = XR_NULL_HANDLE;
|
||||||
|
|
Loading…
Reference in a new issue