atlas factory Windows implementation

This commit is contained in:
ohyzha
2025-01-17 13:11:04 +02:00
parent 45ca54feb7
commit 169d6c4129
9 changed files with 260 additions and 2 deletions

View File

@@ -0,0 +1,69 @@
/*
* 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 "FontAtlas.hpp"
#include "Scene/SubpixelLayout.hpp"
namespace OpenVulkano::Scene
{
class FontAtlasFactory final
{
struct FontIdentifier
{
FontIdentifier(const std::string& font_, const std::set<uint32_t>& charset, SubpixelLayout subpixelLayout_,
float ptSize_, bool msdf_)
: font(font_), subpixelLayout(subpixelLayout_), ptSize(ptSize_), msdf(msdf_)
{
std::for_each(charset.begin(), charset.end(), [&](uint32_t c) { charsetHash ^= c; });
}
std::string font;
size_t charsetHash = 0;
SubpixelLayout subpixelLayout = SubpixelLayout::UNKNOWN;
float ptSize = 0;
bool msdf = true;
bool operator<(const FontIdentifier& other) const
{
if (font != other.font)
{
return font < other.font;
}
if (charsetHash != other.charsetHash)
{
return charsetHash < other.charsetHash;
}
if (subpixelLayout != other.subpixelLayout)
{
return subpixelLayout < other.subpixelLayout;
}
if (ptSize != other.ptSize)
{
return ptSize < other.ptSize;
}
return msdf < other.msdf;
}
};
public:
FontAtlasFactory(bool allowSystemFonts = true) : m_allowSystemFonts(allowSystemFonts) {}
[[nodiscard]] FontAtlas::Ptr GetFontAtlasScalable(const std::string& fontIdentifier,
const std::set<uint32_t>& charset = {},
bool msdf = true) const;
[[nodiscard]] FontAtlas::Ptr GetFontAtlas(const std::string& fontIdentifier, float ptSize,
const std::set<uint32_t>& charset = {},
std::optional<SubpixelLayout> subpixelLayout = std::nullopt) const;
private:
std::string FindFont(const std::string& fontFile) const;
private:
bool m_allowSystemFonts;
mutable std::map<FontIdentifier, FontAtlas::Ptr> m_atlasesCache;
};
}