Copied over function from Texture Library to Texture loader to convert dds format to vk format
This commit is contained in:
parent
7487602151
commit
a7badba8b9
|
@ -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)
|
void SHTextureLoader::LoadImageAsset(AssetPath path, SHTextureAsset& asset)
|
||||||
{
|
{
|
||||||
tinyddsloader::Result loadResult = tinyddsloader::Result::Success;
|
tinyddsloader::Result loadResult = tinyddsloader::Result::Success;
|
||||||
|
@ -53,7 +85,7 @@ namespace SHADE
|
||||||
asset.numBytes = totalBytes;
|
asset.numBytes = totalBytes;
|
||||||
asset.width = file.GetWidth();
|
asset.width = file.GetWidth();
|
||||||
asset.height = file.GetHeight();
|
asset.height = file.GetHeight();
|
||||||
asset.format = static_cast<vk::Format>(file.GetFormat());
|
asset.format = ddsLoaderToVkFormat(file.GetFormat(), true);
|
||||||
asset.mipOffsets = std::move(mipOff);
|
asset.mipOffsets = std::move(mipOff);
|
||||||
asset.pixelData = std::move(pixel);
|
asset.pixelData = std::move(pixel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static std::string TinyDDSResultToString(tinyddsloader::Result value);
|
static std::string TinyDDSResultToString(tinyddsloader::Result value);
|
||||||
|
static vk::Format ddsLoaderToVkFormat(tinyddsloader::DDSFile::DXGIFormat format, bool isLinear);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void LoadImageAsset(AssetPath paths, SHTextureAsset& image);
|
static void LoadImageAsset(AssetPath paths, SHTextureAsset& image);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue