rework label drawable and text drawable's API
This commit is contained in:
@@ -139,23 +139,11 @@ namespace OpenVulkano::Scene
|
||||
throw std::runtime_error("Cannot initialize text drawable with empty atlas data");
|
||||
}
|
||||
m_atlasData = atlasData;
|
||||
m_material.texture = &atlasData->texture;
|
||||
m_cfg = config;
|
||||
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
|
||||
m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT;
|
||||
}
|
||||
|
||||
TextDrawable::TextDrawable(IFontAtlasGenerator* fontAtlasGenerator, const TextConfig& config)
|
||||
{
|
||||
if (!fontAtlasGenerator) { throw std::runtime_error("FontAtlasGenerator is nullptr"); }
|
||||
if (fontAtlasGenerator->GetGlyphsInfo().empty()) { throw std::runtime_error("Glyphs are not loaded"); }
|
||||
m_fontAtlasGenerator = fontAtlasGenerator;
|
||||
m_cfg = config;
|
||||
m_material.texture = const_cast<Texture*>(&m_fontAtlasGenerator->GetAtlas());
|
||||
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
|
||||
m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT;
|
||||
}
|
||||
|
||||
void TextDrawable::GenerateText(const std::string& text, const Math::Vector3f& pos)
|
||||
{
|
||||
if (text.empty())
|
||||
@@ -180,26 +168,12 @@ namespace OpenVulkano::Scene
|
||||
size_t len = GetActualLength();
|
||||
m_geometry.Close();
|
||||
m_geometry.Init(len * 4, len * 6);
|
||||
|
||||
// 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
|
||||
AtlasMetadata* meta;
|
||||
std::map<uint32_t, GlyphInfo>* symbols;
|
||||
if (m_fontAtlasGenerator)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
m_material.texture = &m_atlasData->texture;
|
||||
symbols = &m_atlasData->glyphs;
|
||||
meta = &m_atlasData->meta;
|
||||
}
|
||||
m_material.texture = &m_atlasData->texture;
|
||||
symbols = &m_atlasData->glyphs;
|
||||
meta = &m_atlasData->meta;
|
||||
|
||||
const Texture& atlasTex = *m_material.texture;
|
||||
double cursorX = pos.x;
|
||||
auto begin = text.begin();
|
||||
auto end = text.end();
|
||||
@@ -285,14 +259,4 @@ namespace OpenVulkano::Scene
|
||||
}
|
||||
m_atlasData = atlasData;
|
||||
}
|
||||
|
||||
void TextDrawable::SetFontAtlasGenerator(IFontAtlasGenerator* fontAtlasGenerator)
|
||||
{
|
||||
if (!fontAtlasGenerator || fontAtlasGenerator->GetGlyphsInfo().empty())
|
||||
{
|
||||
Logger::RENDER->error("FontAtlasGenerator is either nullptr or doesn't contain glyphs info");
|
||||
return;
|
||||
}
|
||||
m_fontAtlasGenerator = fontAtlasGenerator;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user