From a7badba8b9b50c4d4f48ebe0ab08997e026a089c Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Tue, 27 Sep 2022 13:58:19 +0800 Subject: [PATCH] Copied over function from Texture Library to Texture loader to convert dds format to vk format --- .../src/Assets/Libraries/SHTextureLoader.cpp | 34 ++++++++++++++++++- .../src/Assets/Libraries/SHTextureLoader.h | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp index ea10aef5..29c1146a 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp @@ -26,6 +26,38 @@ namespace SHADE } } + vk::Format SHTextureLoader::ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear) + { + switch (format) + { + case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm: + case tinyddsloader::DDSFile::DXGIFormat::BC1_UNorm_SRGB: + return isLinear ? vk::Format::eBc1RgbaUnormBlock : vk::Format::eBc1RgbaSrgbBlock; + case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm: + case tinyddsloader::DDSFile::DXGIFormat::BC2_UNorm_SRGB: + return isLinear ? vk::Format::eBc2UnormBlock : vk::Format::eBc2SrgbBlock; + case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm: + case tinyddsloader::DDSFile::DXGIFormat::BC3_UNorm_SRGB: + return isLinear ? vk::Format::eBc3UnormBlock : vk::Format::eBc3SrgbBlock; + case tinyddsloader::DDSFile::DXGIFormat::BC5_UNorm: + case tinyddsloader::DDSFile::DXGIFormat::BC5_SNorm: + return isLinear ? vk::Format::eBc5UnormBlock : vk::Format::eBc5SnormBlock; + case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm: + case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_UNorm_SRGB: + return isLinear ? vk::Format::eR8G8B8A8Unorm : vk::Format::eR8G8B8A8Srgb; + case tinyddsloader::DDSFile::DXGIFormat::R8G8B8A8_SNorm: + return vk::Format::eR8G8B8A8Snorm; + case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm: + case tinyddsloader::DDSFile::DXGIFormat::B8G8R8A8_UNorm_SRGB: + return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8A8Srgb; + case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm: + case tinyddsloader::DDSFile::DXGIFormat::B8G8R8X8_UNorm_SRGB: + return isLinear ? vk::Format::eB8G8R8A8Unorm : vk::Format::eB8G8R8Srgb; + default: + throw std::runtime_error("Unsupported DDS format."); + } + } + void SHTextureLoader::LoadImageAsset(AssetPath path, SHTextureAsset& asset) { tinyddsloader::Result loadResult = tinyddsloader::Result::Success; @@ -53,7 +85,7 @@ namespace SHADE asset.numBytes = totalBytes; asset.width = file.GetWidth(); asset.height = file.GetHeight(); - asset.format = static_cast(file.GetFormat()); + asset.format = ddsLoaderToVkFormat(file.GetFormat(), true); asset.mipOffsets = std::move(mipOff); asset.pixelData = std::move(pixel); } diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.h b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.h index 393e1f02..281a9a19 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.h +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.h @@ -11,6 +11,8 @@ namespace SHADE { private: static std::string TinyDDSResultToString(tinyddsloader::Result value); + static vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear); + public: static void LoadImageAsset(AssetPath paths, SHTextureAsset& image); };