Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swappy and GameActivity #1172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ allprojects {
ext {
abiFilters = "arm64-v8a"
minSdkVersion = 21
targetSdkVersion = 26
compileSdkVersion = 26
targetSdkVersion = 35
compileSdkVersion = 35
shaderPath = '../../../shaders/'
assetPath = '../../../assets/'
}
3 changes: 3 additions & 0 deletions android/examples/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ include_directories(../../../external/gli)
include_directories(../../../external/imgui)
include_directories(${EXTERNAL_DIR}/tinygltf)
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
include_directories(${game-activity-include})
include_directories(${games-frame-pacing-include})

set(KTX_DIR ../../../external/ktx)
set(KTX_SOURCES
Expand All @@ -33,6 +35,7 @@ set_property(TARGET libktx PROPERTY FOLDER "external")

target_link_libraries(
libbase
games-frame-pacing::swappy_static
android
log
z
Expand Down
20 changes: 17 additions & 3 deletions android/examples/deferredmultisampling/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR)

set(NAME deferredmultisampling)
project(${NAME})
find_package(games-frame-pacing REQUIRED CONFIG)
find_package(game-activity REQUIRED CONFIG)

get_target_property(game-activity-include game-activity::game-activity INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(games-frame-pacing-include games-frame-pacing::swappy INTERFACE_INCLUDE_DIRECTORIES)

# Export GameActivity_onCreate(),
# Refer to: https://github.com/android-ndk/ndk/issues/381.
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u GameActivity_onCreate")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u Java_com_google_androidgamesdk_GameActivity_initializeNativeCode")

set(SRC_DIR ../../../examples/${NAME})
set(BASE_DIR ../../../base)
Expand All @@ -12,11 +25,11 @@ file(GLOB EXAMPLE_SRC "${SRC_DIR}/*.cpp")

add_library(native-lib SHARED ${EXAMPLE_SRC})

add_library(native-app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
# add_library(native-app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

add_subdirectory(../base ${CMAKE_SOURCE_DIR}/../base)

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

include_directories(${BASE_DIR})
include_directories(${EXTERNAL_DIR})
Expand All @@ -27,7 +40,8 @@ include_directories(${ANDROID_NDK}/sources/android/native_app_glue)

target_link_libraries(
native-lib
native-app-glue
games-frame-pacing::swappy_static
game-activity::game-activity_static
libbase
android
log
Expand Down
16 changes: 16 additions & 0 deletions android/examples/deferredmultisampling/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ android {
path "CMakeLists.txt"
}
}
buildFeatures {
prefab true
}
}

dependencies {
implementation "androidx.games:games-frame-pacing:2.1.2"

// To use the Games Activity library
implementation "androidx.lifecycle:lifecycle-viewmodel:2.2.0"
implementation "androidx.lifecycle:lifecycle-livedata:2.2.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"
implementation "androidx.core:core:1.5.0"
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
implementation 'androidx.fragment:fragment:1.2.5'
implementation "androidx.games:games-activity:2.0.2"
}

task copyTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name="de.saschawillems.vulkanSample.VulkanActivity"
android:screenOrientation="landscape"
android:theme="@style/AppTheme"
android:configChanges="orientation|keyboardHidden"
android:exported="true">
<meta-data android:name="android.app.lib_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import android.content.pm.ApplicationInfo;
import android.os.Bundle;

import com.google.androidgamesdk.GameActivity;

import java.util.concurrent.Semaphore;

public class VulkanActivity extends NativeActivity {
public class VulkanActivity extends GameActivity {

static {
// Load native library
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2021 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

https://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.
-->

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>

20 changes: 17 additions & 3 deletions android/examples/gltfscenerendering/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR)

set(NAME gltfscenerendering)
project(${NAME})
find_package(games-frame-pacing REQUIRED CONFIG)
find_package(game-activity REQUIRED CONFIG)

get_target_property(game-activity-include game-activity::game-activity INTERFACE_INCLUDE_DIRECTORIES)
get_target_property(games-frame-pacing-include games-frame-pacing::swappy INTERFACE_INCLUDE_DIRECTORIES)

# Export GameActivity_onCreate(),
# Refer to: https://github.com/android-ndk/ndk/issues/381.
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u GameActivity_onCreate")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u Java_com_google_androidgamesdk_GameActivity_initializeNativeCode")

set(SRC_DIR ../../../examples/${NAME})
set(BASE_DIR ../../../base)
Expand All @@ -12,11 +25,11 @@ file(GLOB EXAMPLE_SRC "${SRC_DIR}/*.cpp")

add_library(native-lib SHARED ${EXAMPLE_SRC})

add_library(native-app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
# add_library(native-app-glue STATIC ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

add_subdirectory(../base ${CMAKE_SOURCE_DIR}/../base)

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")

include_directories(${BASE_DIR})
include_directories(${EXTERNAL_DIR})
Expand All @@ -27,7 +40,8 @@ include_directories(${ANDROID_NDK}/sources/android/native_app_glue)

target_link_libraries(
native-lib
native-app-glue
games-frame-pacing::swappy_static
game-activity::game-activity_static
libbase
android
log
Expand Down
16 changes: 16 additions & 0 deletions android/examples/gltfscenerendering/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ android {
path "CMakeLists.txt"
}
}
buildFeatures {
prefab true
}
}

dependencies {
implementation "androidx.games:games-frame-pacing:2.1.2"

// To use the Games Activity library
implementation "androidx.lifecycle:lifecycle-viewmodel:2.2.0"
implementation "androidx.lifecycle:lifecycle-livedata:2.2.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"
implementation "androidx.core:core:1.5.0"
implementation "androidx.constraintlayout:constraintlayout:2.0.4"
implementation 'androidx.fragment:fragment:1.2.5'
implementation "androidx.games:games-activity:2.0.2"
}

task copyTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name="de.saschawillems.vulkanSample.VulkanActivity"
android:screenOrientation="landscape"
android:theme="@style/AppTheme"
android:configChanges="orientation|keyboardHidden"
android:exported="true">
<meta-data android:name="android.app.lib_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import android.content.pm.ApplicationInfo;
import android.os.Bundle;

import com.google.androidgamesdk.GameActivity;

import java.util.concurrent.Semaphore;

public class VulkanActivity extends NativeActivity {
public class VulkanActivity extends GameActivity {

static {
// Load native library
Expand Down
26 changes: 26 additions & 0 deletions android/examples/gltfscenerendering/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2021 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

https://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.
-->

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
</resources>

2 changes: 2 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonTransitiveRClass=false
org.gradle.jvmargs=-Xmx4096M
android.useAndroidX=true
android.prefabVersion=2.0.0
3 changes: 3 additions & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
file(GLOB BASE_SRC "*.cpp" "*.hpp" "*.h" "../external/imgui/*.cpp")
file(GLOB BASE_HEADERS "*.hpp" "*.h")

include_directories(${game-activity-include})
include_directories(${games-frame-pacing-include})

set(KTX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../external/ktx)
set(KTX_SOURCES
${KTX_DIR}/lib/texture.c
Expand Down
4 changes: 2 additions & 2 deletions base/Entrypoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ void android_main(android_app* state) \
vulkanExample = new VulkanExample(); \
state->userData = vulkanExample; \
state->onAppCmd = VulkanExample::handleAppCommand; \
state->onInputEvent = VulkanExample::handleAppInput; \
androidApp = state; \
vks::android::getDeviceConfig(); \
vulkanExample->initAndroidObjects(state); \
vulkanExample->renderLoop(); \
delete(vulkanExample); \
}
} \

#elif defined(_DIRECT2DISPLAY)
/*
Expand Down
28 changes: 28 additions & 0 deletions base/Log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2024 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 <android/log.h>

#define LOG_TAG "ADPF"

#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__);
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__);
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__);
#ifdef NDEBUG
#define ALOGV(...)
#else
#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__);
#endif
5 changes: 3 additions & 2 deletions base/VulkanAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <android/log.h>
#include <dlfcn.h>
#include <android/native_window_jni.h>
#include "Log.h"

android_app* androidApp;

Expand Down Expand Up @@ -352,10 +353,10 @@ namespace vks

jstring jmessage = jni->NewStringUTF(message);

jclass clazz = jni->GetObjectClass(androidApp->activity->clazz);
jclass clazz = jni->GetObjectClass(androidApp->activity->javaGameActivity);
// Signature has to match java implementation (arguments)
jmethodID methodID = jni->GetMethodID(clazz, "showAlert", "(Ljava/lang/String;)V");
jni->CallVoidMethod(androidApp->activity->clazz, methodID, jmessage);
jni->CallVoidMethod(androidApp->activity->javaGameActivity, methodID, jmessage);
jni->DeleteLocalRef(jmessage);

androidApp->activity->vm->DetachCurrentThread();
Expand Down
3 changes: 2 additions & 1 deletion base/VulkanAndroid.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#if defined(__ANDROID__)

#include <android/log.h>
#include <android_native_app_glue.h>
// #include <android_native_app_glue.h>
#include "game-activity/native_app_glue/android_native_app_glue.h"
#include <android/configuration.h>
#include <memory>
#include <string>
Expand Down
Loading