diff --git a/android/build-all.py b/android/build-all.py
index 56b46dcc..cc331197 100644
--- a/android/build-all.py
+++ b/android/build-all.py
@@ -19,6 +19,7 @@ EXAMPLES = [
"gears",
"geometryshader",
"hdr",
+ "imgui",
"indirectdraw",
"instancing",
"mesh",
diff --git a/android/imgui/.gitignore b/android/imgui/.gitignore
new file mode 100644
index 00000000..7a5d249c
--- /dev/null
+++ b/android/imgui/.gitignore
@@ -0,0 +1,10 @@
+/assets/
+/res/
+/bin/
+/libs/
+/obj/
+/build.xml
+/local.properties
+/project.properties
+/proguard-project.txt
+*.apk
\ No newline at end of file
diff --git a/android/imgui/AndroidManifest.xml b/android/imgui/AndroidManifest.xml
new file mode 100644
index 00000000..dba0fa3b
--- /dev/null
+++ b/android/imgui/AndroidManifest.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/imgui/build.py b/android/imgui/build.py
new file mode 100644
index 00000000..b794dda0
--- /dev/null
+++ b/android/imgui/build.py
@@ -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!")
diff --git a/android/imgui/jni/Android.mk b/android/imgui/jni/Android.mk
new file mode 100644
index 00000000..7c2b6b9d
--- /dev/null
+++ b/android/imgui/jni/Android.mk
@@ -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)
diff --git a/android/imgui/jni/Application.mk b/android/imgui/jni/Application.mk
new file mode 100644
index 00000000..62020feb
--- /dev/null
+++ b/android/imgui/jni/Application.mk
@@ -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
diff --git a/android/uninstall-all.py b/android/uninstall-all.py
index a484b05d..17bbde1a 100644
--- a/android/uninstall-all.py
+++ b/android/uninstall-all.py
@@ -18,6 +18,7 @@ APP_NAMES = [
"de.saschawillems.vulkanGears",
"de.saschawillems.vulkanGeometryshader",
"de.saschawillems.vulkanHDR",
+ "de.saschawillems.vulkanImGui",
"de.saschawillems.vulkanIndirectdraw",
"de.saschawillems.vulkanInstancing",
"de.saschawillems.vulkanMesh",
diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h
index b575daf5..23b58cb6 100644
--- a/base/vulkanexamplebase.h
+++ b/base/vulkanexamplebase.h
@@ -88,8 +88,6 @@ protected:
/** @brief Logical device, application's view of the physical device (GPU) */
// todo: getter? should always point to VulkanDevice->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
VkQueue queue;
// Depth buffer format (selected during Vulkan initialization)
@@ -125,10 +123,6 @@ protected:
// Text overlay submission and execution
VkSemaphore textOverlayComplete;
} 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:
bool prepared = false;
uint32_t width = 1280;
@@ -136,6 +130,11 @@ public:
/** @brief Last frame time measured using a high performance timer (if available) */
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 */
struct Settings {
diff --git a/imgui/imgui_main.cpp b/imgui/main.cpp
similarity index 96%
rename from imgui/imgui_main.cpp
rename to imgui/main.cpp
index cd451b45..d38a658f 100644
--- a/imgui/imgui_main.cpp
+++ b/imgui/main.cpp
@@ -28,7 +28,7 @@
#include "VulkanBuffer.hpp"
#include "VulkanModel.hpp"
-#define ENABLE_VALIDATION false
+#define ENABLE_VALIDATION true
// Options and values to display/toggle from the UI
struct UISettings {
@@ -62,8 +62,8 @@ private:
VkDescriptorPool descriptorPool;
VkDescriptorSetLayout descriptorSetLayout;
VkDescriptorSet descriptorSet;
- std::vector shaderModules;
vks::VulkanDevice *device;
+ VulkanExampleBase *example;
public:
// UI params are set via push constants
struct PushConstBlock {
@@ -71,7 +71,10 @@ public:
glm::vec2 translate;
} pushConstBlock;
- ImGUI(vks::VulkanDevice *vulkanDevice) : device(vulkanDevice) {};
+ ImGUI(VulkanExampleBase *example) : example(example)
+ {
+ device = example->vulkanDevice;
+ };
~ImGUI()
{
@@ -87,7 +90,6 @@ public:
vkDestroyPipelineLayout(device->logicalDevice, pipelineLayout, nullptr);
vkDestroyDescriptorPool(device->logicalDevice, descriptorPool, nullptr);
vkDestroyDescriptorSetLayout(device->logicalDevice, descriptorSetLayout, nullptr);
- for (auto module : shaderModules) { vkDestroyShaderModule(device->logicalDevice, module, nullptr); }
}
// Initialize styles, keys, etc.
@@ -107,7 +109,7 @@ public:
}
// 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();
@@ -326,17 +328,8 @@ public:
pipelineCreateInfo.pVertexInputState = &vertexInputState;
- shaderStages[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_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 };
+ shaderStages[0] = example->loadShader(example->getAssetPath() + "shaders/imgui/ui.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
+ shaderStages[1] = example->loadShader(example->getAssetPath() + "shaders/imgui/ui.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device->logicalDevice, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipeline));
}
@@ -567,8 +560,6 @@ public:
// Set target frame buffer
renderPassBeginInfo.framebuffer = frameBuffers[i];
- VK_CHECK_RESULT(vkResetCommandBuffer(drawCmdBuffers[i], 0));
-
VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));
vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
@@ -760,9 +751,9 @@ public:
void prepareImGui()
{
- imGui = new ImGUI(vulkanDevice);
+ imGui = new ImGUI(this);
imGui->init((float)width, (float)height);
- imGui->initResources(renderPass, queue, getAssetPath());
+ imGui->initResources(renderPass, queue);
}
void prepare()