Cleanup shelf and silence warnings
This commit is contained in:
@@ -7,10 +7,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "Math/Math.hpp"
|
||||
#include "Extensions/FreetypeHelper.hpp"
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
|
||||
struct FT_FaceRec_;
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
struct GlyphForPacking
|
||||
@@ -24,10 +25,10 @@ namespace OpenVulkano::Scene
|
||||
struct Shelf
|
||||
{
|
||||
inline static std::vector<Shelf> CreateShelves(uint32_t atlasWidth, std::vector<GlyphForPacking>& glyphs,
|
||||
const FtFaceRecPtr& face, int channelsCount);
|
||||
FT_FaceRec_* face, int channelsCount);
|
||||
|
||||
Shelf(uint32_t width, uint32_t height, int pixelSize, uint32_t prevShelvesHeight)
|
||||
: m_width(width), m_height(height), m_remainingWidth(width), m_pixelSize(pixelSize), m_prevShelvesHeight(prevShelvesHeight) {}
|
||||
: m_width(width), m_height(height), m_remainingWidth(width), m_prevShelvesHeight(prevShelvesHeight), m_pixelSize(pixelSize) {}
|
||||
bool HasSpaceForGlyph(uint32_t glyphWidth, uint32_t glyphHeight) const
|
||||
{
|
||||
return m_remainingWidth >= glyphWidth && m_height >= glyphHeight;
|
||||
@@ -65,45 +66,4 @@ namespace OpenVulkano::Scene
|
||||
uint32_t m_prevShelvesHeight;
|
||||
int m_pixelSize;
|
||||
};
|
||||
|
||||
std::vector<Shelf> Shelf::CreateShelves(uint32_t atlasWidth, std::vector<GlyphForPacking>& glyphs,
|
||||
const FtFaceRecPtr& face, int channelsCount)
|
||||
{
|
||||
std::vector<Shelf> shelves;
|
||||
for (GlyphForPacking& glyph : glyphs)
|
||||
{
|
||||
FT_Error error = FT_Load_Char(face.get(), glyph.code, FT_LOAD_RENDER);
|
||||
if (error)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FT_GlyphSlot slot = face->glyph;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user