From e7d4e6cf7be2ad16e164b598f8a683def4b3d930 Mon Sep 17 00:00:00 2001 From: bjorn Date: Mon, 27 Jul 2020 13:58:52 -0600 Subject: [PATCH] Start pico headset backend; --- .gitignore | 1 + CMakeLists.txt | 27 ++++- src/modules/headset/headset_pico.c | 130 +++++++++++++++++++++++++ src/resources/Activity_pico.java | 71 ++++++++++++++ src/resources/AndroidManifest_pico.xml | 13 +++ 5 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 src/modules/headset/headset_pico.c create mode 100644 src/resources/Activity_pico.java create mode 100644 src/resources/AndroidManifest_pico.xml diff --git a/.gitignore b/.gitignore index b72139f3..82c999eb 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ bin .vs /test deps/VrApi +deps/pico diff --git a/CMakeLists.txt b/CMakeLists.txt index cd1bdce9..cf8431b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ option(LOVR_USE_WEBVR "Enable the WebVR backend for the headset module" OFF) option(LOVR_USE_WEBXR "Enable the WebXR backend for the headset module" OFF) option(LOVR_USE_OCULUS "Enable the LibOVR backend for the headset module (be sure to also set LOVR_OCULUS_PATH to point to the Oculus SDK)" OFF) 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_LEAP "Enable the Leap Motion backend for the headset module" OFF) @@ -296,6 +297,14 @@ if(LOVR_ENABLE_HEADSET AND LOVR_USE_VRAPI) set(LOVR_VRAPI VrApi) endif() +# Pico Native SDK (1.3.3) +if(LOVR_ENABLE_HEADSET AND LOVR_USE_PICO) + set(LOVR_PICO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/deps/pico" CACHE STRING "The path to the Pico SDK folder (unzipped aar)") + add_library(Pvr_NativeSDK SHARED IMPORTED) + set_target_properties(Pvr_NativeSDK PROPERTIES IMPORTED_LOCATION "${LOVR_PICO_PATH}/jni/${ANDROID_ABI}/libPvr_NativeSDK.so") + set(LOVR_PICO Pvr_NativeSDK) +endif() + # pthreads if(LOVR_ENABLE_THREAD) if(NOT WIN32 AND NOT EMSCRIPTEN) @@ -367,6 +376,7 @@ target_link_libraries(lovr ${LOVR_OPENXR} ${LOVR_OCULUS} ${LOVR_VRAPI} + ${LOVR_PICO} ${LOVR_LEAP} ${LOVR_PTHREADS} ${LOVR_EMSCRIPTEN_FLAGS} @@ -472,6 +482,10 @@ if(LOVR_ENABLE_HEADSET) add_definitions(-DLOVR_USE_VRAPI) target_sources(lovr PRIVATE src/modules/headset/headset_vrapi.c) endif() + if(LOVR_USE_PICO) + add_definitions(-DLOVR_USE_PICO) + target_sources(lovr PRIVATE src/modules/headset/headset_pico.c) + endif() if(LOVR_USE_WEBVR) add_definitions(-DLOVR_USE_WEBVR) target_sources(lovr PRIVATE src/modules/headset/headset_webvr.c) @@ -636,13 +650,22 @@ elseif(ANDROID) PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/${ANDROID_ABI}" ) - # Imported targets need to have their libraries manually copied to lib/ - # We also figure out which Java class (Activity) we're using here + # Flavor-specific config: + # - Imported targets need to have their libraries manually copied to lib/ + # - Figure out which Java class (Activity) and AndroidManifest.xml to use + # - Oculus uses the regular android os layer, pico implements its own in the headset backend + # - Some of the Pico SDK is in a jar that has to be added to the classpath and dx invocation + # TODO error (probably way earlier) if both USE_VRAPI and USE_PICO aren't defined if(LOVR_USE_VRAPI) get_target_property(VRAPI_LIB ${LOVR_VRAPI} IMPORTED_LOCATION) file(COPY ${VRAPI_LIB} DESTINATION lib/${ANDROID_ABI}) set(ANDROID_MANIFEST "${CMAKE_CURRENT_SOURCE_DIR}/src/resources/AndroidManifest_vrapi.xml" CACHE STRING "The AndroidManifest.xml path") set(ANDROID_ACTIVITY "vrapi") + elseif(LOVR_USE_PICO) + get_target_property(PICO_LIB ${LOVR_PICO} IMPORTED_LOCATION) + file(COPY ${PICO_LIB} DESTINATION lib/${ANDROID_ABI}) + set(ANDROID_MANIFEST "${CMAKE_CURRENT_SOURCE_DIR}/src/resources/AndroidManifest_pico.xml" CACHE STRING "The AndroidManifest.xml path") + set(ANDROID_ACTIVITY "pico") endif() # Make an apk diff --git a/src/modules/headset/headset_pico.c b/src/modules/headset/headset_pico.c new file mode 100644 index 00000000..4940d6a6 --- /dev/null +++ b/src/modules/headset/headset_pico.c @@ -0,0 +1,130 @@ +#include "headset/headset.h" +#include + +static struct { + float offset; +} state; + +static bool pico_init(float offset, uint32_t msaa) { + state.offset = offset; + return true; +} + +static void pico_destroy(void) { + memset(&state, 0, sizeof(state)); +} + +static bool pico_getName(char* name, size_t length) { + return false; +} + +static HeadsetOrigin pico_getOriginType(void) { + return ORIGIN_HEAD; +} + +static double pico_getDisplayTime(void) { + return 0.; +} + +static void pico_getDisplayDimensions(uint32_t* width, uint32_t* height) { + *width = 0; + *height = 0; +} + +static const float* pico_getDisplayMask(uint32_t* count) { + *count = 0; + return NULL; +} + +static uint32_t pico_getViewCount(void) { + return 2; +} + +static bool pico_getViewPose(uint32_t view, float* position, float* orientation) { + return false; +} + +static bool pico_getViewAngles(uint32_t view, float* left, float* right, float* up, float* down) { + return false; +} + +static void pico_getClipDistance(float* clipNear, float* clipFar) { + *clipNear = 0.f; + *clipFar = 0.f; +} + +static void pico_setClipDistance(float clipNear, float clipFar) { + // +} + +static void pico_getBoundsDimensions(float* width, float* depth) { + *width = *depth = 0.f; +} + +static const float* pico_getBoundsGeometry(uint32_t* count) { + *count = 0; + return NULL; +} + +static bool pico_getPose(Device device, float* position, float* orientation) { + return false; +} + +static bool pico_getVelocity(Device device, float* velocity, float* angularVelocity) { + return false; +} + +static bool pico_isDown(Device device, DeviceButton button, bool* down, bool* changed) { + return false; +} + +static bool pico_isTouched(Device device, DeviceButton button, bool* touched) { + return false; +} + +static bool pico_getAxis(Device device, DeviceAxis axis, float* value) { + return false; +} + +static bool pico_vibrate(Device device, float strength, float duration, float frequency) { + return false; +} + +static struct ModelData* pico_newModelData(Device device) { + return NULL; +} + +static void pico_renderTo(void (*callback)(void*), void* userdata) { + // +} + +static void pico_update(float dt) { + // +} + +HeadsetInterface lovrHeadsetPicoDriver = { + .driverType = DRIVER_PICO, + .init = pico_init, + .destroy = pico_destroy, + .getName = pico_getName, + .getOriginType = pico_getOriginType, + .getDisplayTime = pico_getDisplayTime, + .getDisplayDimensions = pico_getDisplayDimensions, + .getDisplayMask = pico_getDisplayMask, + .getViewCount = pico_getViewCount, + .getViewPose = pico_getViewPose, + .getViewAngles = pico_getViewAngles, + .getClipDistance = pico_getClipDistance, + .setClipDistance = pico_setClipDistance, + .getBoundsDimensions = pico_getBoundsDimensions, + .getBoundsGeometry = pico_getBoundsGeometry, + .getPose = pico_getPose, + .getVelocity = pico_getVelocity, + .isDown = pico_isDown, + .isTouched = pico_isTouched, + .getAxis = pico_getAxis, + .vibrate = pico_vibrate, + .newModelData = pico_newModelData, + .renderTo = pico_renderTo, + .update = pico_update +}; diff --git a/src/resources/Activity_pico.java b/src/resources/Activity_pico.java new file mode 100644 index 00000000..acb20169 --- /dev/null +++ b/src/resources/Activity_pico.java @@ -0,0 +1,71 @@ +package org.lovr.app; + +import android.os.Bundle; + +import com.picovr.vractivity.Eye; +import com.picovr.vractivity.HmdState; +import com.picovr.vractivity.RenderInterface; +import com.picovr.vractivity.VRActivity; + +public class Activity extends VRActivity implements RenderInterface { + + // Activity + + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + } + + public void onPause() { + super.onPause(); + } + + public void onResume() { + super.onResume(); + } + + // RenderInterface + + public void initGL(int width, int height) { + // + } + + public void onFrameBegin(HmdState state) { + // + } + + public void onDrawEye(Eye eye) { + // + } + + public void onFrameEnd() { + // + } + + public void onRenderPause() { + // + } + + public void onRenderResume() { + // + } + + public void onRendererShutdown() { + // + } + + public void surfaceChangedCallBack(int width, int height) { + // + } + + public void renderEventCallBack(int i) { + // + } + + public void onTouchEvent() { + // + } + + static { + System.loadLibrary("lovr"); + } +} diff --git a/src/resources/AndroidManifest_pico.xml b/src/resources/AndroidManifest_pico.xml new file mode 100644 index 00000000..537727f3 --- /dev/null +++ b/src/resources/AndroidManifest_pico.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + +