Added ETC2 and ASTC texture variants (Refs #174), check device features
This commit is contained in:
parent
f1bf03a440
commit
622a503f90
4 changed files with 106 additions and 43 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
android:label="Displacement mapping"
|
android:label="Displacement mapping"
|
||||||
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="vulkanDisplacement" />
|
<meta-data android:name="android.app.lib_name" android:value="vulkanDisplacement" />
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
||||||
|
|
@ -1,27 +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\displacement"
|
|
||||||
xcopy "..\..\data\shaders\displacement\*.spv" "assets\shaders\displacement" /Y
|
|
||||||
|
|
||||||
mkdir "assets\textures"
|
|
||||||
xcopy "..\..\data\textures\pattern_36_bc3.ktx" "assets\textures" /Y
|
|
||||||
|
|
||||||
mkdir "assets\models"
|
|
||||||
xcopy "..\..\data\models\plane.obj" "assets\models" /Y
|
|
||||||
|
|
||||||
mkdir "res\drawable"
|
|
||||||
xcopy "..\..\android\images\icon.png" "res\drawable" /Y
|
|
||||||
|
|
||||||
call ant debug -Dout.final.file=vulkanDisplacement.apk
|
|
||||||
) ELSE (
|
|
||||||
echo error : ndk-build failed with errors!
|
|
||||||
cd..
|
|
||||||
)
|
|
||||||
53
android/displacement/build.py
Normal file
53
android/displacement/build.py
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import glob
|
||||||
|
|
||||||
|
APK_NAME = "vulkanDisplacement"
|
||||||
|
SHADER_DIR = "displacement"
|
||||||
|
ASSETS_MODELS = ["plane.obj"]
|
||||||
|
ASSETS_TEXTURES = ["stonefloor03_color_bc3_unorm.ktx", "stonefloor03_color_astc_8x8_unorm.ktx", "stonefloor03_color_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 and models
|
||||||
|
if not os.path.exists("./assets/textures"):
|
||||||
|
os.makedirs("./assets/textures")
|
||||||
|
for file in ASSETS_TEXTURES:
|
||||||
|
shutil.copy("../../data/textures/%s" % file, "./assets/textures")
|
||||||
|
if not os.path.exists("./assets/models"):
|
||||||
|
os.makedirs("./assets/models")
|
||||||
|
for file in ASSETS_MODELS:
|
||||||
|
shutil.copy("../../data/models/%s" % file, "./assets/models")
|
||||||
|
|
||||||
|
# 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!")
|
||||||
|
|
@ -70,9 +70,9 @@ public:
|
||||||
float tessStrength = 0.1f;
|
float tessStrength = 0.1f;
|
||||||
} uboTessEval;
|
} uboTessEval;
|
||||||
|
|
||||||
struct {
|
struct Pipelines {
|
||||||
VkPipeline solid;
|
VkPipeline solid;
|
||||||
VkPipeline wireframe;
|
VkPipeline wireframe = VK_NULL_HANDLE;
|
||||||
} pipelines;
|
} pipelines;
|
||||||
|
|
||||||
VkPipelineLayout pipelineLayout;
|
VkPipelineLayout pipelineLayout;
|
||||||
|
|
@ -85,11 +85,6 @@ public:
|
||||||
rotation = glm::vec3(-20.0f, 45.0f, 0.0f);
|
rotation = glm::vec3(-20.0f, 45.0f, 0.0f);
|
||||||
enableTextOverlay = true;
|
enableTextOverlay = true;
|
||||||
title = "Vulkan Example - Tessellation shader displacement mapping";
|
title = "Vulkan Example - Tessellation shader displacement mapping";
|
||||||
// Enable physical device features required for this example
|
|
||||||
// Tell the driver that we are going to use geometry shaders
|
|
||||||
enabledFeatures.tessellationShader = VK_TRUE;
|
|
||||||
// Example also uses a wireframe pipeline, enable non-solid fill modes
|
|
||||||
enabledFeatures.fillModeNonSolid = VK_TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~VulkanExample()
|
~VulkanExample()
|
||||||
|
|
@ -97,7 +92,9 @@ public:
|
||||||
// Clean up used Vulkan resources
|
// Clean up used Vulkan resources
|
||||||
// Note : Inherited destructor cleans up resources stored in base class
|
// Note : Inherited destructor cleans up resources stored in base class
|
||||||
vkDestroyPipeline(device, pipelines.solid, nullptr);
|
vkDestroyPipeline(device, pipelines.solid, nullptr);
|
||||||
vkDestroyPipeline(device, pipelines.wireframe, nullptr);
|
if (pipelines.wireframe != VK_NULL_HANDLE) {
|
||||||
|
vkDestroyPipeline(device, pipelines.wireframe, nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
||||||
|
|
@ -108,10 +105,41 @@ public:
|
||||||
textures.colorHeightMap.destroy();
|
textures.colorHeightMap.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable physical device features required for this example
|
||||||
|
virtual void getEnabledFeatures()
|
||||||
|
{
|
||||||
|
// Geometry shader support is required for this example
|
||||||
|
if (deviceFeatures.fillModeNonSolid) {
|
||||||
|
enabledFeatures.geometryShader = VK_TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vks::tools::exitFatal("Selected GPU does not support tessellation shaders!", "Feature not supported");
|
||||||
|
}
|
||||||
|
// Fill mode non solid is required for wireframe display
|
||||||
|
if (deviceFeatures.fillModeNonSolid) {
|
||||||
|
enabledFeatures.fillModeNonSolid = VK_TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
splitScreen = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void loadAssets()
|
void loadAssets()
|
||||||
{
|
{
|
||||||
models.object.loadFromFile(getAssetPath() + "models/plane.obj", vertexLayout, 0.25f, vulkanDevice, queue);
|
models.object.loadFromFile(getAssetPath() + "models/plane.obj", vertexLayout, 0.25f, vulkanDevice, queue);
|
||||||
textures.colorHeightMap.loadFromFile(getAssetPath() + "textures/pattern_36_bc3.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
|
// Textures
|
||||||
|
if (vulkanDevice->features.textureCompressionBC) {
|
||||||
|
textures.colorHeightMap.loadFromFile(getAssetPath() + "textures/stonefloor03_color_bc3_unorm.ktx", VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
|
||||||
|
}
|
||||||
|
else if (vulkanDevice->features.textureCompressionASTC_LDR) {
|
||||||
|
textures.colorHeightMap.loadFromFile(getAssetPath() + "textures/stonefloor03_color_astc_8x8_unorm.ktx", VK_FORMAT_ASTC_8x8_UNORM_BLOCK, vulkanDevice, queue);
|
||||||
|
}
|
||||||
|
else if (vulkanDevice->features.textureCompressionETC2) {
|
||||||
|
textures.colorHeightMap.loadFromFile(getAssetPath() + "textures/stonefloor03_color_etc2_unorm.ktx", VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, vulkanDevice, queue);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
vks::tools::exitFatal("Device does not support any compressed texture format!", "Error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reBuildCommandBuffers()
|
void reBuildCommandBuffers()
|
||||||
|
|
@ -405,10 +433,12 @@ public:
|
||||||
// Solid pipeline
|
// Solid pipeline
|
||||||
rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT;
|
rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT;
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid));
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.solid));
|
||||||
// Wireframe pipeline
|
if (deviceFeatures.fillModeNonSolid) {
|
||||||
rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
|
// Wireframe pipeline
|
||||||
rasterizationState.cullMode = VK_CULL_MODE_NONE;
|
rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.wireframe));
|
rasterizationState.cullMode = VK_CULL_MODE_NONE;
|
||||||
|
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
|
||||||
|
|
@ -562,7 +592,9 @@ public:
|
||||||
break;
|
break;
|
||||||
case KEY_S:
|
case KEY_S:
|
||||||
case GAMEPAD_BUTTON_X:
|
case GAMEPAD_BUTTON_X:
|
||||||
toggleSplitScreen();
|
if (deviceFeatures.fillModeNonSolid) {
|
||||||
|
toggleSplitScreen();
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -574,11 +606,15 @@ public:
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
textOverlay->addText("Tessellation height: " + ss.str() + " (Buttons L1/R1)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
|
textOverlay->addText("Tessellation height: " + ss.str() + " (Buttons L1/R1)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
|
||||||
textOverlay->addText("\"Button A\" to toggle displacement", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
|
textOverlay->addText("\"Button A\" to toggle displacement", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
|
||||||
textOverlay->addText("\"Button X\" to toggle splitscreen", 5.0f, 115.0f, VulkanTextOverlay::alignLeft);
|
if (deviceFeatures.fillModeNonSolid) {
|
||||||
|
textOverlay->addText("\"Button X\" to toggle splitscreen", 5.0f, 115.0f, VulkanTextOverlay::alignLeft);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
textOverlay->addText("Tessellation height: " + ss.str() + " (numpad +/-)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
|
textOverlay->addText("Tessellation height: " + ss.str() + " (numpad +/-)", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
|
||||||
textOverlay->addText("\"d\" to toggle displacement", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
|
textOverlay->addText("\"d\" to toggle displacement", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
|
||||||
textOverlay->addText("\"s\" to toggle splitscreen", 5.0f, 115.0f, VulkanTextOverlay::alignLeft);
|
if (deviceFeatures.fillModeNonSolid) {
|
||||||
|
textOverlay->addText("\"s\" to toggle splitscreen", 5.0f, 115.0f, VulkanTextOverlay::alignLeft);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue