diff --git a/Common/TimeUtil.cpp b/Common/TimeUtil.cpp index ad00e1e9a7..ad07fbd18c 100644 --- a/Common/TimeUtil.cpp +++ b/Common/TimeUtil.cpp @@ -21,8 +21,6 @@ // TODO: https://github.com/floooh/sokol/blob/9a6237fcdf213e6da48e4f9201f144bcb2dcb46f/sokol_time.h#L229-L248 -static double curtime = 0; - #ifdef _WIN32 static LARGE_INTEGER frequency; @@ -33,7 +31,6 @@ double time_now_d() { if (frequency.QuadPart == 0) { QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&startTime); - curtime = 0.0; frequencyMult = 1.0 / static_cast(frequency.QuadPart); } LARGE_INTEGER time; diff --git a/Common/VR/VRBase.h b/Common/VR/VRBase.h index b0d7b09f81..40c377ec84 100644 --- a/Common/VR/VRBase.h +++ b/Common/VR/VRBase.h @@ -1,6 +1,5 @@ #pragma once -// TODO: Switch to PPSSPP logging #ifdef ANDROID #include #define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, "OpenXR", __VA_ARGS__); diff --git a/Common/VR/VRFramebuffer.cpp b/Common/VR/VRFramebuffer.cpp index 2d9db6c3fc..3cf70642a9 100644 --- a/Common/VR/VRFramebuffer.cpp +++ b/Common/VR/VRFramebuffer.cpp @@ -8,7 +8,7 @@ #include #include -#ifdef ANDROID +#if !defined(_WIN32) #include #include #endif @@ -253,7 +253,7 @@ void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) { delete[] frameBuffer->VKDepthImages; delete[] frameBuffer->VKFrameBuffers; } else { -#ifdef ANDROID +#ifdef XR_USE_GRAPHICS_API_OPENGL_ES GL(glDeleteFramebuffers(frameBuffer->TextureSwapChainLength, frameBuffer->GLFrameBuffers)); free(frameBuffer->GLFrameBuffers); #endif @@ -270,7 +270,7 @@ void* ovrFramebuffer_SetCurrent(ovrFramebuffer* frameBuffer) { if (frameBuffer->UseVulkan) { return (void *)frameBuffer->VKFrameBuffers[frameBuffer->TextureSwapChainIndex]; } else { -#ifdef ANDROID +#ifdef XR_USE_GRAPHICS_API_OPENGL_ES GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->GLFrameBuffers[frameBuffer->TextureSwapChainIndex])); #endif return nullptr; @@ -302,7 +302,7 @@ void ovrFramebuffer_Acquire(ovrFramebuffer* frameBuffer) { if (frameBuffer->UseVulkan) { //TODO:implement } else { -#ifdef ANDROID +#ifdef XR_USE_GRAPHICS_API_OPENGL_ES GL(glEnable( GL_SCISSOR_TEST )); GL(glViewport( 0, 0, frameBuffer->Width, frameBuffer->Height )); GL(glClearColor( 0.0f, 0.0f, 0.0f, 1.0f )); @@ -324,7 +324,7 @@ void ovrFramebuffer_Release(ovrFramebuffer* frameBuffer) { if (frameBuffer->UseVulkan) { //TODO:implement } else { -#ifdef ANDROID +#ifdef XR_USE_GRAPHICS_API_OPENGL_ES GL(glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE)); GL(glClearColor(0.0f, 0.0f, 0.0f, 1.0f)); GL(glClear(GL_COLOR_BUFFER_BIT)); @@ -355,7 +355,7 @@ void ovrRenderer_Create(XrSession session, ovrRenderer* renderer, int width, int if (vulkanContext) { ovrFramebuffer_CreateVK(session, &renderer->FrameBuffer[i], width, height, multiview, vulkanContext); } else { -#ifdef ANDROID +#ifdef XR_USE_GRAPHICS_API_OPENGL_ES ovrFramebuffer_CreateGL(session, &renderer->FrameBuffer[i], width, height, multiview); #endif } @@ -373,7 +373,7 @@ void ovrRenderer_MouseCursor(ovrRenderer* renderer, int x, int y, int size) { if (renderer->FrameBuffer[0].UseVulkan) { //TODO:implement } else { -#ifdef ANDROID +#ifdef XR_USE_GRAPHICS_API_OPENGL_ES GL(glEnable(GL_SCISSOR_TEST)); GL(glScissor(x, y, size, size)); GL(glViewport(x, y, size, size)); @@ -433,6 +433,8 @@ void ovrApp_HandleSessionStateChanges(ovrApp* app, XrSessionState state) { app->SessionActive = (result == XR_SUCCESS); // Set session state once we have entered VR mode and have a valid session object. + + // TODO: This should be a runtime check of the extension's presence, no? #ifdef OPENXR_HAS_PERFORMANCE_EXTENSION if (app->SessionActive) { XrPerfSettingsLevelEXT cpuPerfLevel = XR_PERF_SETTINGS_LEVEL_BOOST_EXT; diff --git a/Common/VR/VRFramebuffer.h b/Common/VR/VRFramebuffer.h index 5dd455fd16..7440e49d70 100644 --- a/Common/VR/VRFramebuffer.h +++ b/Common/VR/VRFramebuffer.h @@ -1,6 +1,6 @@ #pragma once -#include "Common/VR/VRBase.h" +#include "VRBase.h" void ovrApp_Clear(ovrApp* app); void ovrApp_Destroy(ovrApp* app); diff --git a/Common/VR/VRInput.cpp b/Common/VR/VRInput.cpp index 313f9f1d9b..58571b47f1 100644 --- a/Common/VR/VRInput.cpp +++ b/Common/VR/VRInput.cpp @@ -1,7 +1,5 @@ #include "VRInput.h" -#include - -#include +#include #ifdef OPENXR @@ -41,11 +39,39 @@ XrActionStateVector2f moveJoystickState[2]; float vibration_channel_duration[2] = {0.0f, 0.0f}; float vibration_channel_intensity[2] = {0.0f, 0.0f}; - +#if !defined(_WIN32) unsigned long sys_timeBase = 0; int milliseconds(void) { - return (int)(1000.0 * time_now_d()); + struct timeval tp; + + gettimeofday(&tp, NULL); + + if (!sys_timeBase) { + sys_timeBase = tp.tv_sec; + return tp.tv_usec / 1000; + } + + return (tp.tv_sec - sys_timeBase) * 1000 + tp.tv_usec / 1000; } +#else + +static LARGE_INTEGER frequency; +static double frequencyMult; +static LARGE_INTEGER startTime; + +int milliseconds() { + if (frequency.QuadPart == 0) { + QueryPerformanceFrequency(&frequency); + QueryPerformanceCounter(&startTime); + frequencyMult = 1.0 / static_cast(frequency.QuadPart); + } + LARGE_INTEGER time; + QueryPerformanceCounter(&time); + double elapsed = static_cast(time.QuadPart - startTime.QuadPart); + return (int)(elapsed * frequencyMult * 1000.0); +} + +#endif XrTime ToXrTime(const double timeInSeconds) { return (XrTime)(timeInSeconds * 1e9); diff --git a/Common/VR/VRMath.cpp b/Common/VR/VRMath.cpp index df9512d186..bafdff75ea 100644 --- a/Common/VR/VRMath.cpp +++ b/Common/VR/VRMath.cpp @@ -1,10 +1,9 @@ +#define _USE_MATH_DEFINES + #include #include "VRMath.h" -#include "Common/Math/math_util.h" - - float ToDegrees(float rad) { return (float)(rad / M_PI * 180.0f); } diff --git a/Common/VR/VRRenderer.cpp b/Common/VR/VRRenderer.cpp index 60db7063e1..d4b35c596d 100644 --- a/Common/VR/VRRenderer.cpp +++ b/Common/VR/VRRenderer.cpp @@ -2,8 +2,6 @@ #include "VRInput.h" #include "VRRenderer.h" -#include "Common/Math/math_util.h" - #include #include #include