From 884949f92f9fd4ccf886dbd88a21837929a01ce8 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sat, 4 Jan 2025 02:02:14 +0100 Subject: [PATCH] Deduplicate Atlas validity checking --- openVulkanoCpp/Scene/AtlasData.hpp | 2 +- openVulkanoCpp/Scene/TextDrawable.cpp | 16 ++++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/openVulkanoCpp/Scene/AtlasData.hpp b/openVulkanoCpp/Scene/AtlasData.hpp index f62c8de..7311239 100644 --- a/openVulkanoCpp/Scene/AtlasData.hpp +++ b/openVulkanoCpp/Scene/AtlasData.hpp @@ -64,7 +64,7 @@ namespace OpenVulkano::Scene Unique img; Texture texture; - operator bool() const { return !glyphs.empty(); } + operator bool() const { return !glyphs.empty() && texture.textureBuffer; } }; } \ No newline at end of file diff --git a/openVulkanoCpp/Scene/TextDrawable.cpp b/openVulkanoCpp/Scene/TextDrawable.cpp index 5619114..bbe5c1e 100644 --- a/openVulkanoCpp/Scene/TextDrawable.cpp +++ b/openVulkanoCpp/Scene/TextDrawable.cpp @@ -63,6 +63,7 @@ namespace OpenVulkano::Scene {} TextDrawable::TextDrawable(const Array& 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, 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) { - 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; } } \ No newline at end of file