feat: add more image types to load from cooked files
This commit is contained in:
@@ -53,19 +53,44 @@ namespace util
|
||||
return ext == TextureFile::Extension;
|
||||
}
|
||||
|
||||
static VkFormat toVkFormat(TextureFile::PixelFormat format)
|
||||
static VkFormat toVkFormat(TextureFile::PixelFormat format, TextureIntent intent)
|
||||
{
|
||||
switch (format) {
|
||||
case TextureFile::PixelFormat::RGBA16Float: return VK_FORMAT_R16G16B16A16_SFLOAT;
|
||||
case TextureFile::PixelFormat::RGBA8:
|
||||
return intent == TextureIntent::ColorSrgb ? VK_FORMAT_R8G8B8A8_SRGB : VK_FORMAT_R8G8B8A8_UNORM;
|
||||
}
|
||||
return VK_FORMAT_UNDEFINED;
|
||||
}
|
||||
|
||||
// TheChef writes <image>.dtex next to the copied source, so every caller that has the source path gets it
|
||||
static std::filesystem::path findCookedSibling(const std::filesystem::path& p)
|
||||
{
|
||||
std::filesystem::path cooked = p;
|
||||
cooked += TextureFile::Extension;
|
||||
|
||||
std::error_code error;
|
||||
if (!std::filesystem::is_regular_file(cooked, error)) {
|
||||
return {};
|
||||
}
|
||||
const auto sourceTime = std::filesystem::last_write_time(p, error);
|
||||
if (!error && sourceTime > std::filesystem::last_write_time(cooked, error)) {
|
||||
return {};
|
||||
}
|
||||
return cooked;
|
||||
}
|
||||
|
||||
ImageData loadImage(const std::filesystem::path& p, TextureIntent intent)
|
||||
{
|
||||
ImageData data;
|
||||
|
||||
|
||||
if (!isCookedTextureExt(p)) {
|
||||
if (const auto cooked = findCookedSibling(p); !cooked.empty()) {
|
||||
if (ImageData cookedData = loadImage(cooked, intent); cookedData.byteSize != 0) {
|
||||
return cookedData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isCookedTextureExt(p)) {
|
||||
try {
|
||||
@@ -77,7 +102,7 @@ namespace util
|
||||
data.height = static_cast<int>(texture.height);
|
||||
data.channels = 4;
|
||||
|
||||
data.vkFormat = toVkFormat(texture.format);
|
||||
data.vkFormat = toVkFormat(texture.format, intent);
|
||||
data.byteSize = data.cookedPixels.size();
|
||||
} catch (const std::exception& exception) {
|
||||
spdlog::error("Failed to read cooked texture '{}': {}", p.string(), exception.what());
|
||||
|
||||
Reference in New Issue
Block a user