39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
#ifndef DESTRUM_TEXTUREFILE_H
|
|
#define DESTRUM_TEXTUREFILE_H
|
|
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <span>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace TextureFile {
|
|
inline constexpr std::uint32_t Version = 1;
|
|
inline constexpr std::string_view Extension = ".dtex";
|
|
|
|
enum class PixelFormat : std::uint32_t {
|
|
RGBA16Float,
|
|
};
|
|
|
|
struct Texture {
|
|
std::uint32_t width{0};
|
|
std::uint32_t height{0};
|
|
PixelFormat format{PixelFormat::RGBA16Float};
|
|
std::vector<std::uint8_t> pixels;
|
|
};
|
|
|
|
[[nodiscard]] std::size_t BytesPerPixel(PixelFormat format);
|
|
|
|
[[nodiscard]] Texture FromRGBA32Float(std::uint32_t width, std::uint32_t height, std::span<const float> rgba);
|
|
|
|
[[nodiscard]] std::vector<std::uint8_t> Write(const Texture& texture);
|
|
[[nodiscard]] Texture Read(std::span<const std::uint8_t> bytes);
|
|
|
|
void WriteToFile(const Texture& texture, const std::filesystem::path& path);
|
|
[[nodiscard]] Texture ReadFromFile(const std::filesystem::path& path);
|
|
[[nodiscard]] std::optional<std::uint32_t> ReadVersionFromFile(const std::filesystem::path& path);
|
|
}
|
|
|
|
#endif // DESTRUM_TEXTUREFILE_H
|