From 428145c4b9d0f84cf105f284e6262f7658767930 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 15 Aug 2022 16:53:00 +0200 Subject: [PATCH 1/2] OpenXR - 2D mode hack mappable (using screen keycode) --- Common/GPU/OpenGL/GLRenderManager.cpp | 8 +------- Common/VR/VRRenderer.h | 1 + Core/KeyMapDefaults.cpp | 1 + UI/NativeApp.cpp | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index b1c60dbd22..c059585c1f 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -11,7 +11,6 @@ #ifdef OPENXR #include "Core/Config.h" #include "VR/VRBase.h" -#include "VR/VRInput.h" #include "VR/VRRenderer.h" #endif @@ -208,7 +207,7 @@ bool GLRenderManager::ThreadFrame() { VR_BeginFrame(VR_GetEngine()); // Decide if the scene is 3D or not - if (g_Config.bEnableVR && (VR_GetConfig(VR_CONFIG_3D_GEOMETRY_COUNT) > 15)) { + if (g_Config.bEnableVR && !VR_GetConfig(VR_CONFIG_FORCE_2D) && (VR_GetConfig(VR_CONFIG_3D_GEOMETRY_COUNT) > 15)) { VR_SetConfig(VR_CONFIG_MODE, VR_MODE_MONO_6DOF); } else { VR_SetConfig(VR_CONFIG_MODE, VR_MODE_FLAT_SCREEN); @@ -218,11 +217,6 @@ bool GLRenderManager::ThreadFrame() { // Set customizations VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF); VR_SetConfig(VR_CONFIG_FOV_SCALE, g_Config.iFieldOfViewPercentage); - - // hack to quick enable 2D mode in game - if (IN_VRGetButtonState(0) & ovrButton_GripTrigger) { - VR_SetConfig(VR_CONFIG_MODE, VR_MODE_FLAT_SCREEN); - } #endif // In case of syncs or other partial completion, we keep going until we complete a frame. diff --git a/Common/VR/VRRenderer.h b/Common/VR/VRRenderer.h index 3e41a0bef5..853642a5e1 100644 --- a/Common/VR/VRRenderer.h +++ b/Common/VR/VRRenderer.h @@ -15,6 +15,7 @@ enum VRConfig { VR_CONFIG_MIRROR_ROLL, VR_CONFIG_3D_GEOMETRY_COUNT, VR_CONFIG_FOV_SCALE, + VR_CONFIG_FORCE_2D, VR_CONFIG_MAX }; diff --git a/Core/KeyMapDefaults.cpp b/Core/KeyMapDefaults.cpp index d4aa8b13e0..d6d21639cb 100644 --- a/Core/KeyMapDefaults.cpp +++ b/Core/KeyMapDefaults.cpp @@ -317,6 +317,7 @@ static const DefMappingStruct defaultVRLeftController[] = { {CTRL_SELECT , NKCODE_BUTTON_THUMBL}, {CTRL_LTRIGGER , NKCODE_BUTTON_X}, {CTRL_RTRIGGER , NKCODE_BUTTON_Y}, + {CTRL_SCREEN , NKCODE_ALT_LEFT}, }; static const DefMappingStruct defaultVRRightController[] = { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index cc1e08ff4d..d740c323bc 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -142,6 +142,10 @@ #include #endif +#ifdef OPENXR +#include "VR/VRRenderer.h" +#endif + ScreenManager *screenManager; std::string config_filename; @@ -1297,6 +1301,19 @@ bool NativeTouch(const TouchInput &touch) { } bool NativeKey(const KeyInput &key) { + + // Hack to quick enable 2D mode in VR game mode. +#ifdef OPENXR + std::vector nativeKeys; + if (KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &nativeKeys)) { + for (int& nativeKey : nativeKeys) { + if (nativeKey == CTRL_SCREEN) { + VR_SetConfig(VR_CONFIG_FORCE_2D, key.flags & KEY_DOWN); + } + } + } +#endif + // INFO_LOG(SYSTEM, "Key code: %i flags: %i", key.keyCode, key.flags); #if !defined(MOBILE_DEVICE) if (g_Config.bPauseExitsEmulator) { From 70c4781febd469e76fa5aba6410a3fbe375e32a3 Mon Sep 17 00:00:00 2001 From: Lubos Date: Mon, 15 Aug 2022 17:19:42 +0200 Subject: [PATCH 2/2] OpenXR - Option to set canvas distance added --- Common/GPU/OpenGL/GLRenderManager.cpp | 1 + Common/VR/VRRenderer.cpp | 5 +++-- Common/VR/VRRenderer.h | 1 + Core/Config.cpp | 1 + Core/Config.h | 1 + UI/GameSettingsScreen.cpp | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Common/GPU/OpenGL/GLRenderManager.cpp b/Common/GPU/OpenGL/GLRenderManager.cpp index c059585c1f..c78ac13c5b 100644 --- a/Common/GPU/OpenGL/GLRenderManager.cpp +++ b/Common/GPU/OpenGL/GLRenderManager.cpp @@ -216,6 +216,7 @@ bool GLRenderManager::ThreadFrame() { // 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); #endif diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index f772fe283e..1a17cb9f1b 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -383,11 +383,12 @@ void VR_EndFrame( engine_t* engine ) { cylinder_layer.subImage.imageRect.extent.width = width; cylinder_layer.subImage.imageRect.extent.height = height; cylinder_layer.subImage.imageArrayIndex = 0; + float distance = vrConfig[VR_CONFIG_CANVAS_DISTANCE]; const XrVector3f axis = {0.0f, 1.0f, 0.0f}; XrVector3f pos = { - invViewTransform[0].position.x - sin(ToRadians(menuYaw)) * 6.0f, + invViewTransform[0].position.x - sin(ToRadians(menuYaw)) * distance, invViewTransform[0].position.y, - invViewTransform[0].position.z - cos(ToRadians(menuYaw)) * 6.0f + invViewTransform[0].position.z - cos(ToRadians(menuYaw)) * distance }; cylinder_layer.pose.orientation = XrQuaternionf_CreateFromVectorAngle(axis, ToRadians(menuYaw)); cylinder_layer.pose.position = pos; diff --git a/Common/VR/VRRenderer.h b/Common/VR/VRRenderer.h index 853642a5e1..721342252c 100644 --- a/Common/VR/VRRenderer.h +++ b/Common/VR/VRRenderer.h @@ -16,6 +16,7 @@ enum VRConfig { VR_CONFIG_3D_GEOMETRY_COUNT, VR_CONFIG_FOV_SCALE, VR_CONFIG_FORCE_2D, + VR_CONFIG_CANVAS_DISTANCE, VR_CONFIG_MAX }; diff --git a/Core/Config.cpp b/Core/Config.cpp index 580f8cd820..f8de2c8d1f 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1208,6 +1208,7 @@ static ConfigSetting themeSettings[] = { static ConfigSetting vrSettings[] = { ConfigSetting("VREnable", &g_Config.bEnableVR, true), ConfigSetting("VREnable6DoF", &g_Config.bEnable6DoF, true), + ConfigSetting("VRCanvasDistance", &g_Config.iCanvasDistance, 6), ConfigSetting("VRFieldOfView", &g_Config.iFieldOfViewPercentage, 100), }; diff --git a/Core/Config.h b/Core/Config.h index cdb0bbfff2..125792f5fa 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -456,6 +456,7 @@ public: // Virtual reality bool bEnableVR; bool bEnable6DoF; + int iCanvasDistance; int iFieldOfViewPercentage; // Debugger diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 27b6217155..5ee05d8bec 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1119,6 +1119,7 @@ void GameSettingsScreen::CreateViews() { vr6DoF->SetEnabledPtr(&g_Config.bEnableVR); PopupSliderChoice *vrFieldOfView = vrSettings->Add(new PopupSliderChoice(&g_Config.iFieldOfViewPercentage, 100, 150, vr->T("Field of view scale", "Headset's field of view scale"), 10, screenManager(), vr->T("% of native FoV"))); vrFieldOfView->SetEnabledPtr(&g_Config.bEnableVR); + vrSettings->Add(new PopupSliderChoice(&g_Config.iCanvasDistance, 1, 10, vr->T("Distance to 2D menus and scenes", "Distance to 2D menus and scenes"), 1, screenManager(), "")); } }