Cleanup shelf and silence warnings

This commit is contained in:
Georg Hagen
2025-02-11 21:59:57 +01:00
parent b4ffd7ce41
commit af9de9c2af
3 changed files with 54 additions and 46 deletions

View File

@@ -0,0 +1,48 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Shelf.hpp"
#include "Extensions/FreetypeHelper.hpp"
namespace OpenVulkano::Scene
{
std::vector<Shelf> Shelf::CreateShelves(uint32_t atlasWidth, std::vector<GlyphForPacking>& glyphs,
FT_FaceRec_* face, int channelsCount)
{
std::vector<Shelf> shelves;
for (GlyphForPacking& glyph : glyphs)
{
FT_Error error = FT_Load_Char(face, glyph.code, FT_LOAD_RENDER);
if (error) continue;
bool needNewShelf = true;
uint32_t totalPrevShelvesHeight = 0;
for (Shelf& shelf : shelves)
{
if (std::optional<std::pair<uint32_t, uint32_t>> opt = shelf.AddGlyph(glyph.size.x, glyph.size.y))
{
glyph.firstGlyphByteInAtlas = opt->second;
glyph.atlasPos.x = opt->first;
glyph.atlasPos.y = totalPrevShelvesHeight;
needNewShelf = false;
break;
}
totalPrevShelvesHeight += shelf.GetHeight();
}
if (needNewShelf)
{
shelves.emplace_back(atlasWidth, glyph.size.y, channelsCount, totalPrevShelvesHeight);
Shelf& shelf = shelves.back();
uint32_t firstByte = (*shelf.AddGlyph(glyph.size.x, glyph.size.y)).second;
glyph.firstGlyphByteInAtlas = firstByte;
glyph.atlasPos.x = 0;
glyph.atlasPos.y = totalPrevShelvesHeight;
}
}
return shelves;
}
}