Added imgui example Android build

This commit is contained in:
saschawillems 2017-03-31 09:52:26 +02:00
parent ccfc1f1124
commit c849d18db3
9 changed files with 169 additions and 26 deletions

View file

@ -19,6 +19,7 @@ EXAMPLES = [
"gears", "gears",
"geometryshader", "geometryshader",
"hdr", "hdr",
"imgui",
"indirectdraw", "indirectdraw",
"instancing", "instancing",
"mesh", "mesh",

10
android/imgui/.gitignore vendored Normal file
View file

@ -0,0 +1,10 @@
/assets/
/res/
/bin/
/libs/
/obj/
/build.xml
/local.properties
/project.properties
/proguard-project.txt
*.apk

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.saschawillems.vulkanImGui"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="19" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<uses-feature android:name="android.hardware.gamepad" android:required="false"/>
<uses-feature android:name="android.software.leanback" android:required="false"/>
<application android:label="vulkanImGui" android:icon="@drawable/icon" android:hasCode="false">
<activity android:name="android.app.NativeActivity"
android:label="ImGui"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="main" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

56
android/imgui/build.py Normal file
View file

@ -0,0 +1,56 @@
import os
import shutil
import subprocess
import sys
import glob
APK_NAME = "vulkanImGui"
SHADER_DIR = "imgui"
ASSETS_MODELS = ["vulkanscenemodels.dae", "vulkanscenebackground.dae", "vulkanscenelogos.dae"]
if subprocess.call("ndk-build", shell=True) == 0:
print("Build successful")
# Validation
VALIDATION = False
for arg in sys.argv[1:]:
print(arg)
if arg == "-validation":
VALIDATION = True
break
if VALIDATION:
print("Validation enabled, copying validation layers...")
os.makedirs("./libs/armeabi-v7a", exist_ok=True)
for file in glob.glob("../layers/armeabi-v7a/*.so"):
print(file + "\n")
shutil.copy(file, "./libs/armeabi-v7a")
# Assets
os.makedirs("./assets/shaders/base", exist_ok=True)
os.makedirs("./assets/shaders/%s" % SHADER_DIR, exist_ok=True)
os.makedirs("./assets/models", exist_ok=True)
os.makedirs("./res/drawable", exist_ok=True)
# Shaders
# Base
for file in glob.glob("../../data/shaders/base/*.spv"):
shutil.copy(file, "./assets/shaders/base")
# Sample
for file in glob.glob("../../data/shaders/%s/*.spv" %SHADER_DIR):
shutil.copy(file, "./assets/shaders/%s" % SHADER_DIR)
# Models
for file in ASSETS_MODELS:
shutil.copy("../../data/models/%s" % file, "./assets/models")
# Icon
shutil.copy("../../android/images/icon.png", "./res/drawable")
if subprocess.call("ant debug -Dout.final.file=%s.apk" % APK_NAME, shell=True) == 0:
for arg in sys.argv[1:]:
if arg == "-deploy":
if subprocess.call("adb install -r %s.apk" % APK_NAME, shell=True) != 0:
print("Could not deploy to device!")
else:
print("Error during build process!")
else:
print("Error building project!")

View file

@ -0,0 +1,52 @@
LOCAL_PATH := $(call my-dir)/../../imgui
# assimp
include $(CLEAR_VARS)
LOCAL_MODULE := assimp
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../libs/assimp/$(TARGET_ARCH_ABI)/libassimp.a
include $(PREBUILT_STATIC_LIBRARY)
# vulkan example
DATADIR := $(LOCAL_PATH)/../../data
include $(CLEAR_VARS)
LOCAL_MODULE := main
PROJECT_FILES := $(wildcard $(LOCAL_PATH)/../../imgui/*.cpp)
PROJECT_FILES += $(wildcard $(LOCAL_PATH)/../../base/*.cpp)
PROJECT_FILES += $(LOCAL_PATH)/../../external/imgui/imgui.cpp \
$(LOCAL_PATH)/../../external/imgui/imgui_demo.cpp \
$(LOCAL_PATH)/../../external/imgui/imgui_draw.cpp
LOCAL_CPPFLAGS := -std=c++11
LOCAL_CPPFLAGS += -D__STDC_LIMIT_MACROS
LOCAL_CPPFLAGS += -DVK_NO_PROTOTYPES
LOCAL_CPPFLAGS += -DVK_USE_PLATFORM_ANDROID_KHR
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../external/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../external/glm
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../external/gli
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../external/assimp
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../base/
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../external/imgui/
LOCAL_SRC_FILES := $(PROJECT_FILES)
LOCAL_LDLIBS := -landroid -llog -lz
LOCAL_DISABLE_FORMAT_STRING_CHECKS := true
LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true
LOCAL_STATIC_LIBRARIES += android_native_app_glue
LOCAL_STATIC_LIBRARIES += cpufeatures
LOCAL_STATIC_LIBRARIES += libassimp
include $(BUILD_SHARED_LIBRARY)
$(call import-module, android/native_app_glue)
$(call import-module, android/cpufeatures)

View file

@ -0,0 +1,5 @@
APP_PLATFORM := android-19
APP_ABI := armeabi-v7a
APP_STL := c++_static
APP_CPPFLAGS := -std=c++11
NDK_TOOLCHAIN_VERSION := clang

View file

@ -18,6 +18,7 @@ APP_NAMES = [
"de.saschawillems.vulkanGears", "de.saschawillems.vulkanGears",
"de.saschawillems.vulkanGeometryshader", "de.saschawillems.vulkanGeometryshader",
"de.saschawillems.vulkanHDR", "de.saschawillems.vulkanHDR",
"de.saschawillems.vulkanImGui",
"de.saschawillems.vulkanIndirectdraw", "de.saschawillems.vulkanIndirectdraw",
"de.saschawillems.vulkanInstancing", "de.saschawillems.vulkanInstancing",
"de.saschawillems.vulkanMesh", "de.saschawillems.vulkanMesh",

View file

@ -88,8 +88,6 @@ protected:
/** @brief Logical device, application's view of the physical device (GPU) */ /** @brief Logical device, application's view of the physical device (GPU) */
// todo: getter? should always point to VulkanDevice->device // todo: getter? should always point to VulkanDevice->device
VkDevice device; VkDevice device;
/** @brief Encapsulated physical and logical vulkan device */
vks::VulkanDevice *vulkanDevice;
// Handle to the device graphics queue that command buffers are submitted to // Handle to the device graphics queue that command buffers are submitted to
VkQueue queue; VkQueue queue;
// Depth buffer format (selected during Vulkan initialization) // Depth buffer format (selected during Vulkan initialization)
@ -125,10 +123,6 @@ protected:
// Text overlay submission and execution // Text overlay submission and execution
VkSemaphore textOverlayComplete; VkSemaphore textOverlayComplete;
} semaphores; } semaphores;
// Simple texture loader
//vks::tools::VulkanTextureLoader *textureLoader = nullptr;
// Returns the base asset path (for shaders, models, textures) depending on the os
const std::string getAssetPath();
public: public:
bool prepared = false; bool prepared = false;
uint32_t width = 1280; uint32_t width = 1280;
@ -136,6 +130,11 @@ public:
/** @brief Last frame time measured using a high performance timer (if available) */ /** @brief Last frame time measured using a high performance timer (if available) */
float frameTimer = 1.0f; float frameTimer = 1.0f;
/** @brief Returns os specific base asset path (for shaders, models, textures) */
const std::string getAssetPath();
/** @brief Encapsulated physical and logical vulkan device */
vks::VulkanDevice *vulkanDevice;
/** @brief Example settings that can be changed e.g. by command line arguments */ /** @brief Example settings that can be changed e.g. by command line arguments */
struct Settings { struct Settings {

View file

@ -28,7 +28,7 @@
#include "VulkanBuffer.hpp" #include "VulkanBuffer.hpp"
#include "VulkanModel.hpp" #include "VulkanModel.hpp"
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION true
// Options and values to display/toggle from the UI // Options and values to display/toggle from the UI
struct UISettings { struct UISettings {
@ -62,8 +62,8 @@ private:
VkDescriptorPool descriptorPool; VkDescriptorPool descriptorPool;
VkDescriptorSetLayout descriptorSetLayout; VkDescriptorSetLayout descriptorSetLayout;
VkDescriptorSet descriptorSet; VkDescriptorSet descriptorSet;
std::vector<VkShaderModule> shaderModules;
vks::VulkanDevice *device; vks::VulkanDevice *device;
VulkanExampleBase *example;
public: public:
// UI params are set via push constants // UI params are set via push constants
struct PushConstBlock { struct PushConstBlock {
@ -71,7 +71,10 @@ public:
glm::vec2 translate; glm::vec2 translate;
} pushConstBlock; } pushConstBlock;
ImGUI(vks::VulkanDevice *vulkanDevice) : device(vulkanDevice) {}; ImGUI(VulkanExampleBase *example) : example(example)
{
device = example->vulkanDevice;
};
~ImGUI() ~ImGUI()
{ {
@ -87,7 +90,6 @@ public:
vkDestroyPipelineLayout(device->logicalDevice, pipelineLayout, nullptr); vkDestroyPipelineLayout(device->logicalDevice, pipelineLayout, nullptr);
vkDestroyDescriptorPool(device->logicalDevice, descriptorPool, nullptr); vkDestroyDescriptorPool(device->logicalDevice, descriptorPool, nullptr);
vkDestroyDescriptorSetLayout(device->logicalDevice, descriptorSetLayout, nullptr); vkDestroyDescriptorSetLayout(device->logicalDevice, descriptorSetLayout, nullptr);
for (auto module : shaderModules) { vkDestroyShaderModule(device->logicalDevice, module, nullptr); }
} }
// Initialize styles, keys, etc. // Initialize styles, keys, etc.
@ -107,7 +109,7 @@ public:
} }
// Initialize all Vulkan resources used by the ui // Initialize all Vulkan resources used by the ui
void initResources(VkRenderPass renderPass, VkQueue copyQueue, std::string assetPath) void initResources(VkRenderPass renderPass, VkQueue copyQueue)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
@ -326,17 +328,8 @@ public:
pipelineCreateInfo.pVertexInputState = &vertexInputState; pipelineCreateInfo.pVertexInputState = &vertexInputState;
shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; shaderStages[0] = example->loadShader(example->getAssetPath() + "shaders/imgui/ui.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT; shaderStages[1] = example->loadShader(example->getAssetPath() + "shaders/imgui/ui.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
shaderStages[0].pName = "main";
shaderStages[0].module = vks::tools::loadShader((assetPath + "shaders/imgui/ui.vert.spv").c_str(), device->logicalDevice, VK_SHADER_STAGE_VERTEX_BIT);
shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
shaderStages[1].pName = "main";
shaderStages[1].module = vks::tools::loadShader((assetPath + "shaders/imgui/ui.frag.spv").c_str(), device->logicalDevice, VK_SHADER_STAGE_FRAGMENT_BIT);
shaderModules = { shaderStages[0].module, shaderStages[1].module };
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device->logicalDevice, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipeline)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device->logicalDevice, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipeline));
} }
@ -567,8 +560,6 @@ public:
// Set target frame buffer // Set target frame buffer
renderPassBeginInfo.framebuffer = frameBuffers[i]; renderPassBeginInfo.framebuffer = frameBuffers[i];
VK_CHECK_RESULT(vkResetCommandBuffer(drawCmdBuffers[i], 0));
VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo)); VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));
vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
@ -760,9 +751,9 @@ public:
void prepareImGui() void prepareImGui()
{ {
imGui = new ImGUI(vulkanDevice); imGui = new ImGUI(this);
imGui->init((float)width, (float)height); imGui->init((float)width, (float)height);
imGui->initResources(renderPass, queue, getAssetPath()); imGui->initResources(renderPass, queue);
} }
void prepare() void prepare()