feat: add more image types to load from cooked files

This commit is contained in:
2026-10-24 13:23:30 +02:00
parent 118016bcc7
commit 9cf9242c2a
5 changed files with 73 additions and 4 deletions
+27
View File
@@ -432,6 +432,32 @@ namespace {
"cooked texture pixels must be uploaded as stored");
}
void testLdrTextureFile()
{
const std::vector<std::uint8_t> rgba{255, 0, 0, 255, 0, 128, 255, 64};
const auto texture = TextureFile::FromRGBA8(2, 1, rgba);
const auto loaded = TextureFile::Read(TextureFile::Write(texture));
check(loaded.format == TextureFile::PixelFormat::RGBA8 && loaded.pixels == rgba,
"8 bit cooked textures must round-trip");
const auto dir = std::filesystem::temp_directory_path() / "destrum_ldr_texture_test";
std::filesystem::create_directories(dir);
const auto source = dir / "missing_source.png";
auto cooked = source;
cooked += TextureFile::Extension;
TextureFile::WriteToFile(texture, cooked);
const auto color = util::loadImage(source, TextureIntent::ColorSrgb);
const auto data = util::loadImage(source, TextureIntent::DataLinear);
std::filesystem::remove_all(dir);
check(color.vkFormat == VK_FORMAT_R8G8B8A8_SRGB && data.vkFormat == VK_FORMAT_R8G8B8A8_UNORM,
"8 bit cooked textures must pick their color space from the intent");
check(color.width == 2 && color.height == 1 && color.pixels != nullptr &&
std::memcmp(color.pixels, rgba.data(), rgba.size()) == 0,
"loading a source image must use its cooked sibling");
}
void testAssetReferenceCacheKeys()
{
const AssetReference reference{
@@ -528,6 +554,7 @@ void RunAssetsTests()
testAssetManagerLoadsCookedModels();
testTextureFileRoundTrip();
testImageLoaderReadsCookedTextures();
testLdrTextureFile();
testAssetReferenceCacheKeys();
testAssetGuids();
testAssetDatabaseFollowsMovedAssets();