Added ETC2 and ASTC texture variants (Refs #174)

This commit is contained in:
saschawillems 2017-03-09 21:38:24 +01:00
parent 7403372ecd
commit a34bb203e0
14 changed files with 102 additions and 44 deletions

View file

@ -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,11 +790,13 @@ public:
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &scene->pipelines.blending));
// Wire frame rendering pipeline
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));
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:
wireframe = !wireframe;
reBuildCommandBuffers();
if (deviceFeatures.fillModeNonSolid) {
wireframe = !wireframe;
reBuildCommandBuffers();
}
break;
case KEY_P:
scene->renderSingleScenePart = !scene->renderSingleScenePart;
@ -866,19 +898,21 @@ 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);
textOverlay->addText("Press \"Button A\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
#else
textOverlay->addText("Press \"space\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
if ((scene) && (scene->renderSingleScenePart))
{
textOverlay->addText("Rendering mesh " + std::to_string(scene->scenePartIndex + 1) + " of " + std::to_string(static_cast<uint32_t>(scene->meshes.size())) + "(\"p\" to toggle)", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
}
else
{
textOverlay->addText("Rendering whole scene (\"p\" to toggle)", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
}
textOverlay->addText("Press \"space\" to toggle wireframe", 5.0f, 85.0f, VulkanTextOverlay::alignLeft);
if ((scene) && (scene->renderSingleScenePart))
{
textOverlay->addText("Rendering mesh " + std::to_string(scene->scenePartIndex + 1) + " of " + std::to_string(static_cast<uint32_t>(scene->meshes.size())) + "(\"p\" to toggle)", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
}
else
{
textOverlay->addText("Rendering whole scene (\"p\" to toggle)", 5.0f, 100.0f, VulkanTextOverlay::alignLeft);
}
#endif
}
}
};