mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 17:52:26 +02:00
get QtActivity notifications about GVR changes
This commit is contained in:
parent
976c3b633b
commit
43e907ec83
5 changed files with 63 additions and 54 deletions
|
@ -9,7 +9,7 @@
|
|||
<meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_dual"/>
|
||||
|
||||
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation"
|
||||
android:name="org.qtproject.qt5.android.bindings.QtActivity"
|
||||
android:name="${ANDROID_ACTIVITY_NAME}"
|
||||
android:label="@string/AppDisplayName"
|
||||
android:screenOrientation="landscape"
|
||||
android:launchMode="singleTop"
|
||||
|
|
|
@ -39,20 +39,6 @@ macro(qt_create_apk)
|
|||
|
||||
# create "strings.xml"
|
||||
configure_file("${ANDROID_THIS_DIRECTORY}/strings.xml.in" "${ANDROID_APK_BUILD_DIR}/res/values/strings.xml")
|
||||
|
||||
# copy the res folder from the target to the apk build dir
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/res" "${ANDROID_APK_BUILD_DIR}/res"
|
||||
)
|
||||
|
||||
# copy the assets folder from the target to the apk build dir
|
||||
add_custom_command(
|
||||
TARGET ${TARGET_NAME}
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/assets" "${ANDROID_APK_BUILD_DIR}/assets"
|
||||
)
|
||||
|
||||
# figure out where the qt dir is
|
||||
get_filename_component(QT_DIR "${QT_CMAKE_PREFIX_PATH}/../../" ABSOLUTE)
|
||||
|
@ -109,9 +95,29 @@ macro(qt_create_apk)
|
|||
|
||||
configure_file("${ANDROID_THIS_DIRECTORY}/deployment-file.json.in" "${TARGET_NAME}-deployment.json")
|
||||
|
||||
# copy the res folder from the target to the apk build dir
|
||||
add_custom_target(
|
||||
${TARGET_NAME}-copy-res
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/res" "${ANDROID_APK_BUILD_DIR}/res"
|
||||
)
|
||||
|
||||
# copy the assets folder from the target to the apk build dir
|
||||
add_custom_target(
|
||||
${TARGET_NAME}-copy-assets
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/assets" "${ANDROID_APK_BUILD_DIR}/assets"
|
||||
)
|
||||
|
||||
# copy the java folder from src to the apk build dir
|
||||
add_custom_target(
|
||||
${TARGET_NAME}-copy-java
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/java" "${ANDROID_APK_BUILD_DIR}/src"
|
||||
)
|
||||
|
||||
# use androiddeployqt to create the apk
|
||||
add_custom_target(${TARGET_NAME}-apk
|
||||
COMMAND ${ANDROID_DEPLOY_QT} --input "${TARGET_NAME}-deployment.json" --output "${ANDROID_APK_OUTPUT_DIR}" --android-platform android-${ANDROID_API_LEVEL} --install --verbose --deployment bundled "\\$(ARGS)"
|
||||
DEPENDS ${TARGET_NAME}
|
||||
DEPENDS ${TARGET_NAME} ${TARGET_NAME}-copy-res ${TARGET_NAME}-copy-assets ${TARGET_NAME}-copy-java
|
||||
)
|
||||
|
||||
|
||||
endmacro()
|
|
@ -62,7 +62,7 @@ if (NOT ANDROID)
|
|||
|
||||
else (NOT ANDROID)
|
||||
set(_VRLIB_JNI_DIR "VRLib/jni")
|
||||
set(_VRLIB_LIBS_DIR "VRLib/libs/armeabi-v7a")
|
||||
set(_VRLIB_LIBS_DIR "VRLib/obj/local/armeabi-v7a")
|
||||
|
||||
find_path(LIBOVR_VRLIB_DIR VRLib.vcxproj PATH_SUFFIXES VRLib HINTS ${LIBOVR_SEARCH_DIRS})
|
||||
|
||||
|
@ -72,7 +72,7 @@ else (NOT ANDROID)
|
|||
find_path(MINIZIP_DIR minizip.c PATH_SUFFIXES ${_VRLIB_JNI_DIR}/3rdParty/minizip HINTS ${LIBOVR_SEARCH_DIRS})
|
||||
find_path(JNI_DIR VrCommon.h PATH_SUFFIXES ${_VRLIB_JNI_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
|
||||
|
||||
find_library(LIBOVR_LIBRARY_RELEASE NAMES OculusPlugin PATH_SUFFIXES ${_VRLIB_LIBS_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
|
||||
find_library(LIBOVR_LIBRARY_RELEASE NAMES oculus PATH_SUFFIXES ${_VRLIB_LIBS_DIR} HINTS ${LIBOVR_SEARCH_DIRS})
|
||||
endif (NOT ANDROID)
|
||||
|
||||
select_library_configurations(LIBOVR)
|
||||
|
@ -84,7 +84,8 @@ if (APPLE)
|
|||
list(APPEND LIBOVR_LIBRARIES ${IOKit} ${ApplicationServices})
|
||||
list(APPEND LIBOVR_ARGS_LIST IOKit ApplicationServices)
|
||||
elseif (ANDROID)
|
||||
list(APPEND LIBOVR_ARGS_LIST LIBOVR_VRLIB_DIR MINIZIP_DIR JNI_DIR)
|
||||
list(APPEND LIBOVR_ANDROID_LIBRARIES "-lGLESv3" "-lEGL" "-landroid" "-lOpenMAXAL" "-llog" "-lz" "-lOpenSLES")
|
||||
list(APPEND LIBOVR_ARGS_LIST LIBOVR_ANDROID_LIBRARIES LIBOVR_VRLIB_DIR MINIZIP_DIR JNI_DIR)
|
||||
elseif (UNIX)
|
||||
list(APPEND LIBOVR_LIBRARIES "${UDEV_LIBRARY}" "${XINERAMA_LIBRARY}")
|
||||
list(APPEND LIBOVR_ARGS_LIST UDEV_LIBRARY XINERAMA_LIBRARY)
|
||||
|
|
|
@ -6,7 +6,9 @@ set(ANDROID_APK_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/apk")
|
|||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ANDROID_APK_OUTPUT_DIR}/libs/${ANDROID_ABI}")
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
|
||||
setup_hifi_library(Gui Widgets)
|
||||
setup_hifi_library(Gui Widgets AndroidExtras)
|
||||
|
||||
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
|
||||
|
||||
include_glm()
|
||||
|
||||
|
@ -17,15 +19,16 @@ set(ANDROID_SDK_ROOT $ENV{ANDROID_HOME})
|
|||
set(ANDROID_APP_DISPLAY_NAME Interface)
|
||||
set(ANDROID_API_LEVEL 19)
|
||||
set(ANDROID_APK_PACKAGE io.highfidelity.gvrinterface)
|
||||
set(ANDROID_ACTIVITY_NAME io.highfidelity.gvrinterface.GVRActivity)
|
||||
|
||||
find_package(LibOVR REQUIRED)
|
||||
target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES})
|
||||
target_link_libraries(${TARGET_NAME} ${LIBOVR_LIBRARIES} ${LIBOVR_ANDROID_LIBRARIES})
|
||||
include_directories(SYSTEM ${LIBOVR_INCLUDE_DIRS})
|
||||
|
||||
# we need VRLib, so add a project.properties to our apk build folder that says that
|
||||
file(RELATIVE_PATH RELATIVE_VRLIB_PATH ${ANDROID_APK_OUTPUT_DIR} "${LIBOVR_VRLIB_DIR}")
|
||||
file(WRITE "${ANDROID_APK_BUILD_DIR}/project.properties" "android.library.reference.1=${RELATIVE_VRLIB_PATH}")
|
||||
|
||||
list(APPEND IGNORE_COPY_LIBS ${LIBOVR_LIBRARIES})
|
||||
list(APPEND IGNORE_COPY_LIBS ${LIBOVR_ANDROID_LIBRARIES})
|
||||
|
||||
qt_create_apk()
|
|
@ -9,12 +9,12 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QtAndroidExtras/QAndroidJniEnvironment>
|
||||
#include <QtAndroidExtras/QAndroidJniObject>
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
#include <QtWidgets/QMenuBar>
|
||||
|
||||
#include <OVR.h>
|
||||
#include <VrApi/VrApi.h>
|
||||
#include <VrApi/VrApi_local.h>
|
||||
#include <VrApi/LocalPreferences.h>
|
||||
|
||||
#include "GVRMainWindow.h"
|
||||
#include "RenderingClient.h"
|
||||
|
@ -27,6 +27,13 @@ GVRInterface::GVRInterface(int argc, char* argv[]) :
|
|||
_client = new RenderingClient(this);
|
||||
|
||||
connect(this, &QGuiApplication::applicationStateChanged, this, &GVRInterface::handleApplicationStateChange);
|
||||
|
||||
QAndroidJniEnvironment jniEnv;
|
||||
|
||||
QPlatformNativeInterface* interface = QApplication::platformNativeInterface();
|
||||
jobject activity = (jobject) interface->nativeResourceForIntegration("QtActivity");
|
||||
|
||||
ovr_RegisterHmtReceivers(&*jniEnv, activity);
|
||||
}
|
||||
|
||||
void GVRInterface::handleApplicationStateChange(Qt::ApplicationState state) {
|
||||
|
@ -47,35 +54,27 @@ void GVRInterface::handleApplicationStateChange(Qt::ApplicationState state) {
|
|||
void GVRInterface::resumeOVR() {
|
||||
// Reload local preferences, in case we are coming back from a
|
||||
// switch to the dashboard that changed them.
|
||||
ovr_UpdateLocalPreferences();
|
||||
|
||||
// Default vrModeParms
|
||||
ovrModeParms vrModeParms;
|
||||
ovrHmdInfo hmdInfo;
|
||||
|
||||
vrModeParms.AsynchronousTimeWarp = true;
|
||||
vrModeParms.AllowPowerSave = true;
|
||||
vrModeParms.DistortionFileName = NULL;
|
||||
vrModeParms.EnableImageServer = false;
|
||||
vrModeParms.CpuLevel = 2;
|
||||
vrModeParms.GpuLevel = 2;
|
||||
vrModeParms.GameThreadTid = 0;
|
||||
|
||||
const char* cpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_CPU_LEVEL, "-1" );
|
||||
const int cpuLevel = atoi( cpuLevelStr );
|
||||
if ( cpuLevel >= 0 ) {
|
||||
vrModeParms.CpuLevel = cpuLevel;
|
||||
qDebug() << "Local Preferences: Setting cpuLevel" << vrModeParms.CpuLevel;
|
||||
}
|
||||
|
||||
const char* gpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_GPU_LEVEL, "-1" );
|
||||
const int gpuLevel = atoi( gpuLevelStr );
|
||||
if ( gpuLevel >= 0 ) {
|
||||
vrModeParms.GpuLevel = gpuLevel;
|
||||
qDebug() << "Local Preferences: Setting gpuLevel" << vrModeParms.GpuLevel;
|
||||
}
|
||||
|
||||
ovr_EnterVrMode(vrModeParms, &hmdInfo);
|
||||
// ovr_UpdateLocalPreferences();
|
||||
//
|
||||
// // Default vrModeParms
|
||||
// ovrModeParms vrModeParms;
|
||||
// ovrHmdInfo hmdInfo;
|
||||
//
|
||||
// const char* cpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_CPU_LEVEL, "-1" );
|
||||
// const int cpuLevel = atoi( cpuLevelStr );
|
||||
// if ( cpuLevel >= 0 ) {
|
||||
// vrModeParms.CpuLevel = cpuLevel;
|
||||
// qDebug() << "Local Preferences: Setting cpuLevel" << vrModeParms.CpuLevel;
|
||||
// }
|
||||
//
|
||||
// const char* gpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_GPU_LEVEL, "-1" );
|
||||
// const int gpuLevel = atoi( gpuLevelStr );
|
||||
// if ( gpuLevel >= 0 ) {
|
||||
// vrModeParms.GpuLevel = gpuLevel;
|
||||
// qDebug() << "Local Preferences: Setting gpuLevel" << vrModeParms.GpuLevel;
|
||||
// }
|
||||
//
|
||||
// ovr_EnterVrMode(vrModeParms, &hmdInfo);
|
||||
}
|
||||
|
||||
void GVRInterface::pauseOVR() {
|
||||
|
|
Loading…
Reference in a new issue