Added ETC2 and ASTC texture variants (Refs #174)
This commit is contained in:
parent
7403372ecd
commit
a34bb203e0
14 changed files with 102 additions and 44 deletions
|
|
@ -1,23 +0,0 @@
|
|||
cd jni
|
||||
call ndk-build
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
cd..
|
||||
|
||||
mkdir "assets\shaders\base"
|
||||
xcopy "..\..\data\shaders\base\*.spv" "assets\shaders\base" /Y
|
||||
|
||||
|
||||
mkdir "assets\shaders\scenerendering"
|
||||
xcopy "..\..\data\shaders\scenerendering\*.*" "assets\shaders\scenerendering" /Y
|
||||
|
||||
mkdir "assets\models\sibenik"
|
||||
xcopy "..\..\data\models\sibenik\*.*" "assets\models\sibenik" /Y
|
||||
|
||||
mkdir "res\drawable"
|
||||
xcopy "..\..\android\images\icon.png" "res\drawable" /Y
|
||||
|
||||
call ant debug -Dout.final.file=vulkanScenerendering.apk
|
||||
) ELSE (
|
||||
echo error : ndk-build failed with errors!
|
||||
cd..
|
||||
)
|
||||
47
android/scenerendering/build.py
Normal file
47
android/scenerendering/build.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import glob
|
||||
|
||||
APK_NAME = "scenerendering"
|
||||
SHADER_DIR = "pbribl"
|
||||
|
||||
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 model
|
||||
if not os.path.exists("./assets/models/sibenik/"):
|
||||
os.makedirs("./assets/models/sibenik/")
|
||||
for file in glob.glob("../../data/models/sibenik/*.*"):
|
||||
shutil.copy(file, "./assets/models/sibenik")
|
||||
|
||||
# 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/models/sibenik/KAMEN-stup_astc_8x8_unorm.ktx
Normal file
BIN
data/models/sibenik/KAMEN-stup_astc_8x8_unorm.ktx
Normal file
Binary file not shown.
BIN
data/models/sibenik/KAMEN-stup_etc2_unorm.ktx
Normal file
BIN
data/models/sibenik/KAMEN-stup_etc2_unorm.ktx
Normal file
Binary file not shown.
Binary file not shown.
BIN
data/models/sibenik/dummy_rgba_unorm.ktx
Normal file
BIN
data/models/sibenik/dummy_rgba_unorm.ktx
Normal file
Binary file not shown.
BIN
data/models/sibenik/kamen_astc_8x8_unorm.ktx
Normal file
BIN
data/models/sibenik/kamen_astc_8x8_unorm.ktx
Normal file
Binary file not shown.
BIN
data/models/sibenik/kamen_etc2_unorm.ktx
Normal file
BIN
data/models/sibenik/kamen_etc2_unorm.ktx
Normal file
Binary file not shown.
BIN
data/models/sibenik/mramor6x6_astc_8x8_unorm.ktx
Normal file
BIN
data/models/sibenik/mramor6x6_astc_8x8_unorm.ktx
Normal file
Binary file not shown.
BIN
data/models/sibenik/mramor6x6_etc2_unorm.ktx
Normal file
BIN
data/models/sibenik/mramor6x6_etc2_unorm.ktx
Normal file
Binary file not shown.
|
|
@ -148,6 +148,25 @@ private:
|
|||
std::cout << "Material \"" << materials[i].name << "\"" << std::endl;
|
||||
|
||||
// Textures
|
||||
std::string texFormatSuffix;
|
||||
VkFormat texFormat;
|
||||
// Get supported compressed texture format
|
||||
if (vulkanDevice->features.textureCompressionBC) {
|
||||
texFormatSuffix = "_bc3_unorm";
|
||||
texFormat = VK_FORMAT_BC3_UNORM_BLOCK;
|
||||
}
|
||||
//else if (vulkanDevice->features.textureCompressionASTC_LDR) {
|
||||
// texFormatSuffix = "_astc_8x8_unorm";
|
||||
// texFormat = VK_FORMAT_ASTC_8x8_UNORM_BLOCK;
|
||||
//}
|
||||
else if (vulkanDevice->features.textureCompressionETC2) {
|
||||
texFormatSuffix = "_etc2_unorm";
|
||||
texFormat = VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
|
||||
}
|
||||
else {
|
||||
vks::tools::exitFatal("Device does not support any compressed texture format!", "Error");
|
||||
}
|
||||
|
||||
aiString texturefile;
|
||||
// Diffuse
|
||||
aScene->mMaterials[i]->GetTexture(aiTextureType_DIFFUSE, 0, &texturefile);
|
||||
|
|
@ -156,13 +175,14 @@ private:
|
|||
std::cout << " Diffuse: \"" << texturefile.C_Str() << "\"" << std::endl;
|
||||
std::string fileName = std::string(texturefile.C_Str());
|
||||
std::replace(fileName.begin(), fileName.end(), '\\', '/');
|
||||
materials[i].diffuse.loadFromFile(assetPath + fileName, VK_FORMAT_BC3_UNORM_BLOCK, vulkanDevice, queue);
|
||||
fileName.insert(fileName.find(".ktx"), texFormatSuffix);
|
||||
materials[i].diffuse.loadFromFile(assetPath + fileName, texFormat, vulkanDevice, queue);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << " Material has no diffuse, using dummy texture!" << std::endl;
|
||||
// todo : separate pipeline and layout
|
||||
materials[i].diffuse.loadFromFile(assetPath + "dummy.ktx", VK_FORMAT_BC2_UNORM_BLOCK, vulkanDevice, queue);
|
||||
materials[i].diffuse.loadFromFile(assetPath + "dummy_rgba_unorm.ktx", VK_FORMAT_R8G8B8A8_UNORM, vulkanDevice, queue);
|
||||
}
|
||||
|
||||
// For scenes with multiple textures per material we would need to check for additional texture types, e.g.:
|
||||
|
|
@ -563,6 +583,7 @@ public:
|
|||
|
||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||
{
|
||||
title = "Vulkan Example - Scene rendering";
|
||||
rotationSpeed = 0.5f;
|
||||
enableTextOverlay = true;
|
||||
camera.type = Camera::CameraType::firstperson;
|
||||
|
|
@ -570,8 +591,6 @@ public:
|
|||
camera.position = { 15.0f, -13.5f, 0.0f };
|
||||
camera.setRotation(glm::vec3(5.0f, 90.0f, 0.0f));
|
||||
camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f);
|
||||
title = "Vulkan Example - Scene rendering";
|
||||
enabledFeatures.fillModeNonSolid = VK_TRUE;
|
||||
}
|
||||
|
||||
~VulkanExample()
|
||||
|
|
@ -579,6 +598,15 @@ public:
|
|||
delete(scene);
|
||||
}
|
||||
|
||||
// Enable physical device features required for this example
|
||||
virtual void getEnabledFeatures()
|
||||
{
|
||||
// Fill mode non solid is required for wireframe display
|
||||
if (deviceFeatures.fillModeNonSolid) {
|
||||
enabledFeatures.fillModeNonSolid = VK_TRUE;
|
||||
};
|
||||
}
|
||||
|
||||
void reBuildCommandBuffers()
|
||||
{
|
||||
if (!checkCommandBuffers())
|
||||
|
|
@ -762,12 +790,14 @@ public:
|
|||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &scene->pipelines.blending));
|
||||
|
||||
// Wire frame rendering pipeline
|
||||
if (deviceFeatures.fillModeNonSolid) {
|
||||
rasterizationState.cullMode = VK_CULL_MODE_BACK_BIT;
|
||||
blendAttachmentState.blendEnable = VK_FALSE;
|
||||
rasterizationState.polygonMode = VK_POLYGON_MODE_LINE;
|
||||
rasterizationState.lineWidth = 1.0f;
|
||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &scene->pipelines.wireframe));
|
||||
}
|
||||
}
|
||||
|
||||
void updateUniformBuffers()
|
||||
{
|
||||
|
|
@ -839,8 +869,10 @@ public:
|
|||
{
|
||||
case KEY_SPACE:
|
||||
case GAMEPAD_BUTTON_A:
|
||||
if (deviceFeatures.fillModeNonSolid) {
|
||||
wireframe = !wireframe;
|
||||
reBuildCommandBuffers();
|
||||
}
|
||||
break;
|
||||
case KEY_P:
|
||||
scene->renderSingleScenePart = !scene->renderSingleScenePart;
|
||||
|
|
@ -866,6 +898,7 @@ public:
|
|||
|
||||
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);
|
||||
#else
|
||||
|
|
@ -880,6 +913,7 @@ public:
|
|||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
VULKAN_EXAMPLE_MAIN()
|
||||
Loading…
Add table
Add a link
Reference in a new issue