Skip to content

Commit

Permalink
Working on android
Browse files Browse the repository at this point in the history
  • Loading branch information
jherico committed Apr 14, 2018
1 parent 37a3f34 commit 2ec1e85
Show file tree
Hide file tree
Showing 141 changed files with 2,924 additions and 2,336 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ bin_debug
# Android Studio
.idea
*.iml
*.hprof
gradle
gradlew
gradlew.bat
*.hprof
local.properties
android/gradle
android/app/src/main/jniLibs
android/src/main/jniLibs
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_policy(VERSION 3.6)
include("cmake/defaults.cmake")
set(NAME VulkanCppExamples)


project(${NAME})

if (NOT "${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
Expand All @@ -13,7 +14,6 @@ include("cmake/compiler.cmake")

find_package(Threads REQUIRED)


# This define is specific to Vulkan has a depth range of [0, 1], unlike OpenGL which has a [-1, 1]
add_definitions(-DGLM_FORCE_DEPTH_ZERO_TO_ONE)

Expand All @@ -29,8 +29,8 @@ if (NOT ANDROID)
set_target_properties(SetupDebug PROPERTIES FOLDER "CMakeTargets")
endif()


if (ANDROID)
add_definitions(-DVULKAN_HPP_NO_SMART_HANDLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
set(APP_GLUE_DIR ${ANDROID_NDK}/sources/android/native_app_glue)
include_directories(${APP_GLUE_DIR})
Expand Down
50 changes: 0 additions & 50 deletions android/app/build.gradle

This file was deleted.

21 changes: 0 additions & 21 deletions android/app/proguard-rules.pro

This file was deleted.

58 changes: 43 additions & 15 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.android.application'

buildscript {

repositories {
google()
jcenter()
android {
compileSdkVersion 26
defaultConfig {
applicationId "org.saintandreas.vulkanexamples"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
ndk { abiFilter "arm64-v8a" }
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-26',
'-DANDROID_TOOLCHAIN=clang',
'-DANDROID_STL=c++_shared',
'-DVULKAN_SDK=' + vulkan_sdk
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'

sourceSets {
main {
jniLibs.srcDirs += "${android.ndkDirectory}/sources/third_party/vulkan/src/build-android/jniLibs"
assets.srcDirs += "$projectDir.absolutePath/../data"
}
}

externalNativeBuild {
cmake {
path '../CMakeLists.txt'
}
}
}

allprojects {
repositories {
google()
jcenter()
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
}
1 change: 0 additions & 1 deletion android/settings.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@
android:name=".examples.ComputeShader">
<meta-data android:name="android.app.lib_name" android:value="computeshader" />
</activity>
<!--
<activity android:configChanges="orientation|screenSize|keyboardHidden" android:launchMode="singleTask" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:name=".examples.Context">
<meta-data android:name="android.app.lib_name" android:value="context" />
</activity>
-->
<activity android:configChanges="orientation|screenSize|keyboardHidden" android:launchMode="singleTask" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:name=".examples.Deferred">
<meta-data android:name="android.app.lib_name" android:value="deferred" />
Expand Down
File renamed without changes.
File renamed without changes.
153 changes: 153 additions & 0 deletions base/AndroidNativeApp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
//
// Created by Brad on 12/21/2017.
//

#pragma once
#ifndef VULKAN_ANDROIDNATIVEAPP_H
#define VULKAN_ANDROIDNATIVEAPP_H

#include "android_native_app_glue.h"
#include <type_traits>

namespace android {
class NativeApp {
public:
virtual ~NativeApp() {}

protected:
static int32_t inputCallback(struct android_app* app, AInputEvent* event) {
NativeApp* appClass = (NativeApp*)app->userData;
return appClass->onInput(event);
}

static void appCmdCallback(struct android_app* app, int32_t cmd) {
NativeApp* appClass = (NativeApp*)app->userData;
appClass->onCmd(cmd);
}

virtual int32_t onInput(AInputEvent* event) { return 0; }

virtual void onCmd(int32_t cmd) {
switch (cmd) {
case APP_CMD_CONFIG_CHANGED:
onConfigChanged();
break;
case APP_CMD_CONTENT_RECT_CHANGED:
onContentRectChanged();
break;
case APP_CMD_DESTROY:
onDestroy();
break;
case APP_CMD_GAINED_FOCUS:
onGainedFocus();
break;
case APP_CMD_INIT_WINDOW:
onInitWindow();
break;
case APP_CMD_INPUT_CHANGED:
onInputCHanged();
break;
case APP_CMD_LOST_FOCUS:
onLostFocus();
break;
case APP_CMD_LOW_MEMORY:
onLowMemory();
break;
case APP_CMD_PAUSE:
onPause();
break;
case APP_CMD_RESUME:
onResume();
break;
case APP_CMD_SAVE_STATE:
onSaveState();
break;
case APP_CMD_START:
onStart();
break;
case APP_CMD_STOP:
onStop();
break;
case APP_CMD_TERM_WINDOW:
onTermWindow();
break;
case APP_CMD_WINDOW_REDRAW_NEEDED:
onWindowRedrawNeeded();
break;
case APP_CMD_WINDOW_RESIZED:
onWindowResized();
break;
}
}

virtual void onConfigChanged() {}

virtual void onContentRectChanged() {}

virtual void onDestroy() {}

virtual void onGainedFocus() {}

virtual void onInitWindow() {}

virtual void onInputCHanged() {}

virtual void onLostFocus() {}

virtual void onLowMemory() {}

virtual void onPause() {}

virtual void onResume() {}

virtual void onSaveState() {}

virtual void onStart() {}

virtual void onStop() {}

virtual void onTermWindow() {}

virtual void onWindowRedrawNeeded() {}

virtual void onWindowResized() {}

protected:
NativeApp(android_app* app)
: app(app) {
app->userData = this;
app->onAppCmd = appCmdCallback;
app->onInputEvent = inputCallback;
}

android_app* const app;
};

template <typename T>
class NativeStatefulApp : public NativeApp {
using Parent = NativeApp;
// FIXME
// static_assert(std::is_trivally_copyable<T>::value);

public:
NativeStatefulApp(android_app* app)
: Parent(app) {
if (app->savedState != nullptr) {
// We are starting with a previous saved state; restore from it.
state = *reinterpret_cast<const T*>(app->savedState);
}
}

protected:
void onSaveState() override {
size_t size = sizeof(T);
app->savedStateSize = size;
app->savedState = malloc(size);
*((T*)app->savedState) = state;
}

T state;
};
} // namespace android

#endif //VULKAN_ANDROIDNATIVEAPP_H
1 change: 0 additions & 1 deletion base/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
set(TARGET_NAME base)


set(SHADER_DIR "${PROJECT_SOURCE_DIR}/data/shaders")
file(GLOB_RECURSE SHADERS
${SHADER_DIR}/*.vert
Expand Down
8 changes: 3 additions & 5 deletions base/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ class Vectors {
}
#endif

#define RUN_EXAMPLE(ExampleType) \
ENTRY_POINT_START \
ExampleType* example = new ExampleType(); \
example->run(); \
delete (example); \
#define RUN_EXAMPLE(ExampleType) \
ENTRY_POINT_START \
ExampleType().run(); \
ENTRY_POINT_END

#define VULKAN_EXAMPLE_MAIN() RUN_EXAMPLE(VulkanExample)
3 changes: 3 additions & 0 deletions base/gl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "gl.hpp"

#if !defined(__ANDROID__)
#include <mutex>

typedef PROC(APIENTRYP PFNWGLGETPROCADDRESS)(LPCSTR);
Expand Down Expand Up @@ -95,3 +97,4 @@ void gl::setupDebugLogging() {
glDebugMessageCallback(debugMessageCallback, NULL);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
}
#endif
4 changes: 4 additions & 0 deletions base/gl.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "common.hpp"

#if !defined(__ANDROID__)
#include <glad/glad.h>

namespace gl {
Expand All @@ -8,3 +10,5 @@ GLuint buildProgram(const std::string& vertexShaderSource, const std::string& fr
void report();
void setupDebugLogging();
} // namespace gl

#endif
Loading

0 comments on commit 2ec1e85

Please sign in to comment.