48 lines
1.4 KiB
C++
48 lines
1.4 KiB
C++
/*
|
|
* 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;
|
|
}
|
|
} |