From 15af767e25a03901db4f754215a343c14d9412e6 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 24 Jun 2024 17:26:38 +0200 Subject: [PATCH] OpenXR - SBS support prepared --- Common/VR/PPSSPPVR.cpp | 6 ++++-- Common/VR/VRRenderer.cpp | 22 ++++++++++++++++++---- Common/VR/VRRenderer.h | 2 ++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index ff6fd60f6f..173243fda9 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -670,11 +670,13 @@ bool StartVRRender() { if (g_Config.bEnableVR && !vrIncompatibleGame && (appMode == VR_GAME_MODE) && vrScene) { VR_SetConfig(VR_CONFIG_MODE, vrStereo ? VR_MODE_STEREO_6DOF : VR_MODE_MONO_6DOF); vrFlatGame = false; - } else { + } else if (appMode == VR_GAME_MODE) { VR_SetConfig(VR_CONFIG_MODE, vrStereo ? VR_MODE_STEREO_SCREEN : VR_MODE_MONO_SCREEN); if (IsGameVRScene()) { vrFlatGame = true; } + } else { + VR_SetConfig(VR_CONFIG_MODE, VR_MODE_MONO_SCREEN); } vr3DGeometryCount /= 2; @@ -709,7 +711,7 @@ int GetVRFBOIndex() { int GetVRPassesCount() { bool vrStereo = !PSP_CoreParameter().compat.vrCompat().ForceMono && g_Config.bEnableStereo; - return vrStereo ? 2 : 1; + return vrStereo ? 2 : 1; } bool IsPassthroughSupported() { diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index f9a55fcb5f..441eac8f8b 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -384,14 +384,14 @@ void VR_EndFrame( engine_t* engine ) { void VR_FinishFrame( engine_t* engine ) { int vrMode = vrConfig[VR_CONFIG_MODE]; XrCompositionLayerProjectionView projection_layer_elements[2] = {}; - if ((vrMode == VR_MODE_MONO_6DOF) || (vrMode == VR_MODE_STEREO_6DOF)) { + if ((vrMode == VR_MODE_MONO_6DOF) || (vrMode == VR_MODE_SBS_6DOF) || (vrMode == VR_MODE_STEREO_6DOF)) { VR_SetConfigFloat(VR_CONFIG_MENU_YAW, hmdorientation.y); for (int eye = 0; eye < ovrMaxNumEyes; eye++) {; ovrFramebuffer* frameBuffer = &engine->appState.Renderer.FrameBuffer[0]; XrPosef pose = invViewTransform[0]; - if (vrMode != VR_MODE_MONO_6DOF) { - frameBuffer = &engine->appState.Renderer.FrameBuffer[eye]; + if (vrMode == VR_MODE_STEREO_6DOF) { + frameBuffer = &engine->appState.Renderer.FrameBuffer[eye]; pose = invViewTransform[eye]; } @@ -407,6 +407,13 @@ void VR_FinishFrame( engine_t* engine ) { projection_layer_elements[eye].subImage.imageRect.extent.width = frameBuffer->ColorSwapChain.Width; projection_layer_elements[eye].subImage.imageRect.extent.height = frameBuffer->ColorSwapChain.Height; projection_layer_elements[eye].subImage.imageArrayIndex = 0; + + if (vrMode == VR_MODE_SBS_6DOF) { + projection_layer_elements[eye].subImage.imageRect.extent.width /= 2; + if (eye == 1) { + projection_layer_elements[eye].subImage.imageRect.offset.x += frameBuffer->ColorSwapChain.Width / 2; + } + } } XrCompositionLayerProjection projection_layer = {}; @@ -418,7 +425,7 @@ void VR_FinishFrame( engine_t* engine ) { projection_layer.views = projection_layer_elements; engine->appState.Layers[engine->appState.LayerCount++].Projection = projection_layer; - } else if ((vrMode == VR_MODE_MONO_SCREEN) || (vrMode == VR_MODE_STEREO_SCREEN)) { + } else if ((vrMode == VR_MODE_MONO_SCREEN) || (vrMode == VR_MODE_SBS_SCREEN) || (vrMode == VR_MODE_STEREO_SCREEN)) { // Flat screen pose float distance = VR_GetConfigFloat(VR_CONFIG_CANVAS_DISTANCE) / 4.0f - 1.0f; @@ -455,6 +462,13 @@ void VR_FinishFrame( engine_t* engine ) { if (vrMode == VR_MODE_MONO_SCREEN) { cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH; engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer; + } else if (vrMode == VR_MODE_SBS_SCREEN) { + cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_LEFT; + cylinder_layer.subImage.imageRect.extent.width /= 2; + engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer; + cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_RIGHT; + cylinder_layer.subImage.imageRect.offset.x += cylinder_layer.subImage.imageRect.extent.width; + engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer; } else { cylinder_layer.eyeVisibility = XR_EYE_VISIBILITY_LEFT; engine->appState.Layers[engine->appState.LayerCount++].Cylinder = cylinder_layer; diff --git a/Common/VR/VRRenderer.h b/Common/VR/VRRenderer.h index a86a859219..6c86761730 100644 --- a/Common/VR/VRRenderer.h +++ b/Common/VR/VRRenderer.h @@ -27,8 +27,10 @@ enum VRConfigFloat { enum VRMode { VR_MODE_MONO_SCREEN, + VR_MODE_SBS_SCREEN, VR_MODE_STEREO_SCREEN, VR_MODE_MONO_6DOF, + VR_MODE_SBS_6DOF, VR_MODE_STEREO_6DOF };