diff --git a/android/texture/build.bat b/android/texture/build.bat deleted file mode 100644 index 30f7c2b6..00000000 --- a/android/texture/build.bat +++ /dev/null @@ -1,24 +0,0 @@ -cd jni -call ndk-build -if %ERRORLEVEL% EQU 0 ( - echo ndk-build has failed, build cancelled - cd.. - - mkdir "assets\shaders\base" - xcopy "..\..\data\shaders\base\*.spv" "assets\shaders\base" /Y - - - mkdir "assets\shaders\texture" - xcopy "..\..\data\shaders\texture\*.spv" "assets\shaders\texture" /Y - - mkdir "assets\textures" - xcopy "..\..\data\textures\pattern_02_bc2.ktx" "assets\textures" /Y - - mkdir "res\drawable" - xcopy "..\..\android\images\icon.png" "res\drawable" /Y - - call ant debug -Dout.final.file=vulkanTexture.apk -) ELSE ( - echo error : ndk-build failed with errors! - cd.. -) diff --git a/android/texture/build.py b/android/texture/build.py new file mode 100644 index 00000000..9c4b3b41 --- /dev/null +++ b/android/texture/build.py @@ -0,0 +1,48 @@ +import os +import shutil +import subprocess +import sys +import glob + +APK_NAME = "vulkanTexture" +SHADER_DIR = "texture" +ASSETS_TEXTURES = ["metalplate01_bc2_unorm.ktx", "metalplate01_astc_8x8_unorm.ktx", "metalplate01_etc2_unorm.ktx"] + +if subprocess.call("ndk-build", shell=True) == 0: + print("Build successful") + + # Assets + if not os.path.exists("./assets"): + os.makedirs("./assets") + + # Shaders + # Base + if not os.path.exists("./assets/shaders/base"): + os.makedirs("./assets/shaders/base") + for file in glob.glob("../../data/shaders/base/*.spv"): + shutil.copy(file, "./assets/shaders/base") + # Sample + if not os.path.exists("./assets/shaders/%s" % SHADER_DIR): + os.makedirs("./assets/shaders/%s" % SHADER_DIR) + for file in glob.glob("../../data/shaders/%s/*.spv" %SHADER_DIR): + shutil.copy(file, "./assets/shaders/%s" % SHADER_DIR) + # Textures + if not os.path.exists("./assets/textures"): + os.makedirs("./assets/textures") + for file in ASSETS_TEXTURES: + shutil.copy("../../data/textures/%s" % file, "./assets/textures") + + # Icon + if not os.path.exists("./res/drawable"): + os.makedirs("./res/drawable") + shutil.copy("../../android/images/icon.png", "./res/drawable") + + if subprocess.call("ant debug -Dout.final.file=%s.apk" % APK_NAME, shell=True) == 0: + if len(sys.argv) > 1: + if sys.argv[1] == "-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/data/textures/metalplate01_astc_8x8_unorm.ktx b/data/textures/metalplate01_astc_8x8_unorm.ktx new file mode 100644 index 00000000..3f13057a Binary files /dev/null and b/data/textures/metalplate01_astc_8x8_unorm.ktx differ diff --git a/data/textures/pattern_02_bc2.ktx b/data/textures/metalplate01_bc2_unorm.ktx similarity index 100% rename from data/textures/pattern_02_bc2.ktx rename to data/textures/metalplate01_bc2_unorm.ktx diff --git a/data/textures/metalplate01_etc2_unorm.ktx b/data/textures/metalplate01_etc2_unorm.ktx new file mode 100644 index 00000000..1e6ff675 Binary files /dev/null and b/data/textures/metalplate01_etc2_unorm.ktx differ diff --git a/texture/texture.cpp b/texture/texture.cpp index ebc5e5b9..66432335 100644 --- a/texture/texture.cpp +++ b/texture/texture.cpp @@ -79,7 +79,7 @@ public: { zoom = -2.5f; rotation = { 0.0f, 15.0f, 0.0f }; - title = "Vulkan Example - Texturing"; + title = "Vulkan Example - Texture loading"; enableTextOverlay = true; } @@ -591,6 +591,26 @@ public: indices.data())); } + // Texture loading is done here + void loadAssets() + { + // Vulkan core supports three different compressed texture formats + // As the support differs between implemementations we need to check and load the proper texture + // Block compression (BC) is common on desktops, ETC and ASTC on mobile + if (deviceFeatures.textureCompressionBC) { + loadTexture(getAssetPath() + "textures/metalplate01_bc2_unorm.ktx", VK_FORMAT_BC2_UNORM_BLOCK, false); + } + else if (deviceFeatures.textureCompressionASTC_LDR) { + loadTexture(getAssetPath() + "textures/metalplate01_astc_8x8_unorm.ktx", VK_FORMAT_ASTC_8x8_UNORM_BLOCK, false); + } + else if (deviceFeatures.textureCompressionETC2) { + loadTexture(getAssetPath() + "textures/metalplate01_etc2_unorm.ktx", VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, false); + } + else { + vks::tools::exitFatal("Device does not support any compressed texture format!", "Error"); + } + } + void setupVertexDescriptions() { // Binding description @@ -828,13 +848,10 @@ public: void prepare() { VulkanExampleBase::prepare(); + loadAssets(); generateQuad(); setupVertexDescriptions(); prepareUniformBuffers(); - loadTexture( - getAssetPath() + "textures/pattern_02_bc2.ktx", - VK_FORMAT_BC2_UNORM_BLOCK, - false); setupDescriptorSetLayout(); preparePipelines(); setupDescriptorPool();