Added ETC2 and ASTC texture variants (Refs #174), only enable wireframe if non solid fillmode is supported by the device

This commit is contained in:
saschawillems 2017-03-08 21:31:29 +01:00
parent 83806a43c2
commit 4cc7b204df
7 changed files with 86 additions and 37 deletions

View file

@ -15,6 +15,7 @@
android:label="Mesh" android:label="Mesh"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask" android:launchMode="singleTask"
android:screenOrientation="landscape"
android:configChanges="orientation|screenSize|keyboardHidden"> android:configChanges="orientation|screenSize|keyboardHidden">
<meta-data android:name="android.app.lib_name" android:value="vulkanMesh" /> <meta-data android:name="android.app.lib_name" android:value="vulkanMesh" />
<intent-filter> <intent-filter>

View file

@ -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..
)

52
android/mesh/build.py Normal file
View file

@ -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!")

Binary file not shown.

Binary file not shown.

View file

@ -104,8 +104,6 @@ public:
cameraPos = { 0.1f, 1.1f, 0.0f }; cameraPos = { 0.1f, 1.1f, 0.0f };
enableTextOverlay = true; enableTextOverlay = true;
title = "Vulkan Example - Model rendering"; title = "Vulkan Example - Model rendering";
// Enable physical device features required for this example
enabledFeatures.fillModeNonSolid = VK_TRUE;
} }
~VulkanExample() ~VulkanExample()
@ -124,6 +122,14 @@ public:
uniformBuffers.scene.destroy(); uniformBuffers.scene.destroy();
} }
virtual void getEnabledFeatures()
{
// Fill mode non solid is required for wireframe display
if (deviceFeatures.fillModeNonSolid) {
enabledFeatures.fillModeNonSolid = VK_TRUE;
};
}
void reBuildCommandBuffers() void reBuildCommandBuffers()
{ {
if (!checkCommandBuffers()) if (!checkCommandBuffers())
@ -356,7 +362,18 @@ public:
void loadAssets() void loadAssets()
{ {
loadModel(getAssetPath() + "models/voyager/voyager.dae"); 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() void setupVertexDescriptions()
@ -568,10 +585,11 @@ public:
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid));
// Wire frame rendering pipeline // Wire frame rendering pipeline
rasterizationState.polygonMode = VK_POLYGON_MODE_LINE; if (deviceFeatures.fillModeNonSolid) {
rasterizationState.lineWidth = 1.0f; rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
rasterizationState.lineWidth = 1.0f;
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.wireframe)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.wireframe));
}
} }
// Prepare and initialize uniform buffer containing shader uniforms // Prepare and initialize uniform buffer containing shader uniforms
@ -649,19 +667,23 @@ public:
{ {
case KEY_W: case KEY_W:
case GAMEPAD_BUTTON_A: case GAMEPAD_BUTTON_A:
wireframe = !wireframe; if (deviceFeatures.fillModeNonSolid) {
reBuildCommandBuffers(); wireframe = !wireframe;
reBuildCommandBuffers();
}
break; break;
} }
} }
virtual void getOverlayText(VulkanTextOverlay *textOverlay) virtual void getOverlayText(VulkanTextOverlay *textOverlay)
{ {
if (deviceFeatures.fillModeNonSolid) {
#if defined(__ANDROID__) #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 #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 #endif
}
} }
}; };