Shrink GlyphInfo struct

This commit is contained in:
Georg Hagen
2025-01-10 18:09:38 +01:00
parent ce57ed2091
commit f58064d724
3 changed files with 27 additions and 20 deletions

View File

@@ -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;
};

View File

@@ -82,7 +82,11 @@ namespace OpenVulkano::Scene
for (const auto& [key, val] : m_atlasData->glyphs)
{
fs.write(reinterpret_cast<const char*>(&key), sizeof(uint32_t));
fs.write(reinterpret_cast<const char*>(&val), sizeof(GlyphInfo));
fs.write(reinterpret_cast<const char*>(&val.pos), sizeof(GlyphInfo::pos));
fs.write(reinterpret_cast<const char*>(&val.pos), sizeof(GlyphInfo::pos)); // TODO remove this after cleaning up the atlas writing code
fs.write(reinterpret_cast<const char*>(&val.uv), sizeof(GlyphInfo::uv));
fs.write(reinterpret_cast<const char*>(&val.advance), sizeof(GlyphInfo::advance));
fs.write(reinterpret_cast<const char*>(&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;

View File

@@ -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;
}