split font atlas generator to interface and implementation

This commit is contained in:
ohyzha
2024-08-07 20:05:06 +03:00
parent 634b4431b3
commit 38d97f4c28
6 changed files with 160 additions and 101 deletions

View File

@@ -19,20 +19,11 @@
#include "Base/Logger.hpp"
#include "AtlasMetadata.hpp"
#include "Image/Image.hpp"
#if __has_include("msdfgen.h")
#include "msdfgen.h"
#include "msdfgen-ext.h"
#include "msdf-atlas-gen/msdf-atlas-gen.h"
#define MSDFGEN_AVAILABLE 1
#endif
#include <map>
#include "FontAtlasGenerator.hpp"
namespace OpenVulkano::Scene
{
#ifdef MSDFGEN_AVAILABLE
using namespace msdfgen;
using namespace msdf_atlas;
#endif // MSDFGEN_AVAILABLE
struct TextConfig
{
Math::Vector4f textColor = { 1, 1, 1, 1 };
@@ -54,15 +45,12 @@ namespace OpenVulkano::Scene
TextDrawable(const std::string& atlasMetadataFile, Texture* atlasTex, const TextConfig& config = TextConfig());
TextDrawable(const Array<char>& atlasMetadata, Texture* atlasTex, const TextConfig& config = TextConfig());
TextDrawable(const std::map<uint32_t, GlyphInfo>& glyphData, Texture* atlasTex, const TextConfig& config = TextConfig());
#ifdef MSDFGEN_AVAILABLE
TextDrawable(FontAtlasGenerator* fontAtlasGenerator, const TextConfig& config = TextConfig());
#endif
void GenerateText(const std::string& text, const Math::Vector3f& pos = Math::Vector3f(0.f));
void SetConfig(const TextConfig& cfg) { m_cfg = cfg; }
void SetShader(Shader* shader) { m_shader = shader; }
TextConfig& GetConfig() { return m_cfg; }
Shader* GetShader() { return m_shader; }
#ifdef MSDFGEN_AVAILABLE
void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator)
{
if (!fontAtlasGenerator || fontAtlasGenerator->GetGlyphsInfo().empty())
@@ -73,7 +61,6 @@ namespace OpenVulkano::Scene
m_fontAtlasGenerator = fontAtlasGenerator;
}
FontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
#endif
private:
Geometry m_geometry;
Material m_material;
@@ -81,9 +68,7 @@ namespace OpenVulkano::Scene
std::map<uint32_t, GlyphInfo> m_glyphs;
AtlasMetadata m_meta;
std::unique_ptr<Image::Image> m_img;
#ifdef MSDFGEN_AVAILABLE
FontAtlasGenerator* m_fontAtlasGenerator = nullptr;
#endif
Shader* m_shader = &GetDefaultShader();
TextConfig m_cfg;
};