diff --git a/openVulkanoCpp/Scene/Text/FontAtlas.cpp b/openVulkanoCpp/Scene/Text/FontAtlas.cpp index 200f15d..5432244 100644 --- a/openVulkanoCpp/Scene/Text/FontAtlas.cpp +++ b/openVulkanoCpp/Scene/Text/FontAtlas.cpp @@ -16,6 +16,16 @@ namespace OpenVulkano::Scene { + namespace + { + struct FontAtlasFileFlags + { + uint8_t packed = 1; + uint8_t version = 1; + uint16_t reserved = 0; + }; + } + FontAtlas::FontAtlas(const std::filesystem::path& path) { auto content = Utils::ReadFile(path); @@ -41,25 +51,25 @@ namespace OpenVulkano::Scene metadataBytes += sizeof(uint32_t) + sizeof(GlyphInfo); } fs.write(reinterpret_cast(&metadataBytes), sizeof(uint64_t)); - std::array flags = { 1, 1, 0, 0 }; - fs.write(reinterpret_cast(&flags), sizeof(std::array)); + FontAtlasFileFlags flags; + fs.write(reinterpret_cast(&flags), sizeof(FontAtlasFileFlags)); fs.close(); } void FontAtlas::Load(const std::span data) { if (data.size() < 16) { Logger::DATA->warn("Font atlas file is invalid!"); return; }; - uint8_t flags[4] = { 0, 0, 0, 0 }; + FontAtlasFileFlags flags; std::memcpy(&flags, data.data() + data.size() - sizeof(flags), sizeof(flags)); - size_t headerSize = sizeof(flags) + sizeof(uint64_t); + size_t headerSize = sizeof(FontAtlasFileFlags) + sizeof(uint64_t); uint64_t metadataSize = *reinterpret_cast(data.data() + data.size() - headerSize); char* metadata = data.data() + data.size() - headerSize - metadataSize; - if (flags[0] == 0) throw std::runtime_error("No longer support loading of unpacked font atlas!"); + if (flags.packed == 0) throw std::runtime_error("No longer support loading of unpacked font atlas!"); LoadImage({ data.data(), data.size() - headerSize - metadataSize }); std::span metadataSpan(metadata, metadataSize); - if (flags[1] == 0) LoadLegacy(metadataSpan); + if (flags.version == 0) LoadLegacy(metadataSpan); else LoadNew(metadataSpan); if (GetAtlasType() >= FontAtlasType::BITMAP) m_texture.m_samplerConfig = &SamplerConfig::NEAREST; }