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
+15
View File
@@ -21,6 +21,8 @@ std::size_t TextureFile::BytesPerPixel(PixelFormat format) {
switch (format) {
case PixelFormat::RGBA16Float:
return 4 * sizeof(std::uint16_t);
case PixelFormat::RGBA8:
return 4;
}
throw std::runtime_error("Unknown cooked texture pixel format");
}
@@ -46,6 +48,19 @@ TextureFile::Texture TextureFile::FromRGBA32Float(std::uint32_t width, std::uint
return texture;
}
TextureFile::Texture TextureFile::FromRGBA8(std::uint32_t width, std::uint32_t height, std::span<const std::uint8_t> rgba) {
if (rgba.size() != std::size_t{width} * height * 4) {
throw std::invalid_argument("RGBA pixel data doesn't match the texture size");
}
return Texture{
.width = width,
.height = height,
.format = PixelFormat::RGBA8,
.pixels = {rgba.begin(), rgba.end()},
};
}
std::vector<std::uint8_t> TextureFile::Write(const Texture& texture) {
if (texture.pixels.size() != ExpectedByteSize(texture)) {
throw std::invalid_argument("Texture pixel data doesn't match its size and format");