diff --git a/android/examples/vertexattributes/CMakeLists.txt b/android/examples/vertexattributes/CMakeLists.txt
new file mode 100644
index 00000000..8ddd2e72
--- /dev/null
+++ b/android/examples/vertexattributes/CMakeLists.txt
@@ -0,0 +1,35 @@
+cmake_minimum_required(VERSION 3.4.1 FATAL_ERROR)
+
+set(NAME vertexattributes)
+
+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}/imgui)
+include_directories(${EXTERNAL_DIR}/tinygltf)
+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/vertexattributes/build.gradle b/android/examples/vertexattributes/build.gradle
new file mode 100644
index 00000000..2ca7b87c
--- /dev/null
+++ b/android/examples/vertexattributes/build.gradle
@@ -0,0 +1,65 @@
+apply plugin: 'com.android.application'
+apply from: '../gradle/outputfilename.gradle'
+
+android {
+ compileSdkVersion 26
+ defaultConfig {
+ applicationId "de.saschawillems.vulkanVertexattributes"
+ 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/glsl/base'
+ into 'assets/shaders/glsl/base'
+ include '*.spv'
+ }
+
+ copy {
+ from '../../../data/shaders/glsl/vertexattributes'
+ into 'assets/shaders/glsl/vertexattributes'
+ include '*.*'
+ }
+
+ copy {
+ from '../../../data/models/sponza'
+ into 'assets/models/sponza'
+ include '*.*'
+ }
+
+}
+
+preBuild.dependsOn copyTask
\ No newline at end of file
diff --git a/android/examples/vertexattributes/src/main/AndroidManifest.xml b/android/examples/vertexattributes/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..7345a106
--- /dev/null
+++ b/android/examples/vertexattributes/src/main/AndroidManifest.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/examples/vertexattributes/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java b/android/examples/vertexattributes/src/main/java/de/saschawillems/vulkanSample/VulkanActivity.java
new file mode 100644
index 00000000..12e14fc6
--- /dev/null
+++ b/android/examples/vertexattributes/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/examples/vertexattributes/vertexattributes.cpp b/examples/vertexattributes/vertexattributes.cpp
index 1e61712c..b10f9991 100644
--- a/examples/vertexattributes/vertexattributes.cpp
+++ b/examples/vertexattributes/vertexattributes.cpp
@@ -54,34 +54,25 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt
const float* tangentsBuffer = nullptr;
size_t vertexCount = 0;
- // Get buffer data for vertex positions
- if (glTFPrimitive.attributes.find("POSITION") != glTFPrimitive.attributes.end()) {
- const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("POSITION")->second];
- const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView];
- positionBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset]));
- vertexCount = accessor.count;
- }
- // Get buffer data for vertex normals
- if (glTFPrimitive.attributes.find("NORMAL") != glTFPrimitive.attributes.end()) {
- const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("NORMAL")->second];
- const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView];
- normalsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset]));
- }
- // Get buffer data for vertex texture coordinates
- // glTF supports multiple sets, we only load the first one
- if (glTFPrimitive.attributes.find("TEXCOORD_0") != glTFPrimitive.attributes.end()) {
- const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("TEXCOORD_0")->second];
- const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView];
- texCoordsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset]));
- }
- // POI: This sample uses normal mapping, so we also need to load the tangents from the glTF file
- if (glTFPrimitive.attributes.find("TANGENT") != glTFPrimitive.attributes.end()) {
- const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find("TANGENT")->second];
- const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView];
- tangentsBuffer = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset]));
- }
+ // Anonymous functions to simplify buffer view access
+ auto getBuffer = [glTFPrimitive, input, &vertexCount](const std::string attributeName, const float* &bufferTarget) {
+ if (glTFPrimitive.attributes.find(attributeName) != glTFPrimitive.attributes.end()) {
+ const tinygltf::Accessor& accessor = input.accessors[glTFPrimitive.attributes.find(attributeName)->second];
+ const tinygltf::BufferView& view = input.bufferViews[accessor.bufferView];
+ bufferTarget = reinterpret_cast(&(input.buffers[view.buffer].data[accessor.byteOffset + view.byteOffset]));
+ if (attributeName == "POSITION") {
+ vertexCount = accessor.count;
+ }
+ }
+ };
- // Append data to model's vertex buffer
+ // Get buffer pointers to the vertex attributes used in this sample
+ getBuffer("POSITION", positionBuffer);
+ getBuffer("NORMAL", normalsBuffer);
+ getBuffer("TEXCOORD_0", texCoordsBuffer);
+ getBuffer("TANGENT", tangentsBuffer);
+
+ // Append attributes to the vertex buffers
for (size_t v = 0; v < vertexCount; v++) {
// Append interleaved attributes
@@ -97,7 +88,6 @@ void VulkanExample::loadSceneNode(const tinygltf::Node& inputNode, const tinyglt
vertexAttributeBuffers.normal.push_back(glm::normalize(glm::vec3(normalsBuffer ? glm::make_vec3(&normalsBuffer[v * 3]) : glm::vec3(0.0f))));
vertexAttributeBuffers.tangent.push_back(tangentsBuffer ? glm::make_vec4(&tangentsBuffer[v * 4]) : glm::vec4(0.0f));
vertexAttributeBuffers.uv.push_back(texCoordsBuffer ? glm::make_vec2(&texCoordsBuffer[v * 2]) : glm::vec3(0.0f));
-
}
// Indices