code cleanup

This commit is contained in:
ohyzha
2024-08-07 21:52:54 +03:00
parent 38d97f4c28
commit a390470420
6 changed files with 45 additions and 41 deletions

View File

@@ -68,7 +68,7 @@ namespace OpenVulkano
m_drawablesPool.resize(N);
#ifdef MSDFGEN_AVAILABLE
Charset charset = MsdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
msdf_atlas::Charset charset = MsdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
//Charset charset = Charset::ASCII;
//for (unicode_t c = 0x0410; c <= 0x041F; c++)
//{

View File

@@ -6,12 +6,12 @@
#pragma once
#include "Scene/AtlasMetadata.hpp"
#include "Scene/Texture.hpp"
#include <string>
#include <optional>
#include <map>
#include <variant>
#include "Scene/AtlasMetadata.hpp"
#include "Scene/Texture.hpp"
#include <set>
#include <memory>

View File

@@ -9,9 +9,12 @@
#include "MsdfFontAtlasGenerator.hpp"
#include "Base/Logger.hpp"
#include "Scene/AtlasMetadata.hpp"
#include <msdfgen.h>
#include <msdfgen-ext.h>
#include <msdf-atlas-gen/msdf-atlas-gen.h>
#define STBI_MSC_SECURE_CRT
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#include <stb_image_write.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <fstream>
@@ -255,7 +258,7 @@ namespace OpenVulkano::Scene
deinitializeFreetype(ft);
}
void MsdfFontAtlasGenerator::SavePng(const BitmapConstRef<byte, 1>& storage, const std::string& output,
void MsdfFontAtlasGenerator::SavePng(const BitmapConstRef<msdfgen::byte, 1>& storage, const std::string& output,
int channels) const
{
stbi_flip_vertically_on_write(1);

View File

@@ -8,48 +8,49 @@
#if __has_include("msdfgen.h")
#include "Scene/AtlasMetadata.hpp"
#include "FontAtlasGenerator.hpp"
#include "Scene/Texture.hpp"
#include <msdfgen.h>
#include <msdf-atlas-gen/msdf-atlas-gen.h>
#include <string>
#include <optional>
#include <map>
#include <variant>
#include "Scene/AtlasMetadata.hpp"
#include "FontAtlasGenerator.hpp"
#include "Scene/Texture.hpp"
#include "msdfgen.h"
#include "msdfgen-ext.h"
#include "msdf-atlas-gen/msdf-atlas-gen.h"
#define MSDFGEN_AVAILABLE
#define MSDFGEN_AVAILABLE 1
namespace OpenVulkano::Scene
{
using namespace msdfgen;
using namespace msdf_atlas;
using namespace OpenVulkano::Scene;
class MsdfFontAtlasGenerator : public FontAtlasGenerator
{
public:
using SdfGenerator = ImmediateAtlasGenerator<float, 1, sdfGenerator, BitmapAtlasStorage<msdfgen::byte, 1>>;
static Charset LoadAllGlyphs(const std::variant<std::string, Array<char>>& data);
using SdfGenerator = msdf_atlas::ImmediateAtlasGenerator<float, 1, msdf_atlas::sdfGenerator,
msdf_atlas::BitmapAtlasStorage<msdfgen::byte, 1>>;
static msdf_atlas::Charset LoadAllGlyphs(const std::variant<std::string, Array<char>>& data);
void GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset,
const std::optional<std::string>& pngOutput = std::nullopt) override;
void GenerateAtlas(const Array<char>& fontData, int length, const std::set<uint32_t>& charset,
const std::optional<std::string>& pngOutput = std::nullopt) override;
void GenerateAtlas(const std::string& fontFile, const Charset& charset = Charset::ASCII,
void GenerateAtlas(const std::string& fontFile, const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII,
const std::optional<std::string>& pngOutput = std::nullopt);
void GenerateAtlas(const msdfgen::byte* fontData, int length, const Charset& charset = Charset::ASCII,
void GenerateAtlas(const msdfgen::byte* fontData, int length,
const msdf_atlas::Charset& charset = msdf_atlas::Charset::ASCII,
const std::optional<std::string>& pngOutput = std::nullopt);
void SaveAtlasMetadataInfo(const std::string& outputFile, bool packIntoSingleFile = true) const override;
const Texture& GetAtlas() const override { return m_atlasTex; }
std::map<uint32_t, GlyphInfo>& GetGlyphsInfo() override { return m_symbols; }
AtlasMetadata& GetAtlasMetadata() override { return m_meta; }
SdfGenerator& GetFontAtlasGenerator() { return m_generator; }
private:
void InitFreetypeFromFile(FreetypeHandle*& ft, FontHandle*& font, const std::string& file);
void InitFreetypeFromBuffer(FreetypeHandle*& ft, FontHandle*& font, const msdfgen::byte* fontData, int length);
void Generate(FreetypeHandle* ft, FontHandle* font, const Charset& chset,
void InitFreetypeFromFile(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font, const std::string& file);
void InitFreetypeFromBuffer(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font,
const msdfgen::byte* fontData, int length);
void Generate(msdfgen::FreetypeHandle* ft, msdfgen::FontHandle* font, const msdf_atlas::Charset& chset,
const std::optional<std::string>& pngOutput);
void SavePng(const BitmapConstRef<byte, 1>& storage, const std::string& output, int channels) const;
void SavePng(const msdfgen::BitmapConstRef<msdfgen::byte, 1>& storage, const std::string& output,
int channels) const;
private:
SdfGenerator m_generator;
Texture m_atlasTex;

View File

@@ -12,9 +12,11 @@
#include "Scene/FontAtlasGenerator.hpp"
#include "Base/Logger.hpp"
#include "Host/ResourceLoader.hpp"
#include "Image/ImageLoader.hpp"
#include "DataFormat.hpp"
#include "Base/Logger.hpp"
#include <fstream>
#include <utf8.h>
#include "Image/ImageLoader.hpp"
namespace OpenVulkano::Scene
{
@@ -210,4 +212,14 @@ namespace OpenVulkano::Scene
}
SimpleDrawable::Init(m_shader, &m_geometry, &m_material, &m_uniBuffer);
}
void TextDrawable::SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator)
{
if (!fontAtlasGenerator || fontAtlasGenerator->GetGlyphsInfo().empty())
{
Logger::RENDER->error("FontAtlasGenerator is either nullptr or doesn't contain glyphs info");
return;
}
m_fontAtlasGenerator = fontAtlasGenerator;
}
}

View File

@@ -6,24 +6,20 @@
#pragma once
#include "UpdateFrequency.hpp"
#include "Base/ICloseable.hpp"
#include "Math/Math.hpp"
#include "DataFormat.hpp"
#include "SimpleDrawable.hpp"
#include "FontAtlasGenerator.hpp"
#include "Texture.hpp"
#include "Material.hpp"
#include "Geometry.hpp"
#include "UniformBuffer.hpp"
#include "Base/Logger.hpp"
#include "AtlasMetadata.hpp"
#include "Image/Image.hpp"
#include <map>
#include "FontAtlasGenerator.hpp"
namespace OpenVulkano::Scene
{
class FontAtlasGenerator;
struct TextConfig
{
Math::Vector4f textColor = { 1, 1, 1, 1 };
@@ -51,15 +47,7 @@ namespace OpenVulkano::Scene
void SetShader(Shader* shader) { m_shader = shader; }
TextConfig& GetConfig() { return m_cfg; }
Shader* GetShader() { return m_shader; }
void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator)
{
if (!fontAtlasGenerator || fontAtlasGenerator->GetGlyphsInfo().empty())
{
Logger::RENDER->error("FontAtlasGenerator is either nullptr or doesn't contain glyphs info");
return;
}
m_fontAtlasGenerator = fontAtlasGenerator;
}
void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator);
FontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
private:
Geometry m_geometry;