feat: add more image types to load from cooked files
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user