load into buffer

This commit is contained in:
Jorijn van der Graaf 2026-04-11 13:27:15 +02:00
commit 2306f24e42

View file

@ -32,6 +32,12 @@ export namespace Crafter {
Transparent // Color blending is used Transparent // Color blending is used
}; };
struct TextureInfo {
std::uint16_t sizeX;
std::uint16_t sizeY;
OpaqueType opaque;
};
template <typename T> template <typename T>
struct TextureAsset { struct TextureAsset {
std::uint16_t sizeX; std::uint16_t sizeX;
@ -62,6 +68,24 @@ export namespace Crafter {
return tex; return tex;
} }
static TextureInfo LoadInfo(fs::path path) {
TextureInfo info;
std::ifstream file(path, std::ios::binary);
file.read(reinterpret_cast<char*>(&info.sizeX), sizeof(info.sizeX));
file.read(reinterpret_cast<char*>(&info.sizeY), sizeof(info.sizeY));
file.read(reinterpret_cast<char*>(&info.opaque), sizeof(info.opaque));
return info;
}
static void Load(fs::path path, T* pixels, std::uint16_t sizeX, std::uint16_t sizeY) {
std::ifstream file(path, std::ios::binary);
file.seekg(sizeof(std::uint16_t) + sizeof(std::uint16_t) + sizeof(std::uint8_t), std::ios::cur);
file.read(reinterpret_cast<char*>(pixels), sizeX * sizeY * sizeof(T));
}
template <typename TT> template <typename TT>
static TextureAsset<T> LoadPNG(fs::path path) { static TextureAsset<T> LoadPNG(fs::path path) {
TextureAsset<T> tex; TextureAsset<T> tex;