code cleanup
This commit is contained in:
@@ -68,7 +68,7 @@ namespace OpenVulkano
|
|||||||
m_drawablesPool.resize(N);
|
m_drawablesPool.resize(N);
|
||||||
|
|
||||||
#ifdef MSDFGEN_AVAILABLE
|
#ifdef MSDFGEN_AVAILABLE
|
||||||
Charset charset = MsdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
msdf_atlas::Charset charset = MsdfFontAtlasGenerator::LoadAllGlyphs(fontPath);
|
||||||
//Charset charset = Charset::ASCII;
|
//Charset charset = Charset::ASCII;
|
||||||
//for (unicode_t c = 0x0410; c <= 0x041F; c++)
|
//for (unicode_t c = 0x0410; c <= 0x041F; c++)
|
||||||
//{
|
//{
|
||||||
|
|||||||
@@ -6,12 +6,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Scene/AtlasMetadata.hpp"
|
||||||
|
#include "Scene/Texture.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include "Scene/AtlasMetadata.hpp"
|
|
||||||
#include "Scene/Texture.hpp"
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,12 @@
|
|||||||
#include "MsdfFontAtlasGenerator.hpp"
|
#include "MsdfFontAtlasGenerator.hpp"
|
||||||
#include "Base/Logger.hpp"
|
#include "Base/Logger.hpp"
|
||||||
#include "Scene/AtlasMetadata.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 STBI_MSC_SECURE_CRT
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include "stb_image_write.h"
|
#include <stb_image_write.h>
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -255,7 +258,7 @@ namespace OpenVulkano::Scene
|
|||||||
deinitializeFreetype(ft);
|
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
|
int channels) const
|
||||||
{
|
{
|
||||||
stbi_flip_vertically_on_write(1);
|
stbi_flip_vertically_on_write(1);
|
||||||
|
|||||||
@@ -8,48 +8,49 @@
|
|||||||
|
|
||||||
#if __has_include("msdfgen.h")
|
#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 <string>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include "Scene/AtlasMetadata.hpp"
|
#define MSDFGEN_AVAILABLE 1
|
||||||
#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
|
|
||||||
|
|
||||||
namespace OpenVulkano::Scene
|
namespace OpenVulkano::Scene
|
||||||
{
|
{
|
||||||
using namespace msdfgen;
|
|
||||||
using namespace msdf_atlas;
|
|
||||||
using namespace OpenVulkano::Scene;
|
|
||||||
|
|
||||||
class MsdfFontAtlasGenerator : public FontAtlasGenerator
|
class MsdfFontAtlasGenerator : public FontAtlasGenerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using SdfGenerator = ImmediateAtlasGenerator<float, 1, sdfGenerator, BitmapAtlasStorage<msdfgen::byte, 1>>;
|
using SdfGenerator = msdf_atlas::ImmediateAtlasGenerator<float, 1, msdf_atlas::sdfGenerator,
|
||||||
static Charset LoadAllGlyphs(const std::variant<std::string, Array<char>>& data);
|
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,
|
void GenerateAtlas(const std::string& fontFile, const std::set<uint32_t>& charset,
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt) override;
|
const std::optional<std::string>& pngOutput = std::nullopt) override;
|
||||||
void GenerateAtlas(const Array<char>& fontData, int length, const std::set<uint32_t>& charset,
|
void GenerateAtlas(const Array<char>& fontData, int length, const std::set<uint32_t>& charset,
|
||||||
const std::optional<std::string>& pngOutput = std::nullopt) override;
|
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);
|
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);
|
const std::optional<std::string>& pngOutput = std::nullopt);
|
||||||
void SaveAtlasMetadataInfo(const std::string& outputFile, bool packIntoSingleFile = true) const override;
|
void SaveAtlasMetadataInfo(const std::string& outputFile, bool packIntoSingleFile = true) const override;
|
||||||
const Texture& GetAtlas() const override { return m_atlasTex; }
|
const Texture& GetAtlas() const override { return m_atlasTex; }
|
||||||
std::map<uint32_t, GlyphInfo>& GetGlyphsInfo() override { return m_symbols; }
|
std::map<uint32_t, GlyphInfo>& GetGlyphsInfo() override { return m_symbols; }
|
||||||
AtlasMetadata& GetAtlasMetadata() override { return m_meta; }
|
AtlasMetadata& GetAtlasMetadata() override { return m_meta; }
|
||||||
SdfGenerator& GetFontAtlasGenerator() { return m_generator; }
|
SdfGenerator& GetFontAtlasGenerator() { return m_generator; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InitFreetypeFromFile(FreetypeHandle*& ft, FontHandle*& font, const std::string& file);
|
void InitFreetypeFromFile(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font, const std::string& file);
|
||||||
void InitFreetypeFromBuffer(FreetypeHandle*& ft, FontHandle*& font, const msdfgen::byte* fontData, int length);
|
void InitFreetypeFromBuffer(msdfgen::FreetypeHandle*& ft, msdfgen::FontHandle*& font,
|
||||||
void Generate(FreetypeHandle* ft, FontHandle* font, const Charset& chset,
|
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);
|
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:
|
private:
|
||||||
SdfGenerator m_generator;
|
SdfGenerator m_generator;
|
||||||
Texture m_atlasTex;
|
Texture m_atlasTex;
|
||||||
|
|||||||
@@ -12,9 +12,11 @@
|
|||||||
#include "Scene/FontAtlasGenerator.hpp"
|
#include "Scene/FontAtlasGenerator.hpp"
|
||||||
#include "Base/Logger.hpp"
|
#include "Base/Logger.hpp"
|
||||||
#include "Host/ResourceLoader.hpp"
|
#include "Host/ResourceLoader.hpp"
|
||||||
|
#include "Image/ImageLoader.hpp"
|
||||||
|
#include "DataFormat.hpp"
|
||||||
|
#include "Base/Logger.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <utf8.h>
|
#include <utf8.h>
|
||||||
#include "Image/ImageLoader.hpp"
|
|
||||||
|
|
||||||
namespace OpenVulkano::Scene
|
namespace OpenVulkano::Scene
|
||||||
{
|
{
|
||||||
@@ -210,4 +212,14 @@ namespace OpenVulkano::Scene
|
|||||||
}
|
}
|
||||||
SimpleDrawable::Init(m_shader, &m_geometry, &m_material, &m_uniBuffer);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,24 +6,20 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "UpdateFrequency.hpp"
|
|
||||||
#include "Base/ICloseable.hpp"
|
|
||||||
#include "Math/Math.hpp"
|
|
||||||
#include "DataFormat.hpp"
|
|
||||||
#include "SimpleDrawable.hpp"
|
#include "SimpleDrawable.hpp"
|
||||||
#include "FontAtlasGenerator.hpp"
|
|
||||||
#include "Texture.hpp"
|
#include "Texture.hpp"
|
||||||
#include "Material.hpp"
|
#include "Material.hpp"
|
||||||
#include "Geometry.hpp"
|
#include "Geometry.hpp"
|
||||||
#include "UniformBuffer.hpp"
|
#include "UniformBuffer.hpp"
|
||||||
#include "Base/Logger.hpp"
|
|
||||||
#include "AtlasMetadata.hpp"
|
#include "AtlasMetadata.hpp"
|
||||||
#include "Image/Image.hpp"
|
#include "Image/Image.hpp"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "FontAtlasGenerator.hpp"
|
|
||||||
|
|
||||||
namespace OpenVulkano::Scene
|
namespace OpenVulkano::Scene
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class FontAtlasGenerator;
|
||||||
|
|
||||||
struct TextConfig
|
struct TextConfig
|
||||||
{
|
{
|
||||||
Math::Vector4f textColor = { 1, 1, 1, 1 };
|
Math::Vector4f textColor = { 1, 1, 1, 1 };
|
||||||
@@ -51,15 +47,7 @@ namespace OpenVulkano::Scene
|
|||||||
void SetShader(Shader* shader) { m_shader = shader; }
|
void SetShader(Shader* shader) { m_shader = shader; }
|
||||||
TextConfig& GetConfig() { return m_cfg; }
|
TextConfig& GetConfig() { return m_cfg; }
|
||||||
Shader* GetShader() { return m_shader; }
|
Shader* GetShader() { return m_shader; }
|
||||||
void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator)
|
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;
|
|
||||||
}
|
|
||||||
FontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
|
FontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
|
||||||
private:
|
private:
|
||||||
Geometry m_geometry;
|
Geometry m_geometry;
|
||||||
|
|||||||
Reference in New Issue
Block a user