diff --git a/CMakeLists.txt b/CMakeLists.txt index a7c912a2..0b23d351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,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() @@ -608,7 +611,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() if(NOT LOVR_BUILD_SHARED) set_target_properties(lovr PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:console /ENTRY:WinMainCRTStartup") set_target_properties(lovr PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:windows /ENTRY:WinMainCRTStartup") diff --git a/src/api/api.c b/src/api/api.c index 55277760..cdb3aa83 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -42,6 +42,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); diff --git a/src/api/l_math_vectors.c b/src/api/l_math_vectors.c index e7d49b24..3025ce26 100644 --- a/src/api/l_math_vectors.c +++ b/src/api/l_math_vectors.c @@ -134,9 +134,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; } } diff --git a/src/core/os_win32.c b/src/core/os_win32.c index 782d3574..93d0e01c 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" diff --git a/src/modules/graphics/material.c b/src/modules/graphics/material.c index 42a3dd06..439f7938 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(!texture || lovrTextureGetType(texture) == TEXTURE_2D, "Material textures must be 2D"); lovrGraphicsFlushMaterial(material); lovrRetain(texture); lovrRelease(material->textures[textureType], lovrTextureDestroy); diff --git a/src/modules/graphics/opengl.c b/src/modules/graphics/opengl.c index c7a06f36..511003c1 100644 --- a/src/modules/graphics/opengl.c +++ b/src/modules/graphics/opengl.c @@ -2655,15 +2655,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]); diff --git a/src/modules/headset/headset_vrapi.c b/src/modules/headset/headset_vrapi.c index 566ce329..bc19f8b9 100644 --- a/src/modules/headset/headset_vrapi.c +++ b/src/modules/headset/headset_vrapi.c @@ -154,8 +154,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) { @@ -165,8 +164,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; - return (tracking.Status & mask) == mask; + return tracking.Status & VRAPI_TRACKING_STATUS_ORIENTATION_VALID; } static void vrapi_getClipDistance(float* clipNear, float* clipFar) { 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",