Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First attempt GLFW gamepad driver (don't merge yet?) #222

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d43a48d
First attempt GLFW gamepad driver
mcclure Feb 13, 2020
dc1d887
Merge master->driver-gamepad
mcclure Feb 19, 2020
44c8b3a
Fix merge errors, roll back os_glfw.h change
mcclure Feb 19, 2020
81f4232
opengl: Init compareMode for native textures;
bjornbytes Feb 19, 2020
238496d
Start core/gpu;
bjornbytes Feb 19, 2020
cb4a7a5
core/gpu: indirect drawing commands;
bjornbytes Feb 20, 2020
0620cad
core/gpu: gpu_set_vertex_buffers; fixes;
bjornbytes Feb 20, 2020
aadadb9
core/gpu: will it blend;
bjornbytes Feb 20, 2020
a658da7
core/gpu: Add all uncompressed texture formats;
bjornbytes Feb 20, 2020
6452f51
core/gpu: attribute formats;
bjornbytes Feb 20, 2020
7d2bec7
core/gpu: add vulkan backend;
bjornbytes Feb 20, 2020
f428cea
core/gpu: gl backend compiles;
bjornbytes Feb 20, 2020
b9b8062
core/gpu: texture views;
bjornbytes Feb 21, 2020
93d556b
zip: read compressed size from central directory;
bjornbytes Feb 21, 2020
3d3fb71
core/gpu: start shader stuff; coherent buffer mapping;
bjornbytes Feb 22, 2020
2cf6d7b
Improve lovr.filesystem.load errors;
bjornbytes Feb 22, 2020
5d8bf1d
Fix Source:setLooping assert;
bjornbytes Feb 22, 2020
b045d42
Opaque Buffer;
bjornbytes Feb 23, 2020
52d4f7e
Opaque Texture;
bjornbytes Feb 23, 2020
d034e8c
Opaque Canvas;
bjornbytes Feb 23, 2020
aabb8cb
Opaque Shader;
bjornbytes Feb 23, 2020
f8b8d42
Opaque Mesh; Opaque OpenGL;
bjornbytes Feb 23, 2020
ef7ebae
core/gpu: vulkan feature detection; rm stats;
bjornbytes Feb 23, 2020
fa771b0
Fix CMake;
bjornbytes Feb 23, 2020
69dd0d4
audio: rm paused and stopped states; rm rewind;
bjornbytes Feb 26, 2020
90b605f
Add restart cookie; lovr.event.restart; arg.restart;
bjornbytes Feb 26, 2020
0d09841
Shader:send doesn't error on unknown uniform;
bjornbytes Feb 28, 2020
1d6b761
oculus_mobile: Add handModels to bridge;
bjornbytes Mar 2, 2020
45648ba
Scope a variable better;
bjornbytes Mar 3, 2020
9c044ee
CMake: Don't exclude Lua lib targets;
bjornbytes Mar 3, 2020
8dcc977
Tup: emscripten support; LuaJIT flag;
bjornbytes Mar 3, 2020
a18121b
tup: fully support web builds;
bjornbytes Mar 4, 2020
6f6de92
Add preliminary WebXR backend;
bjornbytes Mar 5, 2020
c02839f
Allow anisotropy to be used with any TextureFilter;
bjornbytes Mar 5, 2020
a01cc5a
Fix lovr.graphics.getDefaultFilter;
bjornbytes Mar 6, 2020
6d0369d
Convert some collider functions to use vectors;
bjornbytes Mar 8, 2020
e553672
Fix sampler uniform error message enum;
bjornbytes Mar 14, 2020
37d8df4
Allow initializing empty TextureData with Blob;
bjornbytes Mar 29, 2020
aed0499
Add oculus_touch to action manifest;
bjornbytes Apr 3, 2020
077d90b
update ovr driver to newer frame submission api
shakesoda Apr 3, 2020
64362a0
Merge pull request #234 from shakesoda/patch-1
bjornbytes Apr 3, 2020
d8abfcf
Remove mat4_transform_project, it not only duplicates mat4_transform,…
mcclure Apr 5, 2020
89e2e6d
Merge pull request #236 from mcclure/no-mat4-project
bjornbytes Apr 6, 2020
14e79bf
implement haptics on oculus
shakesoda Apr 12, 2020
809d9b7
ignore haptics for non-hands
shakesoda Apr 12, 2020
34cef26
use clamp/max macros
shakesoda Apr 12, 2020
eb03795
Merge pull request #238 from shakesoda/patch-2
bjornbytes Apr 12, 2020
f297072
Merge driver-gamepad with current master
mcclure Apr 15, 2020
0ef8d74
Fix bugs: activate gamepad driver properly, multiple-detect bug
mcclure Apr 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ config/*
/debug.sh
/db
/lovr
/lovr.js
/lovr.worker.js
/lovr.html
/lovr.wasm
build
build-*
/libs
Expand Down
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option(LOVR_USE_OCULUS "Enable the LibOVR backend for the headset module (be sur
option(LOVR_USE_OCULUS_MOBILE "Enable the Oculus Mobile (Android) backend for the headset module" OFF)
option(LOVR_USE_DESKTOP_HEADSET "Enable the keyboard/mouse backend for the headset module" ON)
option(LOVR_USE_LEAP "Enable the Leap Motion backend for the headset module" OFF)
option(LOVR_USE_GAMEPAD "Enable the gamepad backend for desktop systems" ON)

option(LOVR_SYSTEM_ENET "Use the system-provided enet" OFF)
option(LOVR_SYSTEM_GLFW "Use the system-provided glfw" OFF)
Expand Down Expand Up @@ -72,6 +73,7 @@ elseif(ANDROID)
set(LOVR_USE_OCULUS OFF)
set(LOVR_USE_DESKTOP_HEADSET OFF)
set(LOVR_USE_OCULUS_MOBILE ON)
set(LOVR_USE_GAMEPAD OFF) # Requires GLFW currently
set(LOVR_BUILD_SHARED ON) # Android has only "activities"
elseif(UNIX)
find_package(PkgConfig)
Expand Down Expand Up @@ -148,7 +150,7 @@ else()
add_subdirectory(deps/lua lua)
include_directories(deps/lua/src ${CMAKE_BINARY_DIR}/lua)
set(LOVR_LUA liblua_static)
set_target_properties(lua luac liblua liblua_static PROPERTIES EXCLUDE_FROM_ALL 1)
set_target_properties(lua luac PROPERTIES EXCLUDE_FROM_ALL 1)
endif()
endif()

Expand Down Expand Up @@ -414,16 +416,11 @@ endif()
if(LOVR_ENABLE_GRAPHICS)
add_definitions(-DLOVR_ENABLE_GRAPHICS)
target_sources(lovr PRIVATE
src/modules/graphics/buffer.c
src/modules/graphics/canvas.c
src/modules/graphics/font.c
src/modules/graphics/graphics.c
src/modules/graphics/material.c
src/modules/graphics/mesh.c
src/modules/graphics/model.c
src/modules/graphics/opengl.c
src/modules/graphics/shader.c
src/modules/graphics/texture.c
src/api/l_graphics.c
src/api/l_graphics_canvas.c
src/api/l_graphics_font.c
Expand Down Expand Up @@ -476,6 +473,10 @@ if(LOVR_ENABLE_HEADSET)
add_definitions(-DLOVR_USE_LEAP)
target_sources(lovr PRIVATE src/modules/headset/leap.c)
endif()
if(LOVR_USE_GAMEPAD)
add_definitions(-DLOVR_USE_GAMEPAD)
target_sources(lovr PRIVATE src/modules/headset/gamepad.c)
endif()
endif()

if(LOVR_ENABLE_MATH)
Expand Down
4 changes: 3 additions & 1 deletion Tupfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include_rules
SRC += src/main.c
SRC += src/core/arr.c
SRC += src/core/fs.c
SRC_@(GPU) += src/core/gpu_@(GPU_BACKEND).c
SRC += src/core/maf.c
SRC += src/core/map.c
SRC += src/core/os_$(PLATFORM).c
Expand All @@ -26,6 +27,7 @@ SRC_@(HEADSET)@(OPENXR) += src/modules/headset/openxr.c
SRC_@(HEADSET)@(OCULUS) += src/modules/headset/oculus.c
SRC_@(HEADSET)@(VRAPI) += src/modules/headset/oculus_mobile.c
SRC_@(HEADSET)@(WEBVR) += src/modules/headset/webvr.c
SRC_@(HEADSET)@(WEBXR) += src/modules/headset/webxr.c
SRC_@(HEADSET)@(LEAP) += src/modules/headset/leap.c
SRC_@(MATH) += src/modules/math/*.c
SRC_@(PHYSICS) += src/modules/physics/*.c
Expand Down Expand Up @@ -69,5 +71,5 @@ SRC_@(GRAPHICS) += src/resources/shaders.c

: foreach $(RES) $(RES_y) |> !xd |> %f.h
: foreach $(SRC) $(SRC_y) $(SRC_yy) | src/resources/*.h |> !cc |> .obj/%B.o
: .obj/*.o |> !ld |> lovr
: .obj/*.o $(STATIC_LIBS) $(STATIC_LIBS_y) |> !ld |> lovr$(SUFFIX) | $(EXTRAS) $(EXTRAS_y)
: foreach $(LIBS) |> !cp |> libs/%b
71 changes: 55 additions & 16 deletions Tuprules.tup
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,84 @@ CFLAGS_@(OCULUS) += -DLOVR_USE_OCULUS
CFLAGS_@(OCULUS) += -I@(OCULUS_PATH)/LibOVR/Include
CFLAGS_@(VRAPI) += -DLOVR_USE_OCULUS_MOBILE
CFLAGS_@(WEBVR) += -DLOVR_USE_WEBVR
CFLAGS_@(WEBXR) += -DLOVR_USE_WEBXR
CFLAGS_@(LEAP) += -DLOVR_USE_LEAP

## Platforms
# A little gnarly, but basically you can set CONFIG_PLATFORM to pick a specific one, otherwise
# we use the builtin TUP_PLATFORM which is the current OS (so it won't work with android/web).
# Also macosx gets converted to macos
ifeq (@(PLATFORM),)
PLATFORM = @(TUP_PLATFORM)
else
PLATFORM = @(PLATFORM)
endif

ifeq ($(PLATFORM),macosx)
PLATFORM = macos
endif

ifeq ($(PLATFORM),macos)
LDFLAGS += -lobjc
LDFLAGS += -pagezero_size 10000 -image_base 100000000
ORIGIN = @executable_path
LDFLAGS_@(LUAJIT) += -pagezero_size 10000 -image_base 100000000
LDFLAGS += -Wl,-rpath,@executable_path/libs
SO = dylib
endif

ifeq ($(PLATFORM),linux)
LDFLAGS += -lm -lpthread
ORIGIN = \$ORIGIN
LDFLAGS += -Wl,-rpath,\$ORIGIN/libs
SO = so
endif

ifeq ($(PLATFORM),web)
SUFFIX = .html
EXTRAS = lovr.js lovr.wasm
EXTRAS_@(THREAD) += lovr.worker.js
LDFLAGS += -s USE_GLFW=3
LDFLAGS += -s USE_WEBGL2
LDFLAGS += -s FULL_ES2
LDFLAGS += -s FULL_ES3
LDFLAGS += -s GL_PREINITIALIZED_CONTEXT
LDFLAGS += -s FORCE_FILESYSTEM
LDFLAGS += -s EXPORTED_FUNCTIONS="[
LDFLAGS += '_main',
ifeq (@(WEBVR),y)
LDFLAGS += '_webvr_onAnimationFrame',
endif
ifeq (@(WEBXR),y)
LDFLAGS += '_lovrCanvasCreateFromHandle','_lovrGraphicsSetCamera',
endif
LDFLAGS += '_mat4_set','_mat4_identity','_mat4_invert','_mat4_multiply','_mat4_rotateQuat',
LDFLAGS += '_mat4_transform','_mat4_transformDirection'
LDFLAGS += ]"
LDFLAGS_@(WEBVR) += --js-library $(ROOT)/src/resources/webvr.js
LDFLAGS_@(WEBXR) += --js-library $(ROOT)/src/resources/webxr.js
LDFLAGS += --shell-file $(ROOT)/src/resources/lovr.html
CFLAGS_@(THREAD) += -s USE_PTHREADS=1
LDFLAGS_@(THREAD) += -s USE_PTHREADS=1
endif

## Libraries
ifeq (@(CMAKE_DEPS),y)
ifeq ($(PLATFORM),web)
CFLAGS += -I$(ROOT)/deps/lua/src -I$(ROOT)/build/lua
STATIC_LIBS += $(ROOT)/build/lua/liblua.a

CFLAGS_@(DATA) += -I$(ROOT)/deps/msdfgen
STATIC_LIBS_@(DATA) += $(ROOT)/build/lib_msdfgen/libmsdfgen.a

CFLAGS_@(PHYSICS) += -I$(ROOT)/deps/ode/include -I$(ROOT)/build/ode/include
STATIC_LIBS_@(PHYSICS) += $(ROOT)/build/ode/libode.a
else
ifeq (@(CMAKE_DEPS),y)

# enet
CFLAGS_@(ENET) += -I$(ROOT)/deps/enet/include
LDFLAGS_@(ENET) += -L$(ROOT)/build/enet -lenet

# LuaJIT
CFLAGS += -I$(ROOT)/deps/luajit/src
LDFLAGS += -L$(ROOT)/build/luajit/src -lluajit
LIBS += $(ROOT)/build/luajit/src/libluajit.$(SO)
# Lua
ifeq (@(LUAJIT),y)
CFLAGS += -I$(ROOT)/deps/luajit/src
LDFLAGS += -L$(ROOT)/build/luajit/src -lluajit
LIBS += $(ROOT)/build/luajit/src/libluajit.$(SO)
else
CFLAGS += -I$(ROOT)/deps/lua/src -I$(ROOT)/build/lua
LDFLAGS += -L$(ROOT)/build/lua -llua
endif

# msdfgen
CFLAGS_@(DATA) += -I$(ROOT)/deps/msdfgen
Expand All @@ -102,9 +142,8 @@ ifeq (@(CMAKE_DEPS),y)
LDFLAGS_@(AUDIO) += -L$(ROOT)/build/openal -lopenal
LIBS_@(AUDIO) += $(ROOT)/build/openal/libopenal.*$(SO)*

# Configure rpath to look for libraries in a `libs` folder next to the executable
LDFLAGS += -Wl,-rpath,$(ORIGIN)/libs
LIBS += $(LIBS_y)
endif
endif

CFLAGS += @(EXTRA_CFLAGS)
Expand Down
9 changes: 9 additions & 0 deletions config/default
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ CONFIG_LEAP=n
CONFIG_OCULUS_PATH=
CONFIG_LEAP_PATH=

## LuaJIT
CONFIG_LUAJIT=y

## OpenGL flavor
# Can be GL, GLES, or WEBGL. Ideally this should be autodetected though.
CONFIG_GL=GL

## Experimental renderer settings
# GPU enables the core/gpu renderer
# GPU_BACKEND is used to select the backend (gl, vk, wg)
CONFIG_GPU=n
CONFIG_GPU_BACKEND=gl
12 changes: 0 additions & 12 deletions src/api/l_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,6 @@ static int l_lovrAudioPause(lua_State* L) {
return 0;
}

static int l_lovrAudioResume(lua_State* L) {
lovrAudioResume();
return 0;
}

static int l_lovrAudioRewind(lua_State* L) {
lovrAudioRewind();
return 0;
}

static int l_lovrAudioSetDopplerEffect(lua_State* L) {
float factor = luax_optfloat(L, 1, 1.f);
float speedOfSound = luax_optfloat(L, 2, 343.29f);
Expand Down Expand Up @@ -237,8 +227,6 @@ static const luaL_Reg lovrAudio[] = {
{ "newMicrophone", l_lovrAudioNewMicrophone },
{ "newSource", l_lovrAudioNewSource },
{ "pause", l_lovrAudioPause },
{ "resume", l_lovrAudioResume },
{ "rewind", l_lovrAudioRewind },
{ "setDopplerEffect", l_lovrAudioSetDopplerEffect },
{ "setOrientation", l_lovrAudioSetOrientation },
{ "setPose", l_lovrAudioSetPose },
Expand Down
24 changes: 0 additions & 24 deletions src/api/l_audio_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ static int l_lovrSourceIsLooping(lua_State* L) {
return 1;
}

static int l_lovrSourceIsPaused(lua_State* L) {
lua_pushboolean(L, lovrSourceIsPaused(luax_checktype(L, 1, Source)));
return 1;
}

static int l_lovrSourceIsPlaying(lua_State* L) {
lua_pushboolean(L, lovrSourceIsPlaying(luax_checktype(L, 1, Source)));
return 1;
Expand All @@ -149,11 +144,6 @@ static int l_lovrSourceIsRelative(lua_State* L) {
return 1;
}

static int l_lovrSourceIsStopped(lua_State* L) {
lua_pushboolean(L, lovrSourceIsStopped(luax_checktype(L, 1, Source)));
return 1;
}

static int l_lovrSourcePause(lua_State* L) {
lovrSourcePause(luax_checktype(L, 1, Source));
return 0;
Expand All @@ -166,16 +156,6 @@ static int l_lovrSourcePlay(lua_State* L) {
return 0;
}

static int l_lovrSourceResume(lua_State* L) {
lovrSourceResume(luax_checktype(L, 1, Source));
return 0;
}

static int l_lovrSourceRewind(lua_State* L) {
lovrSourceRewind(luax_checktype(L, 1, Source));
return 0;
}

static int l_lovrSourceSeek(lua_State* L) {
Source* source = luax_checktype(L, 1, Source);
TimeUnit unit = luax_checkenum(L, 3, TimeUnits, "seconds", "TimeUnit");
Expand Down Expand Up @@ -306,14 +286,10 @@ const luaL_Reg lovrSource[] = {
{ "getVolume", l_lovrSourceGetVolume },
{ "getVolumeLimits", l_lovrSourceGetVolumeLimits },
{ "isLooping", l_lovrSourceIsLooping },
{ "isPaused", l_lovrSourceIsPaused },
{ "isPlaying", l_lovrSourceIsPlaying },
{ "isRelative", l_lovrSourceIsRelative },
{ "isStopped", l_lovrSourceIsStopped },
{ "pause", l_lovrSourcePause },
{ "play", l_lovrSourcePlay },
{ "resume", l_lovrSourceResume },
{ "rewind", l_lovrSourceRewind },
{ "seek", l_lovrSourceSeek },
{ "setCone", l_lovrSourceSetCone },
{ "setFalloff", l_lovrSourceSetFalloff },
Expand Down
16 changes: 11 additions & 5 deletions src/api/l_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,18 @@ static int l_lovrDataNewTextureData(lua_State* L) {
int width = luaL_checkinteger(L, 1);
int height = luaL_checkinteger(L, 2);
TextureFormat format = luax_checkenum(L, 3, TextureFormats, "rgba", "TextureFormat");
textureData = lovrTextureDataCreate(width, height, 0x0, format);
Blob* blob = lua_isnoneornil(L, 4) ? NULL : luax_checktype(L, 4, Blob);
textureData = lovrTextureDataCreate(width, height, blob, 0x0, format);
} else {
Blob* blob = luax_readblob(L, 1, "Texture");
bool flip = lua_isnoneornil(L, 2) ? true : lua_toboolean(L, 2);
textureData = lovrTextureDataCreateFromBlob(blob, flip);
lovrRelease(Blob, blob);
TextureData* source = luax_totype(L, 1, TextureData);
if (source) {
textureData = lovrTextureDataCreate(source->width, source->height, source->blob, 0x0, source->format);
} else {
Blob* blob = luax_readblob(L, 1, "Texture");
bool flip = lua_isnoneornil(L, 2) ? true : lua_toboolean(L, 2);
textureData = lovrTextureDataCreateFromBlob(blob, flip);
lovrRelease(Blob, blob);
}
}

luax_pushtype(L, TextureData, textureData);
Expand Down
20 changes: 18 additions & 2 deletions src/api/l_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void luax_checkvariant(lua_State* L, int index, Variant* variant) {
int type = lua_type(L, index);
switch (type) {
case LUA_TNIL:
case LUA_TNONE:
variant->type = TYPE_NIL;
break;

Expand Down Expand Up @@ -99,10 +100,12 @@ static int nextEvent(lua_State* L) {
case EVENT_QUIT:
if (event.data.quit.restart) {
lua_pushliteral(L, "restart");
luax_pushvariant(L, &event.data.quit.cookie);
return 3;
} else {
lua_pushnumber(L, event.data.quit.exitCode);
return 2;
}
return 2;

case EVENT_FOCUS:
lua_pushboolean(L, event.data.boolean.value);
Expand Down Expand Up @@ -173,9 +176,10 @@ static int l_lovrEventQuit(lua_State* L) {
EventData data;

int argType = lua_type(L, 1);
if (argType == LUA_TSTRING && 0 == strcmp("restart", lua_tostring(L, 1))) {
if (argType == LUA_TSTRING && !strcmp("restart", lua_tostring(L, 1))) {
data.quit.restart = true;
data.quit.exitCode = 0;
luax_checkvariant(L, 2, &data.quit.cookie);
} else if (argType == LUA_TNUMBER || lua_isnoneornil(L, 1)) {
data.quit.restart = false;
data.quit.exitCode = luaL_optint(L, 1, 0);
Expand All @@ -189,12 +193,24 @@ static int l_lovrEventQuit(lua_State* L) {
return 0;
}

static int l_lovrEventRestart(lua_State* L) {
EventData data;
data.quit.exitCode = 0;
data.quit.restart = true;
luax_checkvariant(L, 1, &data.quit.cookie);
EventType type = EVENT_QUIT;
Event event = { .type = type, .data = data };
lovrEventPush(event);
return 0;
}

static const luaL_Reg lovrEvent[] = {
{ "clear", l_lovrEventClear },
{ "poll", l_lovrEventPoll },
{ "pump", l_lovrEventPump },
{ "push", l_lovrEventPush },
{ "quit", l_lovrEventQuit },
{ "restart", l_lovrEventRestart },
{ NULL, NULL }
};

Expand Down
5 changes: 5 additions & 0 deletions src/api/l_filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ static void pushDirectoryItem(void* context, const char* path) {
static int luax_loadfile(lua_State* L, const char* path, const char* debug) {
size_t size;
void* buffer = luax_readfile(path, &size);
if (!buffer) {
lua_pushnil(L);
lua_pushfstring(L, "Could not load file '%s'", path);
return 2;
}
int status = luaL_loadbuffer(L, buffer, size, debug);
free(buffer);
switch (status) {
Expand Down
Loading