split font atlas generator to interface and implementation
This commit is contained in:
@@ -18,11 +18,6 @@
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
#ifdef MSDFGEN_AVAILABLE
|
||||
using namespace msdfgen;
|
||||
using namespace msdf_atlas;
|
||||
#endif
|
||||
|
||||
Shader& TextDrawable::GetDefaultShader()
|
||||
{
|
||||
static bool once = true;
|
||||
@@ -113,7 +108,6 @@ namespace OpenVulkano::Scene
|
||||
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
|
||||
}
|
||||
|
||||
#ifdef MSDFGEN_AVAILABLE
|
||||
TextDrawable::TextDrawable(FontAtlasGenerator* fontAtlasGenerator, const TextConfig& config)
|
||||
{
|
||||
if (!fontAtlasGenerator) { throw std::runtime_error("FontAtlasGenerator is nullptr"); }
|
||||
@@ -123,7 +117,6 @@ namespace OpenVulkano::Scene
|
||||
m_material.texture = const_cast<Texture*>(&m_fontAtlasGenerator->GetAtlas());
|
||||
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
void TextDrawable::GenerateText(const std::string& text, const Math::Vector3f& pos)
|
||||
{
|
||||
@@ -135,32 +128,36 @@ namespace OpenVulkano::Scene
|
||||
m_geometry.Close();
|
||||
m_geometry.Init(text.size() * 4, text.size() * 6);
|
||||
|
||||
#ifdef MSDFGEN_AVAILABLE
|
||||
// TODO: better implementation to decide what to use: data from atlas generator or data read from file
|
||||
// we have msdf but loaded glyphs metadata from file before
|
||||
std::optional<std::reference_wrapper<std::map<unicode_t, GlyphInfo>>> glyphData;
|
||||
if (m_fontAtlasGenerator->GetGlyphsInfo().empty() && !m_glyphs.empty())
|
||||
AtlasMetadata* meta;
|
||||
std::map<uint32_t, GlyphInfo>* symbols;
|
||||
if (m_fontAtlasGenerator)
|
||||
{
|
||||
// texture is set in ctor
|
||||
glyphData = m_glyphs;
|
||||
if (m_fontAtlasGenerator->GetGlyphsInfo().empty() && !m_glyphs.empty())
|
||||
{
|
||||
// texture is set in ctor
|
||||
symbols = &m_glyphs;
|
||||
}
|
||||
else
|
||||
{
|
||||
// just in case if FontAtlasGenerator changed it's atlas
|
||||
m_material.texture = const_cast<Texture*>(&m_fontAtlasGenerator->GetAtlas());
|
||||
symbols = &m_fontAtlasGenerator->GetGlyphsInfo();
|
||||
}
|
||||
meta = &m_fontAtlasGenerator->GetAtlasMetadata();
|
||||
}
|
||||
else
|
||||
{
|
||||
// just in case if FontAtlasGenerator changed it's atlas
|
||||
m_material.texture = const_cast<Texture*>(&m_fontAtlasGenerator->GetAtlas());
|
||||
glyphData = m_fontAtlasGenerator->GetGlyphsInfo();
|
||||
symbols = &m_glyphs;
|
||||
meta = &m_meta;
|
||||
}
|
||||
std::map<unicode_t, GlyphInfo>& symbols = glyphData.value();
|
||||
AtlasMetadata& meta = m_fontAtlasGenerator->GetAtlasMetadata();
|
||||
#else
|
||||
std::map<unicode_t, GlyphInfo>& symbols = m_glyphs;
|
||||
AtlasMetadata& meta = m_meta;
|
||||
#endif
|
||||
|
||||
const Texture& atlasTex = *m_material.texture;
|
||||
double cursorX = pos.x;
|
||||
auto begin = text.begin();
|
||||
auto end = text.end();
|
||||
const double lineHeight = meta.lineHeight;
|
||||
const double lineHeight = meta->lineHeight;
|
||||
double posY = pos.y;
|
||||
for (size_t i = 0; begin != end; i++)
|
||||
{
|
||||
@@ -171,11 +168,11 @@ namespace OpenVulkano::Scene
|
||||
cursorX = pos.x;
|
||||
continue;
|
||||
}
|
||||
if (symbols.find(c) != symbols.end())
|
||||
if (symbols->find(c) != symbols->end())
|
||||
{
|
||||
uint32_t vIdx = i * 4;
|
||||
uint32_t indices[] = { 1 + vIdx, 2 + vIdx, 3 + vIdx, 1 + vIdx, 3 + vIdx, 0 + vIdx };
|
||||
GlyphInfo& info = symbols.at(c);
|
||||
GlyphInfo& info = symbols->at(c);
|
||||
|
||||
// left bottom
|
||||
m_geometry.vertices[vIdx].position.x = info.xyz[0].x + cursorX;
|
||||
|
||||
Reference in New Issue
Block a user