From 0e4f93d2007e534560ca9c12f8b7149f8e03ebfa Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 5 Sep 2022 18:15:31 +0200 Subject: [PATCH] OpenXR - Fixing FOV better --- Common/GPU/OpenGL/GLRenderManager.cpp | 3 +-- Common/VR/PPSSPPVR.cpp | 2 +- Common/VR/VRFramebuffer.cpp | 2 +- Common/VR/VRMath.h | 2 +- Common/VR/VRRenderer.cpp | 13 +++---------- Common/VR/VRRenderer.h | 9 ++++----- 6 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index 7c228f240b..efdf0bd7f4 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -594,6 +594,7 @@ void GLRenderManager::Run(int frame) { } else { queueRunner_.RunSteps(stepsOnThread, skipGLCalls_); } + stepsOnThread.clear(); if (!skipGLCalls_) { for (auto iter : frameData.activePushBuffers) { @@ -601,8 +602,6 @@ void GLRenderManager::Run(int frame) { } } - stepsOnThread.clear(); - switch (frameData.type) { case GLRRunType::END: EndSubmitFrame(frame); diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index f3040ea4d1..2d3562468c 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -238,7 +238,7 @@ bool PreVRRender() { // Set customizations VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF); VR_SetConfig(VR_CONFIG_CANVAS_DISTANCE, g_Config.iCanvasDistance); - VR_SetConfig(VR_CONFIG_FOV_SCALE, g_Config.iFieldOfViewPercentage * 0.5f); + VR_SetConfig(VR_CONFIG_FOV_SCALE, g_Config.iFieldOfViewPercentage); return true; } return false; diff --git a/Common/VR/VRFramebuffer.cpp b/Common/VR/VRFramebuffer.cpp index b01775c588..70f2ad02aa 100644 --- a/Common/VR/VRFramebuffer.cpp +++ b/Common/VR/VRFramebuffer.cpp @@ -166,7 +166,7 @@ void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer) { XrSwapchainImageWaitInfo waitInfo; waitInfo.type = XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO; waitInfo.next = NULL; - waitInfo.timeout = 1000; /* timeout in nanoseconds */ + waitInfo.timeout = 1000000; /* timeout in nanoseconds */ XrResult res = xrWaitSwapchainImage(frameBuffer->ColorSwapChain.Handle, &waitInfo); int i = 0; while ((res != XR_SUCCESS) && (i < 10)) { diff --git a/Common/VR/VRMath.h b/Common/VR/VRMath.h index c0ccb36aac..eb801ac73f 100644 --- a/Common/VR/VRMath.h +++ b/Common/VR/VRMath.h @@ -17,7 +17,7 @@ float ToRadians(float deg); // ovrMatrix4f float ovrMatrix4f_Minor(const ovrMatrix4f* m, int r0, int r1, int r2, int c0, int c1, int c2); ovrMatrix4f ovrMatrix4f_CreateFromQuaternion(const XrQuaternionf* q); -ovrMatrix4f ovrMatrix4f_CreateProjectionFov(const float fovDegreesX, const float fovDegreesY, const float offsetX, const float offsetY, const float nearZ, const float farZ); +ovrMatrix4f ovrMatrix4f_CreateProjectionFov(const float angleLeft, const float angleRight, const float angleUp, const float angleDown, const float nearZ, const float farZ); ovrMatrix4f ovrMatrix4f_CreateRotation(const float radiansX, const float radiansY, const float radiansZ); ovrMatrix4f ovrMatrix4f_Inverse(const ovrMatrix4f* m); ovrMatrix4f ovrMatrix4f_Multiply(const ovrMatrix4f* a, const ovrMatrix4f* b); diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index bc066035d2..1cc8dc06e1 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -462,17 +462,10 @@ void VR_BindFramebuffer(engine_t *engine) { ovrMatrix4f VR_GetMatrix( VRMatrix matrix ) { ovrMatrix4f output; - if (matrix == VR_PROJECTION_MATRIX_HUD) { - float hudScale = ToRadians(15.0f); - output = ovrMatrix4f_CreateProjectionFov(-hudScale, hudScale, hudScale, -hudScale, 1.0f, 0.0f ); - } else if ((matrix == VR_PROJECTION_MATRIX_LEFT_EYE) || (matrix == VR_PROJECTION_MATRIX_RIGHT_EYE)) { + if ((matrix == VR_PROJECTION_MATRIX_LEFT_EYE) || (matrix == VR_PROJECTION_MATRIX_RIGHT_EYE)) { XrFovf fov = matrix == VR_PROJECTION_MATRIX_LEFT_EYE ? projections[0].fov : projections[1].fov; - float fovScale = vrConfig[VR_CONFIG_FOV_SCALE] * 0.01f; - fov.angleLeft *= fovScale; - fov.angleRight *= fovScale; - fov.angleUp *= fovScale; - fov.angleDown *= fovScale; - output = ovrMatrix4f_CreateProjectionFov(fov.angleLeft, fov.angleRight, fov.angleUp, fov.angleDown, 1.0f, 0.0f ); + float near = (float)vrConfig[VR_CONFIG_FOV_SCALE] / 200.0f; + output = ovrMatrix4f_CreateProjectionFov(fov.angleLeft, fov.angleRight, fov.angleUp, fov.angleDown, near, 0.0f ); } else if ((matrix == VR_VIEW_MATRIX_LEFT_EYE) || (matrix == VR_VIEW_MATRIX_RIGHT_EYE)) { XrPosef invView = matrix == VR_VIEW_MATRIX_LEFT_EYE ? invViewTransform[0] : invViewTransform[1]; diff --git a/Common/VR/VRRenderer.h b/Common/VR/VRRenderer.h index abec8dfbaf..d5ef2bdc6d 100644 --- a/Common/VR/VRRenderer.h +++ b/Common/VR/VRRenderer.h @@ -26,11 +26,10 @@ enum VRConfig { }; enum VRMatrix { - VR_PROJECTION_MATRIX_HUD = 0, - VR_PROJECTION_MATRIX_LEFT_EYE = 1, - VR_PROJECTION_MATRIX_RIGHT_EYE = 2, - VR_VIEW_MATRIX_LEFT_EYE = 3, - VR_VIEW_MATRIX_RIGHT_EYE = 4 + VR_PROJECTION_MATRIX_LEFT_EYE = 0, + VR_PROJECTION_MATRIX_RIGHT_EYE = 1, + VR_VIEW_MATRIX_LEFT_EYE = 2, + VR_VIEW_MATRIX_RIGHT_EYE = 3 }; enum VRMode {