From 48a1e40000e926ddad2a0b1e042fd60d79c08c14 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Fri, 29 Mar 2019 14:11:00 +0100 Subject: [PATCH] Added negative viewport height example Android build files --- .../negativeviewportheight/CMakeLists.txt | 36 ++++++++++ .../negativeviewportheight/build.gradle | 72 +++++++++++++++++++ .../src/main/AndroidManifest.xml | 24 +++++++ .../vulkanSample/VulkanActivity.java | 58 +++++++++++++++ android/settings.gradle | 1 + 5 files changed, 191 insertions(+) create mode 100644 android/examples/negativeviewportheight/CMakeLists.txt create mode 100644 android/examples/negativeviewportheight/build.gradle create mode 100644 android/examples/negativeviewportheight/src/main/AndroidManifest.xml create mode 100644 android/examples/negativeviewportheight/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java diff --git a/android/examples/negativeviewportheight/CMakeLists.txt b/android/examples/negativeviewportheight/CMakeLists.txt new file mode 100644 index 00000000..c3644237 --- /dev/null +++ b/android/examples/negativeviewportheight/CMakeLists.txt @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR) + +set(NAME negativeviewportheight) + +set(SRC_DIR ../../../examples/${NAME}) +set(BASE_DIR ../../../base) +set(EXTERNAL_DIR ../../../external) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -DVK_USE_PLATFORM_ANDROID_KHR -DVK_NO_PROTOTYPES") + +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_subdirectory(../base ${CMAKE_SOURCE_DIR}/../base) + +set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate") + +include_directories(${BASE_DIR}) +include_directories(${EXTERNAL_DIR}) +include_directories(${EXTERNAL_DIR}/glm) +include_directories(${EXTERNAL_DIR}/gli) +include_directories(${EXTERNAL_DIR}/imgui) +include_directories(${EXTERNAL_DIR}/assimp) +include_directories(${ANDROID_NDK}/sources/android/native_app_glue) + +target_link_libraries( + native-lib + native-app-glue + libbase + android + log + z +) diff --git a/android/examples/negativeviewportheight/build.gradle b/android/examples/negativeviewportheight/build.gradle new file mode 100644 index 00000000..ccd1485b --- /dev/null +++ b/android/examples/negativeviewportheight/build.gradle @@ -0,0 +1,72 @@ +apply plugin: 'com.android.application' +apply from: '../gradle/outputfilename.gradle' + +android { + compileSdkVersion 26 + defaultConfig { + applicationId "de.saschawillems.vulkanNegativeviewportheight" + minSdkVersion 19 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + ndk { + abiFilters "armeabi-v7a" + } + externalNativeBuild { + cmake { + cppFlags "-std=c++14" + arguments "-DANDROID_STL=c++_shared", '-DANDROID_TOOLCHAIN=clang' + } + } + } + sourceSets { + main.assets.srcDirs = ['assets'] + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + path "CMakeLists.txt" + } + } +} + +task copyTask << { + copy { + from '../../common/res/drawable' + into "src/main/res/drawable" + include 'icon.png' + } + + copy { + from '../../../data/shaders/base' + into "assets/shaders/base" + include '*.spv' + } + + copy { + from '../../../data/shaders/negativeviewportheight' + into 'assets/shaders/negativeviewportheight' + include '*.*' + } + + copy { + from '../../../data/textures' + into 'assets/textures' + include 'texture_orientation_ccw_rgba.ktx' + } + + copy { + from '../../../data/textures' + into 'assets/textures' + include 'texture_orientation_cw_rgba.ktx' + } + + +} + +preBuild.dependsOn copyTask \ No newline at end of file diff --git a/android/examples/negativeviewportheight/src/main/AndroidManifest.xml b/android/examples/negativeviewportheight/src/main/AndroidManifest.xml new file mode 100644 index 00000000..ee8f2623 --- /dev/null +++ b/android/examples/negativeviewportheight/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + diff --git a/android/examples/negativeviewportheight/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java b/android/examples/negativeviewportheight/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java new file mode 100644 index 00000000..12e14fc6 --- /dev/null +++ b/android/examples/negativeviewportheight/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2018 by Sascha Willems - www.saschawillems.de + * + * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + */ +package de.saschawillems.vulkanSample; + +import android.app.AlertDialog; +import android.app.NativeActivity; +import android.content.DialogInterface; +import android.content.pm.ApplicationInfo; +import android.os.Bundle; + +import java.util.concurrent.Semaphore; + +public class VulkanActivity extends NativeActivity { + + static { + // Load native library + System.loadLibrary("native-lib"); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + // Use a semaphore to create a modal dialog + + private final Semaphore semaphore = new Semaphore(0, true); + + public void showAlert(final String message) + { + final VulkanActivity activity = this; + + ApplicationInfo applicationInfo = activity.getApplicationInfo(); + final String applicationName = applicationInfo.nonLocalizedLabel.toString(); + + this.runOnUiThread(new Runnable() { + public void run() { + AlertDialog.Builder builder = new AlertDialog.Builder(activity, android.R.style.Theme_Material_Dialog_Alert); + builder.setTitle(applicationName); + builder.setMessage(message); + builder.setPositiveButton("Close", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + semaphore.release(); + } + }); + builder.setCancelable(false); + AlertDialog dialog = builder.create(); + dialog.show(); + } + }); + try { + semaphore.acquire(); + } + catch (InterruptedException e) { } + } +} diff --git a/android/settings.gradle b/android/settings.gradle index e467c0d3..eeac1468 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -26,6 +26,7 @@ include 'examples/:mesh' include 'examples/:multisampling' include 'examples/:multithreading' include 'examples/:multiview' +include 'examples/:negativeviewportheight' include 'examples/:occlusionquery' include 'examples/:offscreen' include 'examples/:parallaxmapping'