Deduplicate Atlas validity checking

This commit is contained in:
Georg Hagen
2025-01-04 02:02:14 +01:00
parent f156ff5892
commit 884949f92f
2 changed files with 5 additions and 13 deletions

View File

@@ -63,6 +63,7 @@ namespace OpenVulkano::Scene
{}
TextDrawable::TextDrawable(const Array<char>& atlasMetadata, Texture* atlasTex, const TextConfig& config)
: m_cfg(config)
{
uint32_t isPacked;
std::memcpy(&isPacked, atlasMetadata.Data() + (atlasMetadata.Size() - sizeof(uint32_t)), sizeof(uint32_t));
@@ -105,7 +106,6 @@ namespace OpenVulkano::Scene
read_bytes += sizeof(GlyphInfo);
readMetadataBytes += sizeof(GlyphInfo);
}
m_cfg = config;
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT;
if (m_atlasData->meta.atlasType == FontAtlasType::BITMAP)
@@ -115,13 +115,9 @@ namespace OpenVulkano::Scene
}
TextDrawable::TextDrawable(const std::shared_ptr<AtlasData>& atlasData, const TextConfig& config)
: m_atlasData(atlasData), m_cfg(config)
{
if (!atlasData || atlasData->glyphs.empty() || !atlasData->texture.textureBuffer)
{
throw std::runtime_error("Cannot initialize text drawable with empty atlas data");
}
m_atlasData = atlasData;
m_cfg = config;
if (!atlasData || !*atlasData) throw std::runtime_error("Cannot initialize text drawable with empty atlas data");
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT;
}
@@ -140,7 +136,6 @@ namespace OpenVulkano::Scene
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;
@@ -225,10 +220,7 @@ namespace OpenVulkano::Scene
void TextDrawable::SetAtlasData(const std::shared_ptr<AtlasData>& atlasData)
{
if (!atlasData || atlasData->glyphs.empty() || !atlasData->texture.textureBuffer)
{
throw std::runtime_error("Cannot initialize text drawable with empty atlas data");
}
if (!atlasData || !*atlasData) throw std::runtime_error("Cannot initialize text drawable with empty atlas data");
m_atlasData = atlasData;
}
}