diff --git a/openVulkanoCpp/Scene/Text/BitmapFontAtlasGenerator.cpp b/openVulkanoCpp/Scene/Text/BitmapFontAtlasGenerator.cpp index e917b29..b6958ea 100644 --- a/openVulkanoCpp/Scene/Text/BitmapFontAtlasGenerator.cpp +++ b/openVulkanoCpp/Scene/Text/BitmapFontAtlasGenerator.cpp @@ -47,7 +47,7 @@ namespace OpenVulkano::Scene } auto [allGlyphs, atlasWidth] = InitGlyphsForPacking(chset, face); - std::vector shelves = Shelf::CreateShelves(atlasWidth, allGlyphs, face, m_channelsCount); + std::vector shelves = Shelf::CreateShelves(atlasWidth, allGlyphs, face.get(), m_channelsCount); uint32_t atlasHeight = 0; std::for_each(shelves.begin(), shelves.end(), [&](const Shelf& shelf) { atlasHeight += shelf.GetHeight(); }); const Math::Vector2ui atlasResolution = { atlasWidth, atlasHeight }; @@ -183,7 +183,7 @@ namespace OpenVulkano::Scene void BitmapFontAtlasGenerator::FillSubpixelData(const FT_Bitmap& bitmap, const GlyphForPacking& glyph) { Texture* tex = m_atlasData->GetTexture(); - char* texBuffer = static_cast(tex->textureBuffer); + uint8_t* texBuffer = static_cast(tex->textureBuffer); if (m_subpixelLayout.IsHorizontalSubpixelLayout()) { // RGB RGB RGB diff --git a/openVulkanoCpp/Scene/Text/Shelf.cpp b/openVulkanoCpp/Scene/Text/Shelf.cpp new file mode 100644 index 0000000..2809f46 --- /dev/null +++ b/openVulkanoCpp/Scene/Text/Shelf.cpp @@ -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::CreateShelves(uint32_t atlasWidth, std::vector& glyphs, + FT_FaceRec_* face, int channelsCount) + { + std::vector 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> 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; + } +} \ No newline at end of file diff --git a/openVulkanoCpp/Scene/Text/Shelf.hpp b/openVulkanoCpp/Scene/Text/Shelf.hpp index 6b633b7..2370287 100644 --- a/openVulkanoCpp/Scene/Text/Shelf.hpp +++ b/openVulkanoCpp/Scene/Text/Shelf.hpp @@ -7,10 +7,11 @@ #pragma once #include "Math/Math.hpp" -#include "Extensions/FreetypeHelper.hpp" #include #include +struct FT_FaceRec_; + namespace OpenVulkano::Scene { struct GlyphForPacking @@ -24,10 +25,10 @@ namespace OpenVulkano::Scene struct Shelf { inline static std::vector CreateShelves(uint32_t atlasWidth, std::vector& 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::CreateShelves(uint32_t atlasWidth, std::vector& glyphs, - const FtFaceRecPtr& face, int channelsCount) - { - std::vector 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> 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; - } }