From 63a141dc5438a4adf2713e012a0ff8ce0c926237 Mon Sep 17 00:00:00 2001 From: Ben Ferguson Date: Sat, 14 Nov 2020 09:21:01 -0500 Subject: [PATCH 01/26] Add Quest 2 90hz to android manifest --- src/resources/AndroidManifest_oculus.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/resources/AndroidManifest_oculus.xml b/src/resources/AndroidManifest_oculus.xml index 18307554..b24478e5 100644 --- a/src/resources/AndroidManifest_oculus.xml +++ b/src/resources/AndroidManifest_oculus.xml @@ -9,6 +9,7 @@ + From ceaac7843919aaa112537510b81815e26b2c7e69 Mon Sep 17 00:00:00 2001 From: Josip Miskovic Date: Mon, 16 Nov 2020 19:03:52 +0100 Subject: [PATCH 02/26] Fix NaN return from mat4 unpacking The caluclated angle is forced to PI if cos(angle) falls outside the [-1, +1] range due to floating point precision error. --- src/core/maf.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/maf.h b/src/core/maf.h index aef621b8..8aaa7a69 100644 --- a/src/core/maf.h +++ b/src/core/maf.h @@ -1,5 +1,6 @@ #include #include +#include #include "util.h" #pragma once @@ -534,7 +535,12 @@ MAF void mat4_getAngleAxis(mat4 m, float* angle, float* ax, float* ay, float* az diagonal[1] /= sy; diagonal[2] /= sz; vec3_normalize(axis); - *angle = acosf((diagonal[0] + diagonal[1] + diagonal[2] - 1.f) / 2.f); + float cosangle = (diagonal[0] + diagonal[1] + diagonal[2] - 1.f) / 2.f; + if (fabsf(cosangle) < 1.f - FLT_EPSILON) { + *angle = acosf(cosangle); + } else { + *angle = (float) M_PI; + } *ax = axis[0]; *ay = axis[1]; *az = axis[2]; From c6b49813894492d2e25f533328de46c2d2531fd4 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 12 Oct 2020 16:39:56 -0600 Subject: [PATCH 03/26] Fix OpenXR view matrix; --- src/modules/headset/headset_openxr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/headset/headset_openxr.c b/src/modules/headset/headset_openxr.c index 832504a0..bdbe9a95 100644 --- a/src/modules/headset/headset_openxr.c +++ b/src/modules/headset/headset_openxr.c @@ -803,7 +803,7 @@ static void openxr_renderTo(void (*callback)(void*), void* userdata) { float viewMatrix[16]; XrView* view = &views[eye]; mat4_fromQuat(viewMatrix, &view->pose.orientation.x); - memcpy(viewMatrix, &view->pose.position.x, 3 * sizeof(float)); + memcpy(viewMatrix + 12, &view->pose.position.x, 3 * sizeof(float)); mat4_invert(viewMatrix); lovrGraphicsSetViewMatrix(eye, viewMatrix); From 40c403dfb670b42fccf3ad348d281a393d6282f3 Mon Sep 17 00:00:00 2001 From: bjornbytes Date: Sat, 24 Oct 2020 16:16:57 -0600 Subject: [PATCH 04/26] CMake: Add LOVR_SYSTEM_OPENXR; Searches for the system-installed OpenXR loader using pkg-config. --- CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c0845ad..ed0c7f53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ option(LOVR_SYSTEM_GLFW "Use the system-provided glfw" OFF) option(LOVR_SYSTEM_LUA "Use the system-provided Lua" OFF) option(LOVR_SYSTEM_ODE "Use the system-provided ODE" OFF) option(LOVR_SYSTEM_OPENAL "Use the system-provided OpenAL" OFF) +option(LOVR_SYSTEM_OPENXR "Use the system-provided OpenXR" OFF) option(LOVR_BUILD_EXE "Build an executable (or an apk on Android)" ON) option(LOVR_BUILD_SHARED "Build a shared library (takes precedence over LOVR_BUILD_EXE)" OFF) @@ -244,8 +245,17 @@ if(LOVR_ENABLE_HEADSET AND LOVR_USE_OPENXR) set_target_properties(openxr_loader PROPERTIES IMPORTED_LOCATION "${LOVR_OPENXR_OCULUS_PATH}/Libs/Android/${ANDROID_ABI}/Release/libopenxr_loader.so") set(LOVR_OPENXR openxr_loader) else() - add_subdirectory(deps/openxr openxr) - set(LOVR_OPENXR openxr_loader) + if(LOVR_SYSTEM_OPENXR) + pkg_search_module(OPENXR openxr) + if(NOT OPENXR_FOUND) + message(FATAL_ERROR "OpenXR not found.") + endif() + include_directories(${OPENXR_INCLUDE_DIRS}) + set(LOVR_OPENXR ${OPENXR_LIBRARIES}) + else() + add_subdirectory(deps/openxr openxr) + set(LOVR_OPENXR openxr_loader) + endif() endif() endif() From 94e7bafe47229c1b8ba17fd8b7a6e4a9a74497d5 Mon Sep 17 00:00:00 2001 From: bjornbytes Date: Sun, 25 Oct 2020 13:11:46 -0600 Subject: [PATCH 05/26] KeyCode -> KeyboardKey because X11 conflict; --- src/api/l_event.c | 6 +++--- src/core/os.h | 6 +++--- src/core/os_android.c | 4 ++-- src/core/os_glfw.h | 8 ++++---- src/core/os_web.c | 4 ++-- src/modules/event/event.c | 2 +- src/modules/headset/headset_pico.c | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/api/l_event.c b/src/api/l_event.c index d5dd2b21..47613f32 100644 --- a/src/api/l_event.c +++ b/src/api/l_event.c @@ -21,7 +21,7 @@ StringEntry lovrEventType[] = { { 0 } }; -StringEntry lovrKeyCode[] = { +StringEntry lovrKeyboardKey[] = { [KEY_A] = ENTRY("a"), [KEY_B] = ENTRY("b"), [KEY_C] = ENTRY("c"), @@ -205,13 +205,13 @@ static int nextEvent(lua_State* L) { return 3; case EVENT_KEYPRESSED: - luax_pushenum(L, KeyCode, event.data.key.code); + luax_pushenum(L, KeyboardKey, event.data.key.code); lua_pushinteger(L, event.data.key.scancode); lua_pushboolean(L, event.data.key.repeat); return 4; case EVENT_KEYRELEASED: - luax_pushenum(L, KeyCode, event.data.key.code); + luax_pushenum(L, KeyboardKey, event.data.key.code); lua_pushinteger(L, event.data.key.scancode); return 3; diff --git a/src/core/os.h b/src/core/os.h index bd26d53d..add5c14f 100644 --- a/src/core/os.h +++ b/src/core/os.h @@ -122,7 +122,7 @@ typedef enum { KEY_NUM_LOCK, KEY_COUNT -} KeyCode; +} KeyboardKey; typedef enum { BUTTON_PRESSED, @@ -133,7 +133,7 @@ typedef void (*quitCallback)(void); typedef void (*windowFocusCallback)(bool focused); typedef void (*windowResizeCallback)(int width, int height); typedef void (*mouseButtonCallback)(MouseButton button, ButtonAction action); -typedef void (*keyboardCallback)(ButtonAction action, KeyCode key, uint32_t scancode, bool repeat); +typedef void (*keyboardCallback)(ButtonAction action, KeyboardKey key, uint32_t scancode, bool repeat); typedef void (*textCallback)(uint32_t codepoint); bool lovrPlatformInit(void); @@ -165,4 +165,4 @@ void lovrPlatformOnTextEvent(textCallback callback); void lovrPlatformGetMousePosition(double* x, double* y); void lovrPlatformSetMouseMode(MouseMode mode); bool lovrPlatformIsMouseDown(MouseButton button); -bool lovrPlatformIsKeyDown(KeyCode key); +bool lovrPlatformIsKeyDown(KeyboardKey key); diff --git a/src/core/os_android.c b/src/core/os_android.c index c22bfc05..e1846264 100644 --- a/src/core/os_android.c +++ b/src/core/os_android.c @@ -42,7 +42,7 @@ static int32_t onInputEvent(struct android_app* app, AInputEvent* event) { default: return 0; } - KeyCode key; + KeyboardKey key; switch (AKeyEvent_getKeyCode(event)) { case AKEYCODE_A: key = KEY_A; break; case AKEYCODE_B: key = KEY_B; break; @@ -466,7 +466,7 @@ bool lovrPlatformIsMouseDown(MouseButton button) { return false; } -bool lovrPlatformIsKeyDown(KeyCode key) { +bool lovrPlatformIsKeyDown(KeyboardKey key) { return false; } diff --git a/src/core/os_glfw.h b/src/core/os_glfw.h index 1d786724..b3be66a1 100644 --- a/src/core/os_glfw.h +++ b/src/core/os_glfw.h @@ -53,7 +53,7 @@ static void onMouseButton(GLFWwindow* window, int b, int a, int mods) { static void onKeyboardEvent(GLFWwindow* window, int k, int scancode, int a, int mods) { if (glfwState.onKeyboardEvent) { - KeyCode key; + KeyboardKey key; switch (k) { case GLFW_KEY_A: key = KEY_A; break; case GLFW_KEY_B: key = KEY_B; break; @@ -167,7 +167,7 @@ static int convertMouseButton(MouseButton button) { } } -static int convertKeyCode(KeyCode key) { +static int convertKey(KeyboardKey key) { switch (key) { case KEY_W: return GLFW_KEY_W; case KEY_A: return GLFW_KEY_A; @@ -332,8 +332,8 @@ bool lovrPlatformIsMouseDown(MouseButton button) { return glfwState.window ? glfwGetMouseButton(glfwState.window, convertMouseButton(button)) == GLFW_PRESS : false; } -bool lovrPlatformIsKeyDown(KeyCode key) { - return glfwState.window ? glfwGetKey(glfwState.window, convertKeyCode(key)) == GLFW_PRESS : false; +bool lovrPlatformIsKeyDown(KeyboardKey key) { + return glfwState.window ? glfwGetKey(glfwState.window, convertKey(key)) == GLFW_PRESS : false; } #ifdef _WIN32 diff --git a/src/core/os_web.c b/src/core/os_web.c index fd97888f..e7048ada 100644 --- a/src/core/os_web.c +++ b/src/core/os_web.c @@ -89,7 +89,7 @@ static EM_BOOL onMouseMove(int type, const EmscriptenMouseEvent* data, void* use } static EM_BOOL onKeyEvent(int type, const EmscriptenKeyboardEvent* data, void* userdata) { - KeyCode key; + KeyboardKey key; DOM_PK_CODE_TYPE scancode = emscripten_compute_dom_pk_code(data->code); switch (scancode) { case DOM_PK_ESCAPE: key = KEY_ESCAPE; break; @@ -359,6 +359,6 @@ bool lovrPlatformIsMouseDown(MouseButton button) { return state.mouseMap[button]; } -bool lovrPlatformIsKeyDown(KeyCode key) { +bool lovrPlatformIsKeyDown(KeyboardKey key) { return state.keyMap[key]; } diff --git a/src/modules/event/event.c b/src/modules/event/event.c index c6d94c7a..8f678d70 100644 --- a/src/modules/event/event.c +++ b/src/modules/event/event.c @@ -14,7 +14,7 @@ static struct { size_t head; } state; -static void onKeyboardEvent(ButtonAction action, KeyCode key, uint32_t scancode, bool repeat) { +static void onKeyboardEvent(ButtonAction action, KeyboardKey key, uint32_t scancode, bool repeat) { lovrEventPush((Event) { .type = action == BUTTON_PRESSED ? EVENT_KEYPRESSED : EVENT_KEYRELEASED, .data.key.code = key, diff --git a/src/modules/headset/headset_pico.c b/src/modules/headset/headset_pico.c index 56612505..7d45eb93 100644 --- a/src/modules/headset/headset_pico.c +++ b/src/modules/headset/headset_pico.c @@ -189,7 +189,7 @@ bool lovrPlatformIsMouseDown(MouseButton button) { return false; } -bool lovrPlatformIsKeyDown(KeyCode key) { +bool lovrPlatformIsKeyDown(KeyboardKey key) { return false; } From ca04882093bb1c8a926ea8076b788460d5ec7c74 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 24 Oct 2020 19:29:25 +0100 Subject: [PATCH 06/26] OpenXR: Add support for X11 and EGL on Linux --- CMakeLists.txt | 9 ++- src/core/os_glfw.h | 83 ++++++++++++++++++++++++++-- src/modules/headset/headset_openxr.c | 45 +++++++++++++++ 3 files changed, 131 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed0c7f53..68c65837 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ option(LOVR_USE_OCULUS "Enable the LibOVR backend for the headset module (be sur option(LOVR_USE_VRAPI "Enable the VrApi backend for the headset module" OFF) option(LOVR_USE_PICO "Enable the Pico backend for the headset module" OFF) option(LOVR_USE_DESKTOP_HEADSET "Enable the keyboard/mouse backend for the headset module" ON) +option(LOVR_USE_LINUX_EGL "Use the EGL graphics extension on Linux" OFF) option(LOVR_SYSTEM_ENET "Use the system-provided enet" OFF) option(LOVR_SYSTEM_GLFW "Use the system-provided glfw" OFF) @@ -698,6 +699,12 @@ elseif(ANDROID) ) endif() elseif(UNIX) - target_sources(lovr PRIVATE src/core/os_linux.c) + if(LOVR_USE_LINUX_EGL) + target_sources(lovr PRIVATE src/core/os_linux.c) + target_compile_definitions(lovr PRIVATE -DLOVR_LINUX_EGL) + else() + target_sources(lovr PRIVATE src/core/os_linux.c) + target_compile_definitions(lovr PRIVATE -DLOVR_LINUX_X11) + endif() target_compile_definitions(lovr PRIVATE -DLOVR_GL) endif() diff --git a/src/core/os_glfw.h b/src/core/os_glfw.h index b3be66a1..88109c80 100644 --- a/src/core/os_glfw.h +++ b/src/core/os_glfw.h @@ -2,12 +2,26 @@ #define GLFW_INCLUDE_NONE #include + #ifndef EMSCRIPTEN -#ifdef _WIN32 -#define GLFW_EXPOSE_NATIVE_WIN32 -#define GLFW_EXPOSE_NATIVE_WGL -#endif -#include +# ifdef _WIN32 +# define GLFW_EXPOSE_NATIVE_WIN32 +# define GLFW_EXPOSE_NATIVE_WGL +# endif +# ifdef _WIN32 +# define GLFW_EXPOSE_NATIVE_WIN32 +# define GLFW_EXPOSE_NATIVE_WGL +# endif +# ifdef LOVR_LINUX_EGL +# define EGL_NO_X11 +# include +# define GLFW_EXPOSE_NATIVE_EGL +# endif +# ifdef LOVR_LINUX_X11 +# define GLFW_EXPOSE_NATIVE_X11 +# define GLFW_EXPOSE_NATIVE_GLX +# endif +# include #endif static struct { @@ -204,12 +218,18 @@ bool lovrPlatformCreateWindow(const WindowFlags* flags) { return false; } + +#ifdef LOVR_LINUX_EGL + glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); +#endif glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, flags->debug); +#ifndef LOVR_LINUX_EGL glfwWindowHint(GLFW_CONTEXT_NO_ERROR, !flags->debug); +#endif glfwWindowHint(GLFW_SAMPLES, flags->msaa); glfwWindowHint(GLFW_RESIZABLE, flags->resizable); glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE); @@ -345,3 +365,56 @@ HGLRC lovrPlatformGetContext() { return glfwGetWGLContext(glfwState.window); } #endif + +#ifdef LOVR_LINUX_EGL +PFNEGLGETPROCADDRESSPROC lovrPlatformGetEGLProcAddr(void) +{ + return (PFNEGLGETPROCADDRESSPROC)glfwGetProcAddress; +} + +EGLDisplay lovrPlatformGetEGLDisplay(void) +{ + return glfwGetEGLDisplay(); +} + +EGLContext lovrPlatformGetEGLContext(void) +{ + return glfwGetEGLContext(glfwState.window); +} + +EGLConfig lovrPlatformGetEGLConfig(void) +{ + EGLDisplay dpy = lovrPlatformGetEGLDisplay(); + EGLContext ctx = lovrPlatformGetEGLContext(); + EGLint cfg_id = -1; + EGLint num_cfgs = -1; + EGLConfig cfg = NULL; + PFNEGLQUERYCONTEXTPROC eglQueryContext = (PFNEGLQUERYCONTEXTPROC)glfwGetProcAddress("eglQueryContext"); + PFNEGLCHOOSECONFIGPROC eglChooseConfig = (PFNEGLCHOOSECONFIGPROC)glfwGetProcAddress("eglChooseConfig"); + + eglQueryContext(dpy, ctx, EGL_CONFIG_ID, &cfg_id); + EGLint attrs [4] = { + EGL_CONFIG_ID, cfg_id, + EGL_NONE, EGL_NONE, + }; + eglChooseConfig(dpy, attrs, &cfg, 1, &num_cfgs); + return cfg; +} +#endif + +#ifdef LOVR_LINUX_X11 +Display* lovrPlatformGetX11Display(void) +{ + return glfwGetX11Display(); +} + +GLXDrawable lovrPlatformGetGLXDrawable(void) +{ + return glfwGetGLXWindow(glfwState.window); +} + +GLXContext lovrPlatformGetGLXContext(void) +{ + return glfwGetGLXContext(glfwState.window); +} +#endif diff --git a/src/modules/headset/headset_openxr.c b/src/modules/headset/headset_openxr.c index bdbe9a95..a1403f6c 100644 --- a/src/modules/headset/headset_openxr.c +++ b/src/modules/headset/headset_openxr.c @@ -24,6 +24,19 @@ #define XR_USE_GRAPHICS_API_OPENGL_ES #define GRAPHICS_EXTENSION "XR_KHR_opengl_es_enable" #endif +#if defined(LOVR_LINUX_X11) + #define XR_USE_PLATFORM_XLIB + typedef unsigned long XID; + typedef struct Display Display; + typedef XID GLXFBConfig; + typedef XID GLXDrawable; + typedef XID GLXContext; +#endif +#if defined(LOVR_LINUX_EGL) + #define XR_USE_PLATFORM_EGL + #define EGL_NO_X11 + #include +#endif #define XR_NO_PROTOTYPES #include #include @@ -46,6 +59,15 @@ struct ANativeActivity* lovrPlatformGetActivity(void); EGLDisplay lovrPlatformGetEGLDisplay(void); EGLContext lovrPlatformGetEGLContext(void); EGLConfig lovrPlatformGetEGLConfig(void); +#elif defined(LOVR_LINUX_X11) +Display* lovrPlatformGetX11Display(void); +GLXDrawable lovrPlatformGetGLXDrawable(void); +GLXContext lovrPlatformGetGLXContext(void); +#elif defined(LOVR_LINUX_EGL) +PFNEGLGETPROCADDRESSPROC lovrPlatformGetEGLProcAddr(void); +EGLDisplay lovrPlatformGetEGLDisplay(void); +EGLContext lovrPlatformGetEGLContext(void); +EGLConfig lovrPlatformGetEGLConfig(void); #endif #define XR_FOREACH(X)\ @@ -183,6 +205,10 @@ static bool openxr_init(float supersample, float offset, uint32_t msaa) { enabledExtensionNames[enabledExtensionCount++] = XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME; #endif +#ifdef LOVR_LINUX_EGL + enabledExtensionNames[enabledExtensionCount++] = "XR_MNDX_egl_enable"; +#endif + enabledExtensionNames[enabledExtensionCount++] = GRAPHICS_EXTENSION; if (hasExtension(extensions, extensionCount, XR_EXT_HAND_TRACKING_EXTENSION_NAME)) { @@ -326,6 +352,25 @@ static bool openxr_init(float supersample, float offset, uint32_t msaa) { .config = lovrPlatformGetEGLConfig(), .context = lovrPlatformGetEGLContext() }; +#elif defined(LOVR_LINUX_X11) + XrGraphicsBindingOpenGLXlibKHR graphicsBinding = { + .type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR, + .next = NULL, + .xDisplay = lovrPlatformGetX11Display(), + .visualid = 0, + .glxFBConfig = 0, + .glxDrawable = lovrPlatformGetGLXDrawable(), + .glxContext = lovrPlatformGetGLXContext(), + }; +#elif defined(LOVR_LINUX_EGL) + XrGraphicsBindingEGLMNDX graphicsBinding = { + .type = XR_TYPE_GRAPHICS_BINDING_EGL_MNDX, + .next = NULL, + .getProcAddress = lovrPlatformGetEGLProcAddr(), + .display = lovrPlatformGetEGLDisplay(), + .config = lovrPlatformGetEGLConfig(), + .context = lovrPlatformGetEGLContext(), + }; #else #error "Unsupported OpenXR platform/graphics combination" #endif From 220aa70d7cfce5875bcc8369cbb2b288ee71ccdc Mon Sep 17 00:00:00 2001 From: Nevyn Bengtsson Date: Wed, 18 Nov 2020 21:37:31 +0100 Subject: [PATCH 07/26] fix crash in error handler when running out of vectors --- src/resources/boot.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/resources/boot.lua b/src/resources/boot.lua index 4ee0a7b6..d69931a2 100644 --- a/src/resources/boot.lua +++ b/src/resources/boot.lua @@ -277,6 +277,9 @@ function lovr.errhand(message, traceback) render() end lovr.graphics.present() + if lovr.math then + lovr.math.drain() + end end end From cf22c11dd562dbcd11789ff1defca508264c3442 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 18 Nov 2020 19:52:52 +0000 Subject: [PATCH 08/26] Do not try to create hand tracking devices if handTracking is not supported --- src/modules/headset/headset_openxr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/headset/headset_openxr.c b/src/modules/headset/headset_openxr.c index a1403f6c..03177e7a 100644 --- a/src/modules/headset/headset_openxr.c +++ b/src/modules/headset/headset_openxr.c @@ -745,6 +745,10 @@ static bool openxr_getSkeleton(Device device, float* poses) { return false; } + if (!state.features.handTracking) { + return false; + } + XrHandTrackerEXT* handTracker = &state.handTrackers[device - DEVICE_HAND_LEFT]; // Hand trackers are created lazily because on some implementations xrCreateHandTrackerEXT will From d65c72d7c65d3794fe28d060756edb033c99b3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20=C5=81abuda?= Date: Sat, 21 Nov 2020 00:37:32 +0100 Subject: [PATCH 09/26] Added bindings to pose/base --- src/resources/bindings_touch.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/resources/bindings_touch.json b/src/resources/bindings_touch.json index 89267036..104a3542 100644 --- a/src/resources/bindings_touch.json +++ b/src/resources/bindings_touch.json @@ -11,6 +11,8 @@ "poses" : [ { "output" : "/actions/lovr/in/leftHandPose", "path" : "/user/hand/left/pose/raw" }, { "output" : "/actions/lovr/in/rightHandPose", "path" : "/user/hand/right/pose/raw" }, + { "output" : "/actions/lovr/in/leftHandPose", "path" : "/user/hand/left/pose/base" }, + { "output" : "/actions/lovr/in/rightHandPose", "path" : "/user/hand/right/pose/base" }, { "output" : "/actions/lovr/in/leftHandPoint", "path" : "/user/hand/left/pose/tip" }, { "output" : "/actions/lovr/in/rightHandPoint", "path" : "/user/hand/right/pose/tip" } ], From 1ff94bc29a9ebb53b7878d4e5540b7a298394ca7 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 20 Nov 2020 19:23:04 -0700 Subject: [PATCH 10/26] Default errhand agnostic to t.math.globals; --- src/resources/boot.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/boot.lua b/src/resources/boot.lua index d69931a2..1dd2a662 100644 --- a/src/resources/boot.lua +++ b/src/resources/boot.lua @@ -271,7 +271,7 @@ function lovr.errhand(message, traceback) if lovr.graphics.hasWindow() then lovr.graphics.setViewPose(1) local width, height = lovr.graphics.getDimensions() - local projection = mat4():perspective(.1, 100, math.rad(67), width / height) + local projection = lovr.math.mat4():perspective(.1, 100, math.rad(67), width / height) lovr.graphics.setProjection(1, projection) lovr.graphics.clear() render() From 0ef23bb7e2448a9eb38dda86c6a9c5d5afc82203 Mon Sep 17 00:00:00 2001 From: Ben Ferguson Date: Mon, 23 Nov 2020 16:21:22 -0500 Subject: [PATCH 11/26] Removed erroneous manifest entry --- src/resources/AndroidManifest_oculus.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/resources/AndroidManifest_oculus.xml b/src/resources/AndroidManifest_oculus.xml index b24478e5..cb2cbffa 100644 --- a/src/resources/AndroidManifest_oculus.xml +++ b/src/resources/AndroidManifest_oculus.xml @@ -1,6 +1,6 @@ - + @@ -9,7 +9,6 @@ - From c557a8585f7a167b60c793f408aeef8e6ffc189a Mon Sep 17 00:00:00 2001 From: Nevyn Bengtsson Date: Thu, 26 Nov 2020 22:54:15 +0100 Subject: [PATCH 12/26] filesystem.append didn't append in Unix --- src/core/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/fs.c b/src/core/fs.c index 8b46de49..cc2fe55b 100644 --- a/src/core/fs.c +++ b/src/core/fs.c @@ -179,7 +179,7 @@ bool fs_open(const char* path, OpenMode mode, fs_handle* file) { switch (mode) { case OPEN_READ: flags = O_RDONLY; break; case OPEN_WRITE: flags = O_WRONLY | O_CREAT | O_TRUNC; break; - case OPEN_APPEND: flags = O_WRONLY | O_CREAT; break; + case OPEN_APPEND: flags = O_APPEND | O_WRONLY | O_CREAT; break; default: return false; } file->fd = open(path, flags, S_IRUSR | S_IWUSR); From f60441d9051f3d56b90e78dec17f22855166a7b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20=C5=81abuda?= Date: Fri, 27 Nov 2020 21:06:26 +0100 Subject: [PATCH 13/26] Reverting binding to base --- src/resources/bindings_touch.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/resources/bindings_touch.json b/src/resources/bindings_touch.json index 104a3542..89267036 100644 --- a/src/resources/bindings_touch.json +++ b/src/resources/bindings_touch.json @@ -11,8 +11,6 @@ "poses" : [ { "output" : "/actions/lovr/in/leftHandPose", "path" : "/user/hand/left/pose/raw" }, { "output" : "/actions/lovr/in/rightHandPose", "path" : "/user/hand/right/pose/raw" }, - { "output" : "/actions/lovr/in/leftHandPose", "path" : "/user/hand/left/pose/base" }, - { "output" : "/actions/lovr/in/rightHandPose", "path" : "/user/hand/right/pose/base" }, { "output" : "/actions/lovr/in/leftHandPoint", "path" : "/user/hand/left/pose/tip" }, { "output" : "/actions/lovr/in/rightHandPoint", "path" : "/user/hand/right/pose/tip" } ], From 08025b9ac0d7a0e5b52cbc9836a21aedbbc9c605 Mon Sep 17 00:00:00 2001 From: Colby Klein Date: Fri, 27 Nov 2020 17:48:33 -0800 Subject: [PATCH 14/26] fix mat4_lookAt translation offset need to dot with the axes to not have bizarre results. --- src/core/maf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/maf.h b/src/core/maf.h index 8aaa7a69..2db956f6 100644 --- a/src/core/maf.h +++ b/src/core/maf.h @@ -643,9 +643,9 @@ MAF mat4 mat4_lookAt(mat4 m, vec3 from, vec3 to, vec3 up) { m[9] = z[1]; m[10] = z[2]; m[11] = 0.f; - m[12] = from[0]; - m[13] = from[1]; - m[14] = from[2]; + m[12] = -vec3_dot(x, from); + m[13] = -vec3_dot(y, from); + m[14] = -vec3_dot(z, from); m[15] = 1.f; return m; } From 8ef50b5f6ac609aa651b9e2fe6e7a13fad1261e0 Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 2 Dec 2020 14:46:37 -0700 Subject: [PATCH 15/26] lovr.mirror: don't call lovr.headset.getMirrorTexture twice; --- src/resources/boot.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resources/boot.lua b/src/resources/boot.lua index 1dd2a662..01d9532d 100644 --- a/src/resources/boot.lua +++ b/src/resources/boot.lua @@ -221,9 +221,9 @@ function lovr.mirror() local texture = lovr.headset.getMirrorTexture() if texture then -- On some drivers, texture is printed directly to the window if lovr.headset.getDriver() == 'oculus' then - lovr.graphics.fill(lovr.headset.getMirrorTexture(), 0, 1, 1, -1) + lovr.graphics.fill(texture, 0, 1, 1, -1) else - lovr.graphics.fill(lovr.headset.getMirrorTexture()) + lovr.graphics.fill(texture) end end else From e887d4625673f39d9c33c0a56ce874f0e5f8c1d7 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 11 Dec 2020 04:41:48 -0700 Subject: [PATCH 16/26] Fix crash on non-string thread errors; Non-string errors are currently ignored. This is consistent with love, and is pretty obscure, but maybe it can be improved at some point. --- src/api/l_thread.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/api/l_thread.c b/src/api/l_thread.c index 1276aa07..8e5074e1 100644 --- a/src/api/l_thread.c +++ b/src/api/l_thread.c @@ -38,18 +38,22 @@ static int threadRunner(void* data) { } } + mtx_lock(&thread->lock); + // Error handling size_t length; const char* error = lua_tolstring(L, -1, &length); - mtx_lock(&thread->lock); - thread->error = malloc(length + 1); - if (thread->error) { - memcpy(thread->error, error, length + 1); - lovrEventPush((Event) { - .type = EVENT_THREAD_ERROR, - .data.thread = { thread, thread->error } - }); + if (error) { + thread->error = malloc(length + 1); + if (thread->error) { + memcpy(thread->error, error, length + 1); + lovrEventPush((Event) { + .type = EVENT_THREAD_ERROR, + .data.thread = { thread, thread->error } + }); + } } + thread->running = false; mtx_unlock(&thread->lock); lovrRelease(Thread, thread); From 96839c51812d6496dffe01a62e03bab23c3bc641 Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 15 Dec 2020 20:20:25 -0700 Subject: [PATCH 17/26] Slightly better error messages on image load failure; --- src/lib/stb/stb_image.c | 1 + src/modules/data/textureData.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/stb/stb_image.c b/src/lib/stb/stb_image.c index 87375cf6..78f05047 100644 --- a/src/lib/stb/stb_image.c +++ b/src/lib/stb/stb_image.c @@ -4,6 +4,7 @@ #define STBI_ONLY_PNG #define STBI_ONLY_HDR #define STBI_ASSERT(x) +#define STBI_FAILURE_USERMSG #include "stb_image.h" #ifndef LOVR_STBI_VFLIP_PATCH diff --git a/src/modules/data/textureData.c b/src/modules/data/textureData.c index f0cf7685..601f9c88 100644 --- a/src/modules/data/textureData.c +++ b/src/modules/data/textureData.c @@ -524,7 +524,7 @@ TextureData* lovrTextureDataInitFromBlob(TextureData* textureData, Blob* blob, b } if (!textureData->blob->data) { - lovrThrow("Could not load texture data from '%s'", blob->name); + lovrThrow("Could not load TextureData from '%s': %s", blob->name, stbi_failure_reason()); lovrRelease(Blob, textureData->blob); free(textureData); return NULL; From 1efb07b2758e21a94a992b24dfdf5a726041630b Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 6 Jan 2021 19:12:20 -0700 Subject: [PATCH 18/26] Update README; --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fb31f92..575cecde 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ function lovr.draw() end ``` -You can try more examples in your browser on the [docs page](https://lovr.org/docs/Hello_World). +You can try more examples in your browser on the [docs page](https://lovr.org/docs/Intro/Hello_World). Building --- From 522987c21192b28fb6181a0b660d261b4293de83 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 8 Jan 2021 21:26:03 -0700 Subject: [PATCH 19/26] 64 bit nightly builds; --- src/resources/appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/appveyor.yml b/src/resources/appveyor.yml index 4538117d..478a0710 100644 --- a/src/resources/appveyor.yml +++ b/src/resources/appveyor.yml @@ -16,7 +16,7 @@ before_build: - git submodule update --init - md build - cd build - - cmake -DCMAKE_BUILD_TYPE=%configuration% .. + - cmake -DCMAKE_BUILD_TYPE=%configuration% -A x64 .. configuration: Release From 8108b6aa5a3bec571b9c4082098c88e032cce203 Mon Sep 17 00:00:00 2001 From: Nevyn Bengtsson Date: Mon, 11 Jan 2021 15:29:05 +0100 Subject: [PATCH 20/26] Switch luajit GC and remove image_base settings to fix dyld shared cache errors on macOS 11 --- CMakeLists.txt | 7 ++++--- deps/luajit | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68c65837..33faef13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,9 +115,10 @@ endif() # Lua if(LOVR_USE_LUAJIT AND NOT EMSCRIPTEN) - if (APPLE) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000") - endif() + # Required to make luajit compile without breaking linker cache on macOS Big Sur. Also, is a better, + # newer GC so enable it on all builds. + set(LUAJIT_ENABLE_GC64 ON) + if(LOVR_SYSTEM_LUA) pkg_search_module(LUAJIT REQUIRED luajit) include_directories(${LUAJIT_INCLUDE_DIRS}) diff --git a/deps/luajit b/deps/luajit index c37be68c..05db1d35 160000 --- a/deps/luajit +++ b/deps/luajit @@ -1 +1 @@ -Subproject commit c37be68cf0876eb60f9f9ffd3920963f6ef01d7e +Subproject commit 05db1d35d8a35f74ce40d0ba5e387717ad91b24d From eace93664684d5c9149d0ef7910a2bdf8f08015b Mon Sep 17 00:00:00 2001 From: Nevyn Bengtsson Date: Tue, 19 Jan 2021 11:29:43 +0100 Subject: [PATCH 21/26] bump glfw for m1 fix --- deps/glfw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/glfw b/deps/glfw index 6b01affd..94773111 160000 --- a/deps/glfw +++ b/deps/glfw @@ -1 +1 @@ -Subproject commit 6b01affd89975c7d08c98036ce0882d8ac540f4a +Subproject commit 94773111300fee0453844a4c9407af7e880b4df8 From 394759c1ab1c4bfebaff61b29d353688b3c8963a Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Fri, 22 Jan 2021 15:43:01 +0100 Subject: [PATCH 22/26] initialize XrSystemProperties type --- src/modules/headset/headset_openxr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/headset/headset_openxr.c b/src/modules/headset/headset_openxr.c index 03177e7a..4661caba 100644 --- a/src/modules/headset/headset_openxr.c +++ b/src/modules/headset/headset_openxr.c @@ -542,7 +542,9 @@ static void openxr_destroy(void) { } static bool openxr_getName(char* name, size_t length) { - XrSystemProperties properties; + XrSystemProperties properties = { + .type = XR_TYPE_SYSTEM_PROPERTIES + }; XR(xrGetSystemProperties(state.instance, state.system, &properties)); strncpy(name, properties.systemName, length - 1); name[length - 1] = '\0'; From 944a6029f08688a523872cc72c9aa9399daffa80 Mon Sep 17 00:00:00 2001 From: Josip Miskovic Date: Fri, 22 Jan 2021 16:01:27 +0100 Subject: [PATCH 23/26] Add mat4:targetAt and modify the mat4:lookAt lookAt() returns view matrix that can be used to transform the camera perspective. target() returns model matrix that is used to change model transform. Results are matrix inversions of one another. Now both functions exist it is possible to use right one and avoid extra matrix inversion. --- src/api/l_math_vectors.c | 11 +++++++++++ src/core/maf.h | 32 +++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/api/l_math_vectors.c b/src/api/l_math_vectors.c index 1a267214..b24a97ad 100644 --- a/src/api/l_math_vectors.c +++ b/src/api/l_math_vectors.c @@ -1655,6 +1655,16 @@ static int l_lovrMat4LookAt(lua_State* L) { return 1; } +static int l_lovrMat4Target(lua_State* L) { + mat4 m = luax_checkvector(L, 1, V_MAT4, NULL); + vec3 from = luax_checkvector(L, 2, V_VEC3, NULL); + vec3 to = luax_checkvector(L, 3, V_VEC3, NULL); + vec3 up = lua_isnoneornil(L, 4) ? (float[4]) { 0.f, 1.f, 0.f } : luax_checkvector(L, 4, V_VEC3, NULL); + mat4_target(m, from, to, up); + lua_settop(L, 1); + return 1; +} + static int l_lovrMat4__mul(lua_State* L) { mat4 m = luax_checkvector(L, 1, V_MAT4, NULL); VectorType type; @@ -1738,6 +1748,7 @@ const luaL_Reg lovrMat4[] = { { "perspective", l_lovrMat4Perspective }, { "fov", l_lovrMat4Fov }, { "lookAt", l_lovrMat4LookAt }, + { "target", l_lovrMat4Target }, { "__mul", l_lovrMat4__mul }, { "__tostring", l_lovrMat4__tostring }, { "__newindex", l_lovrMat4__newindex }, diff --git a/src/core/maf.h b/src/core/maf.h index 2db956f6..a25bb859 100644 --- a/src/core/maf.h +++ b/src/core/maf.h @@ -625,6 +625,32 @@ MAF void mat4_getFov(mat4 m, float* left, float* right, float* up, float* down) } MAF mat4 mat4_lookAt(mat4 m, vec3 from, vec3 to, vec3 up) { + float x[4]; + float y[4]; + float z[4]; + vec3_normalize(vec3_sub(vec3_init(z, from), to)); + vec3_normalize(vec3_cross(vec3_init(x, up), z)); + vec3_cross(vec3_init(y, z), x); + m[0] = x[0]; + m[1] = y[0]; + m[2] = z[0]; + m[3] = 0.f; + m[4] = x[1]; + m[5] = y[1]; + m[6] = z[1]; + m[7] = 0.f; + m[8] = x[2]; + m[9] = y[2]; + m[10] = z[2]; + m[11] = 0.f; + m[12] = -vec3_dot(x, from); + m[13] = -vec3_dot(y, from); + m[14] = -vec3_dot(z, from); + m[15] = 1.f; + return m; +} + +MAF mat4 mat4_target(mat4 m, vec3 from, vec3 to, vec3 up) { float x[4]; float y[4]; float z[4]; @@ -643,9 +669,9 @@ MAF mat4 mat4_lookAt(mat4 m, vec3 from, vec3 to, vec3 up) { m[9] = z[1]; m[10] = z[2]; m[11] = 0.f; - m[12] = -vec3_dot(x, from); - m[13] = -vec3_dot(y, from); - m[14] = -vec3_dot(z, from); + m[12] = from[0]; + m[13] = from[1]; + m[14] = from[2]; m[15] = 1.f; return m; } From 24484f3930a44e799273d5bc862b41450c6bf8cd Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 25 Jan 2021 13:10:25 -0700 Subject: [PATCH 24/26] Fix lovrInstanceID on Android; --- src/resources/shaders.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/resources/shaders.c b/src/resources/shaders.c index 466c70de..26ad6cd8 100644 --- a/src/resources/shaders.c +++ b/src/resources/shaders.c @@ -47,6 +47,7 @@ const char* lovrShaderVertexPrefix = "" "#if defined MULTIVIEW \n" "layout(num_views = 2) in; \n" "#define lovrViewID (int(gl_ViewID_OVR)) \n" +"#define lovrInstanceID gl_InstanceID \n" "#elif defined INSTANCED_STEREO \n" "#define lovrViewID gl_ViewportIndex \n" "#define lovrInstanceID (gl_InstanceID / lovrViewportCount) \n" From 0cb8a004d32ba828f9b7fe96b35d559dd8750ced Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 25 Jan 2021 14:02:15 -0700 Subject: [PATCH 25/26] webxr.js: update emscripten dynCall syntax; --- src/resources/webxr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resources/webxr.js b/src/resources/webxr.js index 7294492c..313a0ffc 100644 --- a/src/resources/webxr.js +++ b/src/resources/webxr.js @@ -377,7 +377,7 @@ var webxr = { } Module.stackRestore(matrix); Module._lovrGraphicsSetBackbuffer(state.canvas, true, true); - Module.dynCall_vi(callback, userdata); + {{{ makeDynCall('vi', 'callback') }}} (userdata); Module._lovrGraphicsSetBackbuffer(0, false, false); }, From cf2ab46bef4a77037e7ab42806bf2abf1cfb3ba4 Mon Sep 17 00:00:00 2001 From: bjorn Date: Thu, 4 Feb 2021 01:41:35 -0700 Subject: [PATCH 26/26] Fix arr_splice; --- src/core/arr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/arr.h b/src/core/arr.h index 01cf2420..69b74dcb 100644 --- a/src/core/arr.h +++ b/src/core/arr.h @@ -34,7 +34,7 @@ (a)->length += n #define arr_splice(a, i, n)\ - memmove((a)->data + (i), (a)->data + ((i) + n), ((a)->length - (n)) * sizeof(*(a)->data)),\ + memmove((a)->data + (i), (a)->data + ((i) + n), ((a)->length - (i) - (n)) * sizeof(*(a)->data)),\ (a)->length -= n #define arr_clear(a)\