Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

OpenXR implementation #3428

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ npm install
npm run compress
```

## Enable OpenXR builds
You can enable OpenXR API for Oculus by adding this property to your `user.properties` file:

```ini
openxr=true
```

## Development troubleshooting

### `Device supports , but APK only supports armeabi-v7a[...]`
Expand Down
38 changes: 37 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,34 @@ target_link_libraries(native-lib native_app_glue)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
endif()

if(OCULUSVR)

if(OPENXR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DXR_USE_PLATFORM_ANDROID -DXR_USE_GRAPHICS_API_OPENGL_ES")
include_directories(
${CMAKE_SOURCE_DIR}/../third_party/OpenXR-SDK/include
${CMAKE_SOURCE_DIR}/../third_party/ovr_openxr_mobile_sdk/OpenXR/Include
${CMAKE_SOURCE_DIR}/../app/src/openxr/cpp
)
target_sources(
native-lib
PUBLIC
src/openxr/cpp/DeviceDelegateOpenXR.cpp
src/openxr/cpp/OpenXRSwapChain.cpp
src/openxr/cpp/OpenXRLayers.cpp
src/openxr/cpp/OpenXRInput.cpp
src/openxr/cpp/OpenXRExtensions.cpp
)
add_custom_command(TARGET native-lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../third_party/ovr_openxr_mobile_sdk/OpenXR/Libs/Android/${ANDROID_ABI}/Release/libopenxr_oculus.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libopenxr_oculus.so
)
elseif(OCULUSVR)
include_directories(
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Include
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Include
${CMAKE_SOURCE_DIR}/../app/src/oculusvr/cpp
)
target_sources(
native-lib
PUBLIC
Expand All @@ -95,6 +122,9 @@ add_custom_command(TARGET native-lib POST_BUILD
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libvrapi.so
)
endif()

if(OCULUSVR)
add_custom_command(TARGET native-lib POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/../third_party/OVRPlatformSDK/Android/libs/${ANDROID_ABI}/libovrplatformloader.so
Expand All @@ -117,8 +147,14 @@ find_library( # Sets the name of the path variable.
android )

add_library(oculusvr-lib SHARED IMPORTED)
if(OPENXR)
set_target_properties(oculusvr-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../third_party/ovr_openxr_mobile_sdk/OpenXR/Libs/Android/${ANDROID_ABI}/Release/libopenxr_oculus.so )
else()
set_target_properties(oculusvr-lib PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../third_party/ovr_mobile/VrApi/Libs/Android/${ANDROID_ABI}/Release/libvrapi.so )
endif()


add_library(ovrplatform-lib SHARED IMPORTED)
set_target_properties(ovrplatform-lib PROPERTIES IMPORTED_LOCATION
Expand Down
35 changes: 20 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ def getUseDebugSigningOnRelease = { ->
return false
}

def getOpenXRFlags = { ->
if (gradle.hasProperty("userProperties.openxr")) {
return gradle."userProperties.openxr" == "true" ? " -DOPENXR" : ""
}
return ""
}

def getOpenXRCMakeFlags = { ->
if (gradle.hasProperty("userProperties.openxr")) {
return gradle."userProperties.openxr" == "true" ? "-DOPENXR=ON" : ""
}
return ""
}

// Glean: Generate markdown docs for the collected metrics.
ext.gleanGenerateMarkdownDocs = true
ext.gleanDocsDirectory = "$rootDir/docs"
Expand Down Expand Up @@ -120,11 +134,8 @@ android {
dimension "platform"
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
" -DOCULUSVR -DSTORE_BUILD=0"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
cppFlags "-DOCULUSVR -DSTORE_BUILD=0" + getOpenXRFlags()
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON", getOpenXRCMakeFlags()
}
}
manifestPlaceholders = [ headtrackingRequired:"false", permissionToRemove:"android.permission.RECEIVE_BOOT_COMPLETED" ]
Expand All @@ -134,11 +145,8 @@ android {
dimension "platform"
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
" -DOCULUSVR -DSTORE_BUILD=1"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
cppFlags "-DOCULUSVR -DSTORE_BUILD=1" + getOpenXRFlags()
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON", getOpenXRCMakeFlags()
}
}
manifestPlaceholders = [ headtrackingRequired:"false", permissionToRemove:"android.permission.RECEIVE_BOOT_COMPLETED" ]
Expand All @@ -148,11 +156,8 @@ android {
dimension "platform"
externalNativeBuild {
cmake {
cppFlags " -I" + file("${project.rootDir}/third_party/ovr_mobile/VrApi/Include").absolutePath +
" -I" + file("${project.rootDir}/third_party/OVRPlatformSDK/Include").absolutePath +
" -I" + file("${project.rootDir}/app/src/oculusvr/cpp").absolutePath +
" -DOCULUSVR -DSTORE_BUILD=1"
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON"
cppFlags "-DOCULUSVR -DSTORE_BUILD=1" + getOpenXRFlags()
arguments "-DVR_SDK_LIB=oculusvr-lib", "-DVR_SDK_EXTRA_LIB=ovrplatform-lib", "-DOCULUSVR=ON", getOpenXRCMakeFlags()
}
}
manifestPlaceholders = [ headtrackingRequired:"false", permissionToRemove:"android.permission.CAMERA" ]
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/cpp/SplashAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ struct SplashAnimation::State {
return;
}

read->Bind(GL_READ_FRAMEBUFFER);
layer->Bind(GL_DRAW_FRAMEBUFFER);
VRB_GL_CHECK(glClearColor(0.0, 0.0f, 0.0f, 0.0f));
VRB_GL_CHECK(glClear(GL_COLOR_BUFFER_BIT));
read->Bind(GL_READ_FRAMEBUFFER);
VRB_GL_CHECK(glBlitFramebuffer(0, 0, aTexture->GetWidth(), aTexture->GetHeight(),
0, 0, aTexture->GetWidth(), aTexture->GetHeight(),
GL_COLOR_BUFFER_BIT, GL_LINEAR));
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#include <android_native_app_glue.h>
#include <cstdlib>
#include <vrb/RunnableQueue.h>
#if defined(OCULUSVR)
#if defined(OPENXR)
#include "DeviceDelegateOpenXR.h"
#elif defined(OCULUSVR)
#include "DeviceDelegateOculusVR.h"
#endif

Expand All @@ -28,7 +30,10 @@

using namespace crow;

#if defined(OCULUSVR)
#if defined(OPENXR)
typedef DeviceDelegateOpenXR PlatformDeviceDelegate;
typedef DeviceDelegateOpenXRPtr PlatformDeviceDelegatePtr;
#elif defined(OCULUSVR)
typedef DeviceDelegateOculusVR PlatformDeviceDelegate;
typedef DeviceDelegateOculusVRPtr PlatformDeviceDelegatePtr;
#endif
Expand Down Expand Up @@ -232,8 +237,6 @@ android_main(android_app *aAppState) {
pSource->process(aAppState, pSource);
}



// Check if we are exiting.
if (aAppState->destroyRequested != 0) {
sAppContext->mEgl->MakeCurrent();
Expand All @@ -253,10 +256,17 @@ android_main(android_app *aAppState) {
sAppContext->mEgl->MakeCurrent();
}
sAppContext->mQueue->ProcessRunnables();

if (!BrowserWorld::Instance().IsPaused() && sAppContext->mDevice->IsInVRMode()) {
VRB_GL_CHECK(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
BrowserWorld::Instance().Draw();
}
#if defined(OPENXR)
else {
// OpenXR requires to wait for the XR_SESSION_STATE_READY to start presenting
// We need to call ProcessEvents to make sure we receive the event.
sAppContext->mDevice->ProcessEvents();
}
#endif
}
}

Expand Down
Loading