diff --git a/android/mesh/AndroidManifest.xml b/android/mesh/AndroidManifest.xml index 3d75e417..a6d918f0 100644 --- a/android/mesh/AndroidManifest.xml +++ b/android/mesh/AndroidManifest.xml @@ -15,6 +15,7 @@ android:label="Mesh" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:launchMode="singleTask" + android:screenOrientation="landscape" android:configChanges="orientation|screenSize|keyboardHidden"> diff --git a/android/mesh/build.bat b/android/mesh/build.bat deleted file mode 100644 index 6c137b6e..00000000 --- a/android/mesh/build.bat +++ /dev/null @@ -1,26 +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\mesh" - xcopy "..\..\data\shaders\mesh\mesh.vert.spv" "assets\shaders\mesh" /Y - xcopy "..\..\data\shaders\mesh\mesh.frag.spv" "assets\shaders\mesh" /Y - - mkdir "assets\models\voyager" - xcopy "..\..\data\models\voyager\voyager.ktx" "assets\models\voyager" /Y - xcopy "..\..\data\models\voyager\voyager.dae" "assets\models\voyager" /Y - - mkdir "res\drawable" - xcopy "..\..\android\images\icon.png" "res\drawable" /Y - - call ant debug -Dout.final.file=vulkanMesh.apk -) ELSE ( - echo error : ndk-build failed with errors! - cd.. -) diff --git a/android/mesh/build.py b/android/mesh/build.py new file mode 100644 index 00000000..38b43e45 --- /dev/null +++ b/android/mesh/build.py @@ -0,0 +1,52 @@ +import os +import shutil +import subprocess +import sys +import glob + +APK_NAME = "vulkanMesh" +SHADER_DIR = "mesh" +ASSETS_MODELS = ["voyager.dae"] +ASSETS_TEXTURES = ["voyager_astc_8x8_unorm.ktx", "voyager_bc3_unorm.ktx", "voyager_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/models/voyager"): + os.makedirs("./assets/models/voyager") + for file in ASSETS_TEXTURES: + shutil.copy("../../data/models/voyager/%s" % file, "./assets/models/voyager") + # Models + for file in ASSETS_MODELS: + shutil.copy("../../data/models/voyager/%s" % file, "./assets/models/voyager") + + # 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/models/voyager/voyager_astc_8x8_unorm.ktx b/data/models/voyager/voyager_astc_8x8_unorm.ktx new file mode 100644 index 00000000..8ed9be08 Binary files /dev/null and b/data/models/voyager/voyager_astc_8x8_unorm.ktx differ diff --git a/data/models/voyager/voyager.ktx b/data/models/voyager/voyager_bc3_unorm.ktx similarity index 100% rename from data/models/voyager/voyager.ktx rename to data/models/voyager/voyager_bc3_unorm.ktx diff --git a/data/models/voyager/voyager_etc2_unorm.ktx b/data/models/voyager/voyager_etc2_unorm.ktx new file mode 100644 index 00000000..c88480e6 Binary files /dev/null and b/data/models/voyager/voyager_etc2_unorm.ktx differ diff --git a/mesh/mesh.cpp b/mesh/mesh.cpp index f7171386..f6cb0365 100644 --- a/mesh/mesh.cpp +++ b/mesh/mesh.cpp @@ -104,8 +104,6 @@ public: cameraPos = { 0.1f, 1.1f, 0.0f }; enableTextOverlay = true; title = "Vulkan Example - Model rendering"; - // Enable physical device features required for this example - enabledFeatures.fillModeNonSolid = VK_TRUE; } ~VulkanExample() @@ -124,6 +122,14 @@ public: uniformBuffers.scene.destroy(); } + virtual void getEnabledFeatures() + { + // Fill mode non solid is required for wireframe display + if (deviceFeatures.fillModeNonSolid) { + enabledFeatures.fillModeNonSolid = VK_TRUE; + }; + } + void reBuildCommandBuffers() { if (!checkCommandBuffers()) @@ -356,7 +362,18 @@ public: void loadAssets() { loadModel(getAssetPath() + "models/voyager/voyager.dae"); - textures.colorMap.loadFromFile(getAssetPath() + "models/voyager/voyager.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + if (deviceFeatures.textureCompressionBC) { + textures.colorMap.loadFromFile(getAssetPath() + "models/voyager/voyager_bc3_unorm.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue); + } + else if (deviceFeatures.textureCompressionASTC_LDR) { + textures.colorMap.loadFromFile(getAssetPath() + "models/voyager/voyager_astc_8x8_unorm.ktx", VK_FORMAT_ASTC_8x8_UNORM_BLOCK, vulkanDevice, queue); + } + else if (deviceFeatures.textureCompressionETC2) { + textures.colorMap.loadFromFile(getAssetPath() + "models/voyager/voyager_etc2_unorm.ktx", VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, vulkanDevice, queue); + } + else { + vks::tools::exitFatal("Device does not support any compressed texture format!", "Error"); + } } void setupVertexDescriptions() @@ -568,10 +585,11 @@ public: VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid)); // Wire frame rendering pipeline - rasterizationState.polygonMode = VK_POLYGON_MODE_LINE; - rasterizationState.lineWidth = 1.0f; - - VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.wireframe)); + if (deviceFeatures.fillModeNonSolid) { + rasterizationState.polygonMode = VK_POLYGON_MODE_LINE; + rasterizationState.lineWidth = 1.0f; + VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.wireframe)); + } } // Prepare and initialize uniform buffer containing shader uniforms @@ -649,19 +667,23 @@ public: { case KEY_W: case GAMEPAD_BUTTON_A: - wireframe = !wireframe; - reBuildCommandBuffers(); + if (deviceFeatures.fillModeNonSolid) { + wireframe = !wireframe; + reBuildCommandBuffers(); + } break; } } virtual void getOverlayText(VulkanTextOverlay *textOverlay) { + if (deviceFeatures.fillModeNonSolid) { #if defined(__ANDROID__) - textOverlay->addText("Press \"Button A\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); + textOverlay->addText("Press \"Button A\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); #else - textOverlay->addText("Press \"w\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); + textOverlay->addText("Press \"w\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft); #endif + } } };