diff --git a/android/gltfio-android/CMakeLists.txt b/android/gltfio-android/CMakeLists.txt index aa0cd1f5b3..c7d0423de1 100644 --- a/android/gltfio-android/CMakeLists.txt +++ b/android/gltfio-android/CMakeLists.txt @@ -57,45 +57,54 @@ include_directories(${FILAMENT_DIR}/include .. ../../libs/utils/include) -set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--version-script=${CMAKE_SOURCE_DIR}/libgltfio-jni.map") - -add_library(gltfio-jni SHARED +add_library(gltfio-jni-obj OBJECT src/main/cpp/Animator.cpp src/main/cpp/AssetLoader.cpp src/main/cpp/FilamentAsset.cpp src/main/cpp/KtxLoader.cpp src/main/cpp/MaterialProvider.cpp - src/main/cpp/ResourceLoader.cpp + src/main/cpp/ResourceLoader.cpp) - ../common/CallbackUtils.cpp - ../common/NioUtils.cpp +if (NOT DISABLE_GLTFIO_JNI) - $ -) + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libgltfio-jni.map") -set_target_properties(gltfio-jni PROPERTIES LINK_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/libgltfio-jni.symbols) + add_library(gltfio-jni SHARED + $ -# The ordering in the following list is important because CMake does not have dependency information. -target_link_libraries(gltfio-jni - gltfio - filament - backend - filaflat - filabridge - geometry - image - ibl - utils - log - GLESv3 - EGL - android - jnigraphics - gltfio_resources - m -) + src/main/cpp/Gltfio.cpp + + ../common/CallbackUtils.cpp + ../common/NioUtils.cpp + + $ + ) + + set_target_properties(gltfio-jni PROPERTIES LINK_DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/libgltfio-jni.symbols) + + # The ordering in the following list is important because CMake does not have dependency information. + target_link_libraries(gltfio-jni + gltfio + filament + backend + filaflat + filabridge + geometry + image + ibl + utils + log + GLESv3 + EGL + android + jnigraphics + gltfio_resources + m + ) + + if (FILAMENT_SUPPORTS_VULKAN) + target_link_libraries(gltfio-jni bluevk smol-v) + endif() -if (FILAMENT_SUPPORTS_VULKAN) - target_link_libraries(gltfio-jni bluevk smol-v) endif() diff --git a/android/gltfio-android/src/main/cpp/AssetLoader.cpp b/android/gltfio-android/src/main/cpp/AssetLoader.cpp index 1425c55047..a258f99450 100644 --- a/android/gltfio-android/src/main/cpp/AssetLoader.cpp +++ b/android/gltfio-android/src/main/cpp/AssetLoader.cpp @@ -32,18 +32,6 @@ using namespace utils; extern void registerCallbackUtils(JNIEnv*); extern void registerNioUtils(JNIEnv*); -jint JNI_OnLoad(JavaVM* vm, void*) { - JNIEnv* env; - if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { - return -1; - } - - registerCallbackUtils(env); - registerNioUtils(env); - - return JNI_VERSION_1_6; -} - extern "C" JNIEXPORT jlong JNICALL Java_com_google_android_filament_gltfio_AssetLoader_nCreateAssetLoader(JNIEnv*, jclass, jlong nativeEngine, jlong nativeProvider, jlong nativeEntities) { diff --git a/android/gltfio-android/src/main/cpp/Gltfio.cpp b/android/gltfio-android/src/main/cpp/Gltfio.cpp new file mode 100644 index 0000000000..82185b81bd --- /dev/null +++ b/android/gltfio-android/src/main/cpp/Gltfio.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "common/NioUtils.h" + +extern void registerCallbackUtils(JNIEnv*); +extern void registerNioUtils(JNIEnv*); + +jint JNI_OnLoad(JavaVM* vm, void*) { + JNIEnv* env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { + return -1; + } + + registerCallbackUtils(env); + registerNioUtils(env); + + return JNI_VERSION_1_6; +} diff --git a/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/AssetLoader.java b/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/AssetLoader.java index 0025cc89ed..afb19813b0 100644 --- a/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/AssetLoader.java +++ b/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/AssetLoader.java @@ -37,7 +37,7 @@ import java.nio.Buffer; * * companion object { * init { - * AssetLoader.init() + * Gltfio.init() * } * } * @@ -77,13 +77,6 @@ import java.nio.Buffer; public class AssetLoader { private long mNativeObject; - /** - * Initializes the gltfio JNI layer. Must be called before using any gltfio functionality. - */ - public static void init() { - System.loadLibrary("gltfio-jni"); - } - /** * Constructs an AssetLoader that can be used to create and destroy instances of * {@link FilamentAsset}. diff --git a/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/Gltfio.java b/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/Gltfio.java new file mode 100644 index 0000000000..b332bee00b --- /dev/null +++ b/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/Gltfio.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.filament.gltfio; + +public class Gltfio { + /** + * Initializes the gltfio JNI layer. Must be called before using any gltfio functionality. + */ + public static void init() { + System.loadLibrary("gltfio-jni"); + } +} diff --git a/android/samples/sample-gltf-bloom/src/main/java/com/google/android/filament/bloom/MainActivity.kt b/android/samples/sample-gltf-bloom/src/main/java/com/google/android/filament/bloom/MainActivity.kt index c15d1a9286..c8a7442faf 100644 --- a/android/samples/sample-gltf-bloom/src/main/java/com/google/android/filament/bloom/MainActivity.kt +++ b/android/samples/sample-gltf-bloom/src/main/java/com/google/android/filament/bloom/MainActivity.kt @@ -31,6 +31,7 @@ import com.google.android.filament.gltfio.* import java.nio.ByteBuffer import java.nio.ByteOrder import java.nio.channels.Channels + import kotlin.math.* data class Framebuffer( @@ -43,10 +44,9 @@ data class Framebuffer( class MainActivity : Activity() { - // We are using the gltfio library, so init the AssetLoader rather than Filament. companion object { init { - AssetLoader.init() + Gltfio.init() } }