From f58064d724b469189e8ed5f29483a0ea6c5cb75d Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Fri, 10 Jan 2025 18:09:38 +0100 Subject: [PATCH] Shrink GlyphInfo struct --- openVulkanoCpp/Scene/AtlasData.hpp | 2 +- .../Scene/FontAtlasGeneratorBase.cpp | 26 +++++++++---------- openVulkanoCpp/Scene/TextDrawable.cpp | 19 +++++++++----- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/openVulkanoCpp/Scene/AtlasData.hpp b/openVulkanoCpp/Scene/AtlasData.hpp index be784ec..2fc74ef 100644 --- a/openVulkanoCpp/Scene/AtlasData.hpp +++ b/openVulkanoCpp/Scene/AtlasData.hpp @@ -20,7 +20,7 @@ namespace OpenVulkano::Scene { //GlyphGeometry geometry; //GlyphBox glyphBox; - Math::Vector3f_SIMD xyz[4] = {}; + Math::Vector2f_SIMD pos[4] = {}; Math::Vector2f_SIMD uv[4] = {}; double advance = 0; }; diff --git a/openVulkanoCpp/Scene/FontAtlasGeneratorBase.cpp b/openVulkanoCpp/Scene/FontAtlasGeneratorBase.cpp index b1218af..3db5aba 100644 --- a/openVulkanoCpp/Scene/FontAtlasGeneratorBase.cpp +++ b/openVulkanoCpp/Scene/FontAtlasGeneratorBase.cpp @@ -82,7 +82,11 @@ namespace OpenVulkano::Scene for (const auto& [key, val] : m_atlasData->glyphs) { fs.write(reinterpret_cast(&key), sizeof(uint32_t)); - fs.write(reinterpret_cast(&val), sizeof(GlyphInfo)); + fs.write(reinterpret_cast(&val.pos), sizeof(GlyphInfo::pos)); + fs.write(reinterpret_cast(&val.pos), sizeof(GlyphInfo::pos)); // TODO remove this after cleaning up the atlas writing code + fs.write(reinterpret_cast(&val.uv), sizeof(GlyphInfo::uv)); + fs.write(reinterpret_cast(&val.advance), sizeof(GlyphInfo::advance)); + fs.write(reinterpret_cast(&val.advance), sizeof(GlyphInfo::advance)); // TODO remove this afer cleaning up the atlas writing code metadataBytes += sizeof(uint32_t); metadataBytes += sizeof(GlyphInfo); } @@ -125,32 +129,28 @@ namespace OpenVulkano::Scene void FontAtlasGeneratorBase::SetGlyphData(GlyphInfo& info, Math::Vector2d bearing, Math::Vector2d size, const Math::AABB& aabb, double advance) { - const double bearingX = bearing.x; - const double bearingY = bearing.y; - const double w = size.x; - const double h = size.y; const double l = aabb.min.x; const double r = aabb.max.x; const double t = aabb.max.y; const double b = aabb.min.y; - info.xyz[0].x = bearingX; - info.xyz[0].y = h - bearingY; + info.pos[0].x = bearing.x; + info.pos[0].y = size.y - bearing.y; info.uv[0].x = l / m_atlasData->texture.resolution.x; info.uv[0].y = b / m_atlasData->texture.resolution.y; - info.xyz[1].x = bearingX + w; - info.xyz[1].y = h - bearingY; + info.pos[1].x = bearing.x + size.x; + info.pos[1].y = size.y - bearing.y; info.uv[1].x = r / m_atlasData->texture.resolution.x; info.uv[1].y = b / m_atlasData->texture.resolution.y; - info.xyz[2].x = bearingX + w; - info.xyz[2].y = bearingY; //h - bearingY + h; + info.pos[2].x = bearing.x + size.x; + info.pos[2].y = bearing.y; info.uv[2].x = r / m_atlasData->texture.resolution.x; info.uv[2].y = t / m_atlasData->texture.resolution.y; - info.xyz[3].x = bearingX; - info.xyz[3].y = bearingY; + info.pos[3].x = bearing.x; + info.pos[3].y = bearing.y; info.uv[3].x = l / m_atlasData->texture.resolution.x; info.uv[3].y = t / m_atlasData->texture.resolution.y; diff --git a/openVulkanoCpp/Scene/TextDrawable.cpp b/openVulkanoCpp/Scene/TextDrawable.cpp index 88acca2..b17b60c 100644 --- a/openVulkanoCpp/Scene/TextDrawable.cpp +++ b/openVulkanoCpp/Scene/TextDrawable.cpp @@ -107,9 +107,16 @@ namespace OpenVulkano::Scene read_bytes += sizeof(uint32_t); readMetadataBytes += sizeof(uint32_t); GlyphInfo& info = m_atlasData->glyphs[unicode]; - std::memcpy(&info, atlasMetadata.Data() + read_bytes, sizeof(GlyphInfo)); - read_bytes += sizeof(GlyphInfo); - readMetadataBytes += sizeof(GlyphInfo); + for (int i = 0; i < 4; i++) + { + std::memcpy(&info.pos[i], atlasMetadata.Data() + read_bytes, sizeof(GlyphInfo::pos) / 4); + read_bytes += sizeof(GlyphInfo::pos) / 2; + } + std::memcpy(&info.uv, atlasMetadata.Data() + read_bytes, sizeof(GlyphInfo::uv)); + read_bytes += sizeof(GlyphInfo::uv); + std::memcpy(&info.advance, atlasMetadata.Data() + read_bytes, sizeof(GlyphInfo::advance)); + read_bytes += sizeof(GlyphInfo::advance) * 2; + readMetadataBytes += sizeof(GlyphInfo) + sizeof(GlyphInfo::pos) + sizeof(double); } if (m_atlasData->meta.atlasType == FontAtlasType::BITMAP) { @@ -172,10 +179,10 @@ namespace OpenVulkano::Scene for (int i = 0; i < 4; i++) { - vertices->position[i].x = info.xyz[i].x + cursorX; + vertices->position[i].x = info.pos[i].x + cursorX; vertices->uv[i] = info.uv[i]; - if (i < 2) vertices->position[i].y = posY - info.xyz[i].y; - else vertices->position[i].y = posY + info.xyz[i].y; + if (i < 2) vertices->position[i].y = posY - info.pos[i].y; + else vertices->position[i].y = posY + info.pos[i].y; vertices->color = m_cfg.textColor; vertices->background = m_cfg.backgroundColor; }