GodotVR / godot_oculus_mobile

Godot Oculus mobile drivers (Oculus Go / Oculus Quest)
MIT License
169 stars 34 forks source link

Migrate OVRMobile plugin to godot-cpp #100

Closed m4gr3d closed 4 years ago

m4gr3d commented 4 years ago

This PR migrates the Oculus mobile plugin to godot-cpp.

At the expense of binary size increase, this enables to leverage the rich apis providing by the godot-cpp library to improve the plugin functionality.

m4gr3d commented 4 years ago

@NeoSpark314 @BastiaanOlij I'd appreciate your feedback on this change to the plugin. Thanks!

NeoSpark314 commented 4 years ago

I just tried to build it; I did a git submodule update --init --recursive to get the godot headers but when I build I get the following error:

  In file included from ../../../../src/main/cpp\ovr_mobile_session.h:9:

  In file included from ../../../../src/main/cpp/framebuffer.h:15:

  In file included from ../../../../src/main/cpp/common.h:48:

  In file included from ../../../../libs/godot-cpp/include\core/Godot.hpp:12:

  ../../../../libs/godot-cpp/include/core/Ref.hpp:5:10: fatal error: 'Reference.hpp' file not found

  #include "Reference.hpp"

Do you have an idea what I might be missing?

m4gr3d commented 4 years ago

I just tried to build it; I did a git submodule update --init --recursive to get the godot headers but when I build I get the following error:

  In file included from ../../../../src/main/cpp\ovr_mobile_session.h:9:

  In file included from ../../../../src/main/cpp/framebuffer.h:15:

  In file included from ../../../../src/main/cpp/common.h:48:

  In file included from ../../../../libs/godot-cpp/include\core/Godot.hpp:12:

  ../../../../libs/godot-cpp/include/core/Ref.hpp:5:10: fatal error: 'Reference.hpp' file not found

  #include "Reference.hpp"

Do you have an idea what I might be missing?

@NeoSpark314 Sorry, I missed a step. Once you run the git submodule command, you must generate the godot-cpp bindings by following these steps.

I'll update the readme accordingly.

NeoSpark314 commented 4 years ago

Thanks @m4gr3d; I build the libgodot-cpp files now (both libgodot-cpp.android.debug.arm64v8.a and libgodot-cpp.android.debug.armv7.a; but now I get a lot of linker errors (below is just a part of it); maybe I missed something in the generation? :

  [35/35] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\libgodot_ovrmobile.so
  FAILED: cmd.exe /C "cd . && D:\software\android\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=armv7-none-linux-androideabi18 --gcc-toolchain=D:/software/android/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/software/android/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security  -std=c++14 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments   -Wl -shared -Wl,-soname,libgodot_ovrmobile.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\libgodot_ovrmobile.so CMakeFiles/godot_ovrmobile.dir/src/main/cpp/api/ovr_display_refresh_rate.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/api/ovr_guardian_system.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/api/ovr_init_config.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/api/ovr_input.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/api/ovr_performance.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/api/ovr_tracking_transform.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/api/ovr_utilities.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/common.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/framebuffer.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/arvr_interface.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/godot_ovrmobile.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/nativescript_common.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_display_refresh_rate_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_guardian_system_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_hand_tracking_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_init_config_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_input_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_performance_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_tracking_transform_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_utilities_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/gdnative/nativescript/ovr_vr_api_proxy_ns.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/jni_common.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_display_refresh_rate_jni.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_guardian_system_jni.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_init_config_jni.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_input_jni.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_mobile_plugin_jni.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_mobile_plugin_wrapper.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_performance_jni.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_tracking_transform_jni.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/jni/ovr_utilities_jni.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/ovr_mobile_controller.cpp.o CMakeFiles/godot_ovrmobile.dir/src/main/cpp/ovr_mobile_session.cpp.o  -landroid -llog -lEGL -lGLESv3 ../../../../libs/ovr_sdk_mobile/VrApi/Libs/Android/armeabi-v7a/Debug/libvrapi.so -latomic -lm && cd ."
  D:\programming\godot\2.0_godot_oculus_mobile\plugin/src\main\cpp\api\ovr_utilities.cpp:33: error: undefined reference to 'godot::String::empty() const'

  D:\programming\godot\2.0_godot_oculus_mobile\plugin/src\main\cpp\api\ovr_utilities.cpp:34: error: undefined reference to 'godot::String::utf8() const'

...

  D:\programming\godot\2.0_godot_oculus_mobile\plugin/src\main\cpp\jni\ovr_mobile_plugin_wrapper.cpp:0: error: undefined reference to 'android_api'

  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
m4gr3d commented 4 years ago

Did you try to clean (delete) the build directories after generating the Godot cpp bindings and attempting the build again?

NeoSpark314 commented 4 years ago

I tried a gradlew.bat clean and manually deleted the plugin\build folder; but in both cases I still get the same linker error. But from the linker command line call I posted above above it seems to not link against the godot-cpp .so at all.

m4gr3d commented 4 years ago

@NeoSpark314 Do you mind restarting the entire process (all the way from checking out the branch) and provide a screenshot of all the terminal commands you enter. I'll use the screenshot and replicate exactly what you did to see if I can replicate the linker error.

NeoSpark314 commented 4 years ago

@m4gr3d yes; I'll do this; I report back when I'm through

NeoSpark314 commented 4 years ago

@m4gr3d I did a clean co and tried to build; now I have a new error (see last screeshots):

cap01 cap02 cap03 cap04 cap05 cap06

cap07

m4gr3d commented 4 years ago

@NeoSpark314 According to stack overflow the kotlin error might be caused by gradle unable to find the Android SDK. As mentioned in the post, try also setting ANDROID_HOME on your path variable.

m4gr3d commented 4 years ago

@NeoSpark314 In my own shell, I have ANDROID_HOME instead of ANDROID_SDK_HOME set as the environment variable.

m4gr3d commented 4 years ago

@NeoSpark314 Also, I didn't see it in your screenshot, but don't forget to setup the ovr_sdk_mobile directory in your freshly checked-out directory. Just ran into the error while following your steps.

m4gr3d commented 4 years ago

@NeoSpark314 I can confirm the issue is caused by setting ANDROID_SDK_HOME instead of ANDROID_HOME. When I changed my env variable to match yours, I got the same error.

NeoSpark314 commented 4 years ago

@m4gr3d thanks for your help; now it builds!

m4gr3d commented 4 years ago

@m4gr3d thanks for your help; now it builds!

Great to hear!

It's worth adding that the migration to godot-cpp will increase build time (and binary size), but I think it's worth it as it drastically simplifies the process of adding new features/apis and our ability to leverage more of Godot apis.

m4gr3d commented 4 years ago

Build now works (thanks @m4gr3d). The binary file size increase feels quite large (release goes from 600kb .so to 40MB .so); I have not yet had the chance to try it out on the quest; will do a.s.a.p.

@NeoSpark314 is the final apk 40MB? When I generate the aar files, I'm getting less than 2MB

NeoSpark314 commented 4 years ago

No; only the .so files; maybe they are not yet stripped when generated with :generateSharedLibs; the .aar file has the same file size that you wrote (and the .so in there is 'only' 4mb)

m4gr3d commented 4 years ago

That's probably the case. I tested yesterday by building an apk with the debug aar file, and the apk binary size increased by ~1.5MB (so within the expected range). The aar build process most likely strips away a lot from the shared library.

@BastiaanOlij Since you have most experience with the godot-cpp build process, do you know if there are build parameters we can pass to reduce the size of the 'raw' shared libraries, or does their size not matter?

m4gr3d commented 4 years ago

@NeoSpark314 @BastiaanOlij I'm pausing work on this for now because of https://github.com/GodotNativeTools/godot-cpp/issues/394.