From b6c3a8fa17f6a0e54ecdf71c3712542062e2b246 Mon Sep 17 00:00:00 2001 From: Ilya Chelyadin Date: Sat, 1 May 2021 03:11:28 +0300 Subject: [PATCH 01/15] All-in-One Lua loader --- src/api/l_filesystem.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/api/l_filesystem.c b/src/api/l_filesystem.c index 7721b4de..282b5e2f 100644 --- a/src/api/l_filesystem.c +++ b/src/api/l_filesystem.c @@ -411,7 +411,7 @@ static int luaLoader(lua_State* L) { return 0; } -static int libLoader(lua_State* L) { +static int libLoaderCommon(lua_State* L, bool allInOneFlag) { #ifdef _WIN32 const char* extension = ".dll"; #else @@ -454,6 +454,7 @@ static int libLoader(lua_State* L) { #endif for (const char* m = module; *m && length < sizeof(path); m++, length++) { + if (allInOneFlag && *m == '.') break; *p++ = *m == '.' ? LOVR_PATH_SEP : *m; } @@ -484,6 +485,18 @@ static int libLoader(lua_State* L) { return 1; } +static int libLoader(lua_State* L) { + const char* module = lua_tostring(L, 1); + bool allInOneFlag = false; + return libLoaderCommon(L, allInOneFlag); +} + +static int libLoaderAllInOne(lua_State* L) { + const char* module = lua_tostring(L, 1); + bool allInOneFlag = true; + return libLoaderCommon(L, allInOneFlag); +} + int luaopen_lovr_filesystem(lua_State* L) { const char* archive = NULL; @@ -503,5 +516,6 @@ int luaopen_lovr_filesystem(lua_State* L) { luax_register(L, lovrFilesystem); luax_registerloader(L, luaLoader, 2); luax_registerloader(L, libLoader, 3); + luax_registerloader(L, libLoaderAllInOne, 4); return 1; } From 89550e55d6533574bd70c5baabceebb95a0ce0b0 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 31 May 2021 14:35:53 -0600 Subject: [PATCH 02/15] Fix oculus hand model orientation; - Previously, animate was converting from oculus basis to lovr basis. - Not all hand models are animated. - Instead, apply the compensation in newModel. - This means that both animated and non-animated models have correct orientation. - Verified that regular getPose is returning correct rotation as well. --- src/modules/headset/headset_vrapi.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/modules/headset/headset_vrapi.c b/src/modules/headset/headset_vrapi.c index fbba2bc9..9f4efdd5 100644 --- a/src/modules/headset/headset_vrapi.c +++ b/src/modules/headset/headset_vrapi.c @@ -572,6 +572,14 @@ static struct ModelData* vrapi_newModelData(Device device, bool animated) { .skin = ~0u }; + // Root node transform has a rotation compensation for different coordinate spaces + if (device == DEVICE_HAND_LEFT) { + mat4_rotate(model->nodes[model->rootNode].transform.matrix, M_PI, 0.f, 0.f, 1.f); + mat4_rotate(model->nodes[model->rootNode].transform.matrix, M_PI / 2.f, 0.f, 1.f, 0.f); + } else { + mat4_rotate(model->nodes[model->rootNode].transform.matrix, -M_PI / 2.f, 0.f, 1.f, 0.f); + } + // Add the children to the root node *children++ = 0; *children++ = model->jointCount; @@ -598,24 +606,11 @@ static bool vrapi_animate(Device device, struct Model* model) { lovrModelResetPose(model); - // compensate for vrapi_getPose changing "forward" to be -Z - float compensate[4]; - if (device == DEVICE_HAND_LEFT) { - float q[4]; - quat_fromAngleAxis(compensate, (float) M_PI, 0.f, 0.f, 1.f); - quat_mul(compensate, compensate, quat_fromAngleAxis(q, (float) M_PI / 2.f, 0.f, 1.f, 0.f)); - } else { - quat_fromAngleAxis(compensate, (float) -M_PI / 2.f, 0.f, 1.f, 0.f); - } - // Replace node rotations with the rotations in the hand pose, keeping the position the same for (uint32_t i = 0; i < ovrHandBone_MaxSkinnable && i < modelData->nodeCount; i++) { float position[4], orientation[4]; vec3_init(position, modelData->nodes[i].transform.properties.translation); quat_init(orientation, &handPose->BoneRotations[i].x); - if(i == ovrHandBone_WristRoot) { - quat_mul(orientation, orientation, compensate); - } lovrModelPose(model, i, position, orientation, 1.f); } From 46a5c83a084606f82ff188e2dcfa65801d3a6f3f Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 31 May 2021 15:04:24 -0600 Subject: [PATCH 03/15] rm unused variables; --- src/api/l_filesystem.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/api/l_filesystem.c b/src/api/l_filesystem.c index 282b5e2f..2d8a0212 100644 --- a/src/api/l_filesystem.c +++ b/src/api/l_filesystem.c @@ -486,13 +486,11 @@ static int libLoaderCommon(lua_State* L, bool allInOneFlag) { } static int libLoader(lua_State* L) { - const char* module = lua_tostring(L, 1); bool allInOneFlag = false; return libLoaderCommon(L, allInOneFlag); } static int libLoaderAllInOne(lua_State* L) { - const char* module = lua_tostring(L, 1); bool allInOneFlag = true; return libLoaderCommon(L, allInOneFlag); } From ca4b7d01bce2e1efac8c65bfb1f17ead239a9772 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 31 May 2021 15:05:13 -0600 Subject: [PATCH 04/15] Allow passing vec2 as scale argument; Useful for planes. --- src/api/l_math_vectors.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/api/l_math_vectors.c b/src/api/l_math_vectors.c index 9c11646b..c78334dc 100644 --- a/src/api/l_math_vectors.c +++ b/src/api/l_math_vectors.c @@ -76,9 +76,17 @@ int luax_readscale(lua_State* L, int index, vec3 v, int components, const char* } } return index; - default: - vec3_init(v, luax_checkvector(L, index++, V_VEC3, expected ? expected : "vec3 or number")); + default: { + VectorType type; + float* u = luax_tovector(L, index++, &type); + if (type == V_VEC2 || type == V_VEC3) { + v[2] = 1.f; + vec3_init(v, u); + } else { + return luax_typeerror(L, index, "vec3, vec2, or number"); + } return index; + } } } From 3d1775e4685655dc82318d84511fe26ea112a316 Mon Sep 17 00:00:00 2001 From: brainrom Date: Thu, 10 Jun 2021 15:17:21 +0300 Subject: [PATCH 05/15] Lua links properly mlib required to build Lua, dl lib used to load compiled plugins from shared libraries. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c757c79..64550687 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,6 +117,9 @@ else() ) list(TRANSFORM LUA_SRC PREPEND deps/lua/) add_library(lua SHARED ${LUA_SRC}) + target_link_libraries(lua m) + target_link_libraries(lua dl) + target_compile_definitions(lua PRIVATE -DLUA_USE_DLOPEN) include_directories(deps/lua) set(LOVR_LUA lua) endif() From 82b7632cea40afb3ab0aa151941cc089ff9f04d2 Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 12 Jun 2021 14:25:09 -0600 Subject: [PATCH 06/15] Require material textures to be 2D; --- src/modules/graphics/material.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/graphics/material.c b/src/modules/graphics/material.c index 42a3dd06..eef372fa 100644 --- a/src/modules/graphics/material.c +++ b/src/modules/graphics/material.c @@ -89,6 +89,7 @@ Texture* lovrMaterialGetTexture(Material* material, MaterialTexture textureType) void lovrMaterialSetTexture(Material* material, MaterialTexture textureType, Texture* texture) { if (material->textures[textureType] != texture) { + lovrAssert(lovrTextureGetType(texture) == TEXTURE_2D, "Material textures must be 2D"); lovrGraphicsFlushMaterial(material); lovrRetain(texture); lovrRelease(material->textures[textureType], lovrTextureDestroy); From 526e06d4451489fd4d15f23c96c78d22b9ccb7ca Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 16 Jun 2021 16:55:19 -0600 Subject: [PATCH 07/15] Fix mat4 corruption when using vectors; We correct m[15] to 1.f too late, by that time the undefined 4th component of the vec3 could have corrupted the rotation/scale. --- src/api/l_math_vectors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/l_math_vectors.c b/src/api/l_math_vectors.c index c78334dc..b10a8ad4 100644 --- a/src/api/l_math_vectors.c +++ b/src/api/l_math_vectors.c @@ -135,9 +135,9 @@ int luax_readmat4(lua_State* L, int index, mat4 m, int scaleComponents) { index = luax_readvec3(L, index, m + 12, "mat4, vec3, or number"); index = luax_readscale(L, index, S, scaleComponents, NULL); index = luax_readquat(L, index, R, NULL); + m[15] = 1.f; mat4_rotateQuat(m, R); mat4_scale(m, S[0], S[1], S[2]); - m[15] = 1.f; return index; } } From 7e52ffe95686b10b668da0f67a6e4b929f6ed183 Mon Sep 17 00:00:00 2001 From: kokokoshka Date: Tue, 15 Jun 2021 10:36:55 +0300 Subject: [PATCH 08/15] MinGW support --- CMakeLists.txt | 6 +++++- src/core/os_win32.c | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64550687..4981c98a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -595,7 +595,11 @@ endforeach() if(WIN32) target_sources(lovr PRIVATE src/core/os_win32.c) target_sources(lovr PRIVATE src/resources/lovr.rc) - set_target_properties(lovr PROPERTIES COMPILE_FLAGS "/wd4244 /MP") + if (MSVC) + set_target_properties(lovr PROPERTIES COMPILE_FLAGS "/wd4244 /MP") + else() + set_target_properties(lovr PROPERTIES COMPILE_FLAGS "-MP") + endif() set_target_properties(lovr PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:console /ENTRY:WinMainCRTStartup") set_target_properties(lovr PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:windows /ENTRY:WinMainCRTStartup") target_compile_definitions(lovr PRIVATE _CRT_SECURE_NO_WARNINGS) diff --git a/src/core/os_win32.c b/src/core/os_win32.c index ee96dfdd..867d4bd5 100644 --- a/src/core/os_win32.c +++ b/src/core/os_win32.c @@ -2,8 +2,8 @@ #define WIN32_LEAN_AND_MEAN #include #include -#include -#include +#include +#include #include #include "os_glfw.h" From 59d3b25932e3482e518ea7ad37f179dcff1f4106 Mon Sep 17 00:00:00 2001 From: brainrom Date: Tue, 15 Jun 2021 18:16:03 +0300 Subject: [PATCH 09/15] Able to get view angles with 3DOF --- src/modules/headset/headset_vrapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/headset/headset_vrapi.c b/src/modules/headset/headset_vrapi.c index 9f4efdd5..2e5e57e8 100644 --- a/src/modules/headset/headset_vrapi.c +++ b/src/modules/headset/headset_vrapi.c @@ -139,7 +139,7 @@ static bool vrapi_getViewAngles(uint32_t view, float* left, float* right, float* mat4_init(projection, (float*) &tracking.Eye[view].ProjectionMatrix); mat4_transpose(projection); mat4_getFov(projection, left, right, up, down); - uint32_t mask = VRAPI_TRACKING_STATUS_POSITION_VALID | VRAPI_TRACKING_STATUS_ORIENTATION_VALID; + uint32_t mask = VRAPI_TRACKING_STATUS_ORIENTATION_VALID; return (tracking.Status & mask) == mask; } From 92a08c326f3b4bcb228269d9ad6f3292253b3e8a Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 18 Jun 2021 15:51:18 -0600 Subject: [PATCH 10/15] vrapi: getViewPose returns a pose when position is invalid; To match getViewAngles. Also simplify mask check. --- src/modules/headset/headset_vrapi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/headset/headset_vrapi.c b/src/modules/headset/headset_vrapi.c index 2e5e57e8..aa23aa11 100644 --- a/src/modules/headset/headset_vrapi.c +++ b/src/modules/headset/headset_vrapi.c @@ -128,8 +128,7 @@ static bool vrapi_getViewPose(uint32_t view, float* position, float* orientation mat4_invert(transform); mat4_getPosition(transform, position); mat4_getOrientation(transform, orientation); - uint32_t mask = VRAPI_TRACKING_STATUS_POSITION_VALID | VRAPI_TRACKING_STATUS_ORIENTATION_VALID; - return (tracking.Status & mask) == mask; + return tracking.Status & VRAPI_TRACKING_STATUS_ORIENTATION_VALID; } static bool vrapi_getViewAngles(uint32_t view, float* left, float* right, float* up, float* down) { @@ -139,8 +138,7 @@ static bool vrapi_getViewAngles(uint32_t view, float* left, float* right, float* mat4_init(projection, (float*) &tracking.Eye[view].ProjectionMatrix); mat4_transpose(projection); mat4_getFov(projection, left, right, up, down); - uint32_t mask = VRAPI_TRACKING_STATUS_ORIENTATION_VALID; - return (tracking.Status & mask) == mask; + return tracking.Status & VRAPI_TRACKING_STATUS_ORIENTATION_VALID; } static void vrapi_getClipDistance(float* clipNear, float* clipFar) { From 93d867a972516c9b6238e3960fd7319b25fec86d Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 18 Jun 2021 21:31:42 +0100 Subject: [PATCH 11/15] Fix AppImage lovr.desktop file Changes by @darltrash --- src/resources/lovr.desktop | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/resources/lovr.desktop b/src/resources/lovr.desktop index e08efdca..596a1990 100644 --- a/src/resources/lovr.desktop +++ b/src/resources/lovr.desktop @@ -1,5 +1,6 @@ [Desktop Entry] -Type=Application +Exec=AppRun Name=LÖVR +Type=Application Icon=logo -Categories= +Categories=Development; From 41257962119b6348fc767efa0231208510aec33e Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 21 Jun 2021 10:21:35 -0600 Subject: [PATCH 12/15] Fix shaders with nil stages; The length was getting kept as zero, need to adjust length when falling back to default shaders. --- src/modules/graphics/opengl.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/graphics/opengl.c b/src/modules/graphics/opengl.c index 5f97c2ae..bd413e17 100644 --- a/src/modules/graphics/opengl.c +++ b/src/modules/graphics/opengl.c @@ -2639,15 +2639,23 @@ Shader* lovrShaderCreateGraphics(const char* vertexSource, int vertexSourceLengt char* flagSource = lovrShaderGetFlagCode(flags, flagCount); + if (!vertexSource) { + vertexSource = lovrUnlitVertexShader; + vertexSourceLength = -1; + } + + if (!fragmentSource) { + fragmentSource = lovrUnlitFragmentShader; + fragmentSourceLength = -1; + } + // Vertex - vertexSource = vertexSource == NULL ? lovrUnlitVertexShader : vertexSource; const char* vertexSources[] = { version, computeExtensions, singlepass[0], flagSource ? flagSource : "", lovrShaderVertexPrefix, vertexSource, lovrShaderVertexSuffix }; int vertexSourceLengths[] = { -1, -1, -1, -1, -1, vertexSourceLength, -1 }; int vertexSourceCount = sizeof(vertexSources) / sizeof(vertexSources[0]); GLuint vertexShader = compileShader(GL_VERTEX_SHADER, vertexSources, vertexSourceLengths, vertexSourceCount); // Fragment - fragmentSource = fragmentSource == NULL ? lovrUnlitFragmentShader : fragmentSource; const char* fragmentSources[] = { version, computeExtensions, singlepass[1], flagSource ? flagSource : "", lovrShaderFragmentPrefix, fragmentSource, lovrShaderFragmentSuffix }; int fragmentSourceLengths[] = { -1, -1, -1, -1, -1, fragmentSourceLength, -1 }; int fragmentSourceCount = sizeof(fragmentSources) / sizeof(fragmentSources[0]); From 63320252a17f24f7bdc55894f345589b5a99bf4e Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 26 Jun 2021 14:41:42 -0700 Subject: [PATCH 13/15] Fix error when rapidly recreating objects; If you create and destroy objects quickly (using :release), malloc might give you the same pointer. When we look up this pointer in the userdata cache, it'll give you an invalid Proxy/pointer, which throws an error like "Calling 'fn' on bad self". When collecting objects, remove them from the userdata cache. --- src/api/api.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/api/api.c b/src/api/api.c index 88ab0f47..ecb1d574 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -43,6 +43,16 @@ static int luax_meta__tostring(lua_State* L) { static int luax_meta__gc(lua_State* L) { Proxy* p = lua_touserdata(L, 1); if (p) { + // Remove from userdata cache + lua_getfield(L, LUA_REGISTRYINDEX, "_lovrobjects"); + if (lua_istable(L, -1)) { + lua_pushlightuserdata(L, p->object); + lua_pushnil(L); + lua_rawset(L, -3); + } + lua_pop(L, 1); + + // Release lua_getmetatable(L, 1); lua_getfield(L, -1, "__info"); TypeInfo* info = lua_touserdata(L, -1); From f959770396233dc0e54298c3d6cc98033173fd1d Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 29 Jun 2021 13:09:57 -0700 Subject: [PATCH 14/15] Add missing OpenVR pointer actions; --- src/resources/actions.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/resources/actions.json b/src/resources/actions.json index 97c0371d..8d2ffbe1 100644 --- a/src/resources/actions.json +++ b/src/resources/actions.json @@ -5,6 +5,8 @@ "actions" : [ { "name" : "/actions/lovr/in/leftHandPose", "type" : "pose" }, { "name" : "/actions/lovr/in/rightHandPose", "type" : "pose" }, + { "name" : "/actions/lovr/in/leftHandPoint", "type" : "pose" }, + { "name" : "/actions/lovr/in/rightHandPoint", "type" : "pose" }, { "name" : "/actions/lovr/in/leftElbowPose", "type" : "pose" }, { "name" : "/actions/lovr/in/rightElbowPose", "type" : "pose" }, { "name" : "/actions/lovr/in/leftShoulderPose", "type" : "pose" }, @@ -76,6 +78,8 @@ { "/actions/lovr/in/leftHandPose": "Left Hand Pose", "/actions/lovr/in/rightHandPose": "Right Hand Pose", + "/actions/lovr/in/leftHandPoint": "Left Hand Point", + "/actions/lovr/in/rightHandPoint": "Right Hand Point", "/actions/lovr/in/leftTriggerDown": "Left Trigger Press", "/actions/lovr/in/leftTriggerTouch": "Left Trigger Touch", "/actions/lovr/in/leftTriggerAxis": "Left Trigger Axis", From e2cad4ed81dee4667c9ede8992e4744600e2bff5 Mon Sep 17 00:00:00 2001 From: bjorn Date: Sat, 10 Jul 2021 09:42:49 -0700 Subject: [PATCH 15/15] Fix crash in Material:setTexture; --- src/modules/graphics/material.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/graphics/material.c b/src/modules/graphics/material.c index eef372fa..439f7938 100644 --- a/src/modules/graphics/material.c +++ b/src/modules/graphics/material.c @@ -89,7 +89,7 @@ Texture* lovrMaterialGetTexture(Material* material, MaterialTexture textureType) void lovrMaterialSetTexture(Material* material, MaterialTexture textureType, Texture* texture) { if (material->textures[textureType] != texture) { - lovrAssert(lovrTextureGetType(texture) == TEXTURE_2D, "Material textures must be 2D"); + lovrAssert(!texture || lovrTextureGetType(texture) == TEXTURE_2D, "Material textures must be 2D"); lovrGraphicsFlushMaterial(material); lovrRetain(texture); lovrRelease(material->textures[textureType], lovrTextureDestroy);