/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include "FontAtlasType.hpp" #include "Math/Math.hpp" #include "Data/Containers/Array.hpp" #include "Scene/Texture.hpp" #include #include namespace OpenVulkano::Scene { struct GlyphInfo { //GlyphGeometry geometry; //GlyphBox glyphBox; Math::Vector2f_SIMD pos[4] = {}; Math::Vector2f_SIMD uv[4] = {}; double advance = 0; }; class FontAtlas { struct Metadata { double lineHeight = 0; FontAtlasType atlasType = FontAtlasType::UNKNOWN; }; std::map m_glyphs; Metadata m_metadata; Array m_imgData; Texture m_texture; void LoadLegacy(std::span data); void LoadNew(std::span data); void LoadImage(std::span data); Array SerializeMetadata() const; void DeserializeMetadata(const std::span& data); public: FontAtlas() = default; FontAtlas(const Math::Vector2ui textureResolution, const double lineHeight, const FontAtlasType atlasType) { Init(textureResolution, lineHeight, atlasType); } FontAtlas(const std::filesystem::path& path); FontAtlas(const std::span data) { Load(data); } void Init(Math::Vector2ui textureResolution, double lineHeight, FontAtlasType atlasType); void Save(const std::filesystem::path& path) const; void Load(std::span data); [[nodiscard]] operator bool() const { return !m_glyphs.empty() && m_texture.textureBuffer; } [[nodiscard]] Texture* GetTexture() { return &m_texture; } [[nodiscard]] decltype(m_glyphs)& GetGlyphs() { return m_glyphs; } [[nodiscard]] decltype(Metadata::lineHeight) GetLineHeight() const { return m_metadata.lineHeight;} [[nodiscard]] FontAtlasType GetAtlasType() const { return m_metadata.atlasType;} }; }