Added ETC2 and ASTC texture variants (Refs #174)

This commit is contained in:
saschawillems 2017-03-08 20:42:23 +01:00
parent 7d7ef490c2
commit ab95c2f29a
6 changed files with 70 additions and 29 deletions

View file

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

48
android/texture/build.py Normal file
View file

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

Binary file not shown.

Binary file not shown.

View file

@ -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();