Cleanup shelf and silence warnings
This commit is contained in:
@@ -47,7 +47,7 @@ namespace OpenVulkano::Scene
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto [allGlyphs, atlasWidth] = InitGlyphsForPacking(chset, face);
|
auto [allGlyphs, atlasWidth] = InitGlyphsForPacking(chset, face);
|
||||||
std::vector<Shelf> shelves = Shelf::CreateShelves(atlasWidth, allGlyphs, face, m_channelsCount);
|
std::vector<Shelf> shelves = Shelf::CreateShelves(atlasWidth, allGlyphs, face.get(), m_channelsCount);
|
||||||
uint32_t atlasHeight = 0;
|
uint32_t atlasHeight = 0;
|
||||||
std::for_each(shelves.begin(), shelves.end(), [&](const Shelf& shelf) { atlasHeight += shelf.GetHeight(); });
|
std::for_each(shelves.begin(), shelves.end(), [&](const Shelf& shelf) { atlasHeight += shelf.GetHeight(); });
|
||||||
const Math::Vector2ui atlasResolution = { atlasWidth, atlasHeight };
|
const Math::Vector2ui atlasResolution = { atlasWidth, atlasHeight };
|
||||||
@@ -183,7 +183,7 @@ namespace OpenVulkano::Scene
|
|||||||
void BitmapFontAtlasGenerator::FillSubpixelData(const FT_Bitmap& bitmap, const GlyphForPacking& glyph)
|
void BitmapFontAtlasGenerator::FillSubpixelData(const FT_Bitmap& bitmap, const GlyphForPacking& glyph)
|
||||||
{
|
{
|
||||||
Texture* tex = m_atlasData->GetTexture();
|
Texture* tex = m_atlasData->GetTexture();
|
||||||
char* texBuffer = static_cast<char*>(tex->textureBuffer);
|
uint8_t* texBuffer = static_cast<uint8_t*>(tex->textureBuffer);
|
||||||
if (m_subpixelLayout.IsHorizontalSubpixelLayout())
|
if (m_subpixelLayout.IsHorizontalSubpixelLayout())
|
||||||
{
|
{
|
||||||
// RGB RGB RGB
|
// RGB RGB RGB
|
||||||
|
|||||||
48
openVulkanoCpp/Scene/Text/Shelf.cpp
Normal file
48
openVulkanoCpp/Scene/Text/Shelf.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,10 +7,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Math/Math.hpp"
|
#include "Math/Math.hpp"
|
||||||
#include "Extensions/FreetypeHelper.hpp"
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
struct FT_FaceRec_;
|
||||||
|
|
||||||
namespace OpenVulkano::Scene
|
namespace OpenVulkano::Scene
|
||||||
{
|
{
|
||||||
struct GlyphForPacking
|
struct GlyphForPacking
|
||||||
@@ -24,10 +25,10 @@ namespace OpenVulkano::Scene
|
|||||||
struct Shelf
|
struct Shelf
|
||||||
{
|
{
|
||||||
inline static std::vector<Shelf> CreateShelves(uint32_t atlasWidth, std::vector<GlyphForPacking>& glyphs,
|
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)
|
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
|
bool HasSpaceForGlyph(uint32_t glyphWidth, uint32_t glyphHeight) const
|
||||||
{
|
{
|
||||||
return m_remainingWidth >= glyphWidth && m_height >= glyphHeight;
|
return m_remainingWidth >= glyphWidth && m_height >= glyphHeight;
|
||||||
@@ -65,45 +66,4 @@ namespace OpenVulkano::Scene
|
|||||||
uint32_t m_prevShelvesHeight;
|
uint32_t m_prevShelvesHeight;
|
||||||
int m_pixelSize;
|
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