Update fallback glyph handling
This commit is contained in:
@@ -126,9 +126,22 @@ namespace OpenVulkano::Scene
|
||||
m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT;
|
||||
}
|
||||
|
||||
uint32_t TextDrawable::GetFallbackGlyph() const
|
||||
{
|
||||
if (m_atlasData->glyphs.find(MISSING_GLYPH_SYMBOL) != m_atlasData->glyphs.end())
|
||||
{
|
||||
return MISSING_GLYPH_SYMBOL;
|
||||
}
|
||||
Logger::RENDER->warn("Could not find glyph for character ? to use as fallback. Using first glyph instead");
|
||||
return m_atlasData->glyphs.begin()->first;
|
||||
}
|
||||
|
||||
|
||||
void TextDrawable::GenerateText(const std::string& text, const Math::Vector3f& pos)
|
||||
{
|
||||
if (text.empty()) return;
|
||||
if (!m_atlasData && !*m_atlasData) { Logger::RENDER->error("Must have glyphs"); return;}
|
||||
const uint32_t fallbackGlyph = GetFallbackGlyph();
|
||||
|
||||
m_text = text;
|
||||
|
||||
@@ -161,16 +174,8 @@ namespace OpenVulkano::Scene
|
||||
|
||||
if (symbols->find(c) == symbols->end())
|
||||
{
|
||||
Logger::RENDER->error("Could not find glyph for character {}", c);
|
||||
if (symbols->find(static_cast<uint32_t>('?')) != symbols->end())
|
||||
{
|
||||
c = static_cast<uint32_t>('?');
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::RENDER->error("Could not find glyph for character ? to replace glyph {}", c);
|
||||
continue;
|
||||
}
|
||||
Logger::RENDER->warn("Could not find glyph for character {}, using fallback", c);
|
||||
c = fallbackGlyph;
|
||||
}
|
||||
|
||||
uint32_t vIdx = i * 4;
|
||||
|
||||
@@ -34,6 +34,16 @@ namespace OpenVulkano::Scene
|
||||
{
|
||||
static Shader DEFAULT_SHADER_BITMAP, DEFAULT_SHADER_SDF, DEFAULT_SHADER_MSDF;
|
||||
|
||||
Geometry m_geometry;
|
||||
Material m_material;
|
||||
UniformBuffer m_uniBuffer;
|
||||
std::shared_ptr<AtlasData> m_atlasData;
|
||||
Math::AABB m_bbox;
|
||||
std::string m_text;
|
||||
TextConfig m_cfg;
|
||||
|
||||
uint32_t GetFallbackGlyph() const;
|
||||
|
||||
public:
|
||||
[[nodiscard]] static Shader& GetSdfDefaultShader() { return DEFAULT_SHADER_SDF; }
|
||||
[[nodiscard]] static Shader& GetMsdfDefaultShader() { return DEFAULT_SHADER_MSDF; }
|
||||
@@ -51,14 +61,5 @@ namespace OpenVulkano::Scene
|
||||
[[nodiscard]] TextConfig& GetConfig() { return m_cfg; }
|
||||
[[nodiscard]] const std::string& GetText() const { return m_text; }
|
||||
[[nodiscard]] const std::shared_ptr<AtlasData> GetAtlasData() { return m_atlasData; }
|
||||
|
||||
private:
|
||||
Geometry m_geometry;
|
||||
Material m_material;
|
||||
UniformBuffer m_uniBuffer;
|
||||
std::shared_ptr<AtlasData> m_atlasData;
|
||||
Math::AABB m_bbox;
|
||||
std::string m_text;
|
||||
TextConfig m_cfg;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user