OpenXR - Automatically switch between fullscreen/VR

This commit is contained in:
Lubos 2022-07-26 17:20:46 +02:00
parent 9f31b3d507
commit 5c95fd244f
6 changed files with 41 additions and 30 deletions

View File

@ -10,6 +10,7 @@
#ifdef OPENXR
#include "VR/VRBase.h"
#include "VR/VRInput.h"
#include "VR/VRRenderer.h"
#endif
@ -209,6 +210,19 @@ bool GLRenderManager::ThreadFrame() {
return false;
#ifdef OPENXR
VR_BeginFrame(VR_GetEngine());
// Decide if the scene is 3D or not
if (VR_GeView3DCount() > 100) {
VR_SetMode(VR_MODE_MONO_6DOF);
} else {
VR_SetMode(VR_MODE_FLAT_SCREEN);
}
VR_SetView3DCount(VR_GeView3DCount() / 2);
// hack to quick enable 2D mode in game
if (IN_VRGetButtonState(0) & ovrButton_GripTrigger) {
VR_SetMode(VR_MODE_FLAT_SCREEN);
}
#endif
// In case of syncs or other partial completion, we keep going until we complete a frame.

View File

@ -51,6 +51,7 @@
#include "GPU/GLES/FramebufferManagerGLES.h"
#ifdef OPENXR
#include "VR/VRBase.h"
#include "VR/VRRenderer.h"
#endif
@ -314,11 +315,23 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu
render_->SetUniformUI1(&u_depal_mask_shift_off_fmt, val);
}
#ifdef OPENXR
bool is2D = true;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if ((i != j) && (fabs(gstate.projMatrix[i * 4 + j]) > 0.0001f)) {
VR_SetView3DCount(VR_GeView3DCount() + 1);
is2D = false;
}
}
}
#endif
// Update any dirty uniforms before we draw
if (dirty & DIRTY_PROJMATRIX) {
Matrix4x4 flippedMatrix;
#ifdef OPENXR
if (VR_GetMode() == VR_MODE_FLAT_SCREEN) {
if ((VR_GetMode() == VR_MODE_FLAT_SCREEN) || is2D) {
memcpy(&flippedMatrix, gstate.projMatrix, 16 * sizeof(float));
} else {
ovrMatrix4f hmdProjection = VR_GetMatrix(VR_PROJECTION_MATRIX_LEFT_EYE);
@ -484,7 +497,7 @@ void LinkedShader::UpdateUniforms(u32 vertType, const ShaderID &vsid, bool useBu
}
if (dirty & DIRTY_VIEWMATRIX) {
#ifdef OPENXR
if (VR_GetMode() == VR_MODE_FLAT_SCREEN) {
if ((VR_GetMode() == VR_MODE_FLAT_SCREEN) || is2D) {
SetMatrix4x3(render_, &u_view, gstate.viewMatrix);
} else {
// Get view matrix from the game

View File

@ -96,12 +96,6 @@ using namespace std::placeholders;
static AVIDump avi;
#endif
#ifdef OPENXR
#include <VR/VRBase.h>
#include <VR/VRInput.h>
#include <VR/VRRenderer.h>
#endif
// TODO: Ugly!
static bool frameStep_;
static int lastNumFlips;
@ -827,9 +821,6 @@ protected:
};
void EmuScreen::CreateViews() {
#ifdef OPENXR
VR_SetMode(VR_MODE_MONO_6DOF);
#endif
using namespace UI;
auto dev = GetI18NCategory("Developer");
@ -1014,17 +1005,6 @@ UI::EventReturn EmuScreen::OnReset(UI::EventParams &params) {
}
void EmuScreen::update() {
#ifdef OPENXR
// hack to quick enable 2D mode in game and adjust the view
bool leftPressed = IN_VRGetButtonState(0) & ovrButton_Left;
bool rightPressed = IN_VRGetButtonState(0) & ovrButton_Right;
bool gripPressed = IN_VRGetButtonState(0) & ovrButton_GripTrigger;
if (gripPressed && leftPressed) {
VR_SetMode(VR_MODE_FLAT_SCREEN);
} else if (gripPressed && rightPressed) {
VR_SetMode(VR_MODE_MONO_6DOF);
}
#endif
using namespace UI;
UIScreen::update();

View File

@ -48,10 +48,6 @@
#include "UI/OnScreenDisplay.h"
#include "UI/GameInfoCache.h"
#ifdef OPENXR
#include <VR/VRRenderer.h>
#endif
AsyncImageFileView::AsyncImageFileView(const Path &filename, UI::ImageSizeMode sizeMode, UI::LayoutParams *layoutParams)
: UI::Clickable(layoutParams), canFocus_(true), filename_(filename), color_(0xFFFFFFFF), sizeMode_(sizeMode), textureFailed_(false), fixedSizeW_(0.0f), fixedSizeH_(0.0f) {}
@ -368,10 +364,6 @@ GamePauseScreen::~GamePauseScreen() {
}
void GamePauseScreen::CreateViews() {
#ifdef OPENXR
VR_SetMode(VR_MODE_FLAT_SCREEN);
#endif
static const int NUM_SAVESLOTS = 5;
using namespace UI;

View File

@ -16,6 +16,7 @@ GLboolean initialized = GL_FALSE;
GLboolean stageSupported = GL_FALSE;
GLboolean viewInverted = GL_FALSE;
VRMode vrMode = VR_MODE_FLAT_SCREEN;
int view3DCount = 0;
float menuYaw = 0;
float recenterYaw = 0;
@ -434,6 +435,14 @@ VRMode VR_GetMode() {
return vrMode;
}
int VR_GeView3DCount() {
return view3DCount;
}
void VR_SetView3DCount( int value ) {
view3DCount = value;
}
void VR_BindFramebuffer( engine_t* engine, int eye ) {
if (!initialized) return;
ovrFramebuffer* frameBuffer = &engine->appState.Renderer.FrameBuffer[eye];

View File

@ -25,6 +25,9 @@ void VR_EndFrame( engine_t* engine );
void VR_SetMode( VRMode mode );
VRMode VR_GetMode();
int VR_GeView3DCount();
void VR_SetView3DCount( int value );
void VR_BindFramebuffer( engine_t* engine, int eye );
ovrMatrix4f VR_GetMatrix( VRMatrix matrix );
void VR_SetInvertedProjection( bool inverted );