Added ETC2 and ASTC texture variants (Refs #174)
This commit is contained in:
parent
c688f7394c
commit
a5a2211489
8 changed files with 96 additions and 49 deletions
|
|
@ -15,6 +15,7 @@
|
|||
android:label="Texture Array"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
android:launchMode="singleTask"
|
||||
android:screenOrientation="landscape"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden">
|
||||
<meta-data android:name="android.app.lib_name" android:value="vulkanTexturearray" />
|
||||
<intent-filter>
|
||||
|
|
|
|||
|
|
@ -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\texturearray"
|
||||
xcopy "..\..\data\shaders\texturearray\*.spv" "assets\shaders\texturearray" /Y
|
||||
|
||||
mkdir "assets\textures"
|
||||
xcopy "..\..\data\textures\texturearray_bc3.ktx" "assets\textures" /Y
|
||||
|
||||
mkdir "res\drawable"
|
||||
xcopy "..\..\android\images\icon.png" "res\drawable" /Y
|
||||
|
||||
call ant debug -Dout.final.file=vulkanTexturearray.apk
|
||||
) ELSE (
|
||||
echo error : ndk-build failed with errors!
|
||||
cd..
|
||||
)
|
||||
48
android/texturearray/build.py
Normal file
48
android/texturearray/build.py
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import glob
|
||||
|
||||
APK_NAME = "vulkanTexturearray"
|
||||
SHADER_DIR = "texturearray"
|
||||
ASSETS_TEXTURES = ["texturearray_bc3_unorm.ktx", "texturearray_astc_8x8_unorm.ktx", "texturearray_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!")
|
||||
BIN
data/textures/texturearray_astc_8x8_unorm.ktx
Normal file
BIN
data/textures/texturearray_astc_8x8_unorm.ktx
Normal file
Binary file not shown.
BIN
data/textures/texturearray_etc2_unorm.ktx
Normal file
BIN
data/textures/texturearray_etc2_unorm.ktx
Normal file
Binary file not shown.
|
|
@ -497,6 +497,31 @@ public:
|
|||
vkFreeMemory(device, texture.deviceMemory, nullptr);
|
||||
}
|
||||
|
||||
void loadTextures()
|
||||
{
|
||||
// Vulkan core supports three different compressed texture formats
|
||||
// As the support differs between implemementations we need to check device features and select a proper format and file
|
||||
std::string filename;
|
||||
VkFormat format;
|
||||
if (deviceFeatures.textureCompressionBC) {
|
||||
filename = "metalplate01_bc2_unorm.ktx";
|
||||
format = VK_FORMAT_BC3_UNORM_BLOCK;
|
||||
}
|
||||
else if (deviceFeatures.textureCompressionASTC_LDR) {
|
||||
filename = "metalplate01_astc_8x8_unorm.ktx";
|
||||
format = VK_FORMAT_ASTC_8x8_UNORM_BLOCK;
|
||||
}
|
||||
else if (deviceFeatures.textureCompressionETC2) {
|
||||
filename = "metalplate01_etc2_unorm.ktx";
|
||||
format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
|
||||
}
|
||||
else {
|
||||
vks::tools::exitFatal("Device does not support any compressed texture format!", "Error");
|
||||
}
|
||||
|
||||
loadTexture(getAssetPath() + "textures/" + filename, format, false);
|
||||
}
|
||||
|
||||
void buildCommandBuffers()
|
||||
{
|
||||
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
||||
|
|
@ -591,26 +616,6 @@ 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
|
||||
|
|
@ -848,7 +853,7 @@ public:
|
|||
void prepare()
|
||||
{
|
||||
VulkanExampleBase::prepare();
|
||||
loadAssets();
|
||||
loadTextures();
|
||||
generateQuad();
|
||||
setupVertexDescriptions();
|
||||
prepareUniformBuffers();
|
||||
|
|
|
|||
|
|
@ -313,9 +313,26 @@ public:
|
|||
|
||||
void loadTextures()
|
||||
{
|
||||
loadTextureArray(
|
||||
getAssetPath() + "textures/texturearray_bc3.ktx",
|
||||
VK_FORMAT_BC3_UNORM_BLOCK);
|
||||
// Vulkan core supports three different compressed texture formats
|
||||
// As the support differs between implemementations we need to check device features and select a proper format and file
|
||||
std::string filename;
|
||||
VkFormat format;
|
||||
if (deviceFeatures.textureCompressionBC) {
|
||||
filename = "texturearray_bc3_unorm.ktx";
|
||||
format = VK_FORMAT_BC3_UNORM_BLOCK;
|
||||
}
|
||||
else if (deviceFeatures.textureCompressionASTC_LDR) {
|
||||
filename = "texturearray_astc_8x8_unorm.ktx";
|
||||
format = VK_FORMAT_ASTC_8x8_UNORM_BLOCK;
|
||||
}
|
||||
else if (deviceFeatures.textureCompressionETC2) {
|
||||
filename = "texturearray_etc2_unorm.ktx";
|
||||
format = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
|
||||
}
|
||||
else {
|
||||
vks::tools::exitFatal("Device does not support any compressed texture format!", "Error");
|
||||
}
|
||||
loadTextureArray(getAssetPath() + "textures/" + filename, format);
|
||||
}
|
||||
|
||||
void buildCommandBuffers()
|
||||
|
|
@ -664,8 +681,8 @@ public:
|
|||
void prepare()
|
||||
{
|
||||
VulkanExampleBase::prepare();
|
||||
setupVertexDescriptions();
|
||||
loadTextures();
|
||||
setupVertexDescriptions();
|
||||
generateQuad();
|
||||
prepareUniformBuffers();
|
||||
setupDescriptorSetLayout();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue