implement text rendering without msdfgen library

This commit is contained in:
ohyzha
2024-08-05 18:25:19 +03:00
parent 62a0e84634
commit afccf5dee0
10 changed files with 302 additions and 150 deletions

View File

@@ -17,14 +17,20 @@
#include "Geometry.hpp"
#include "UniformBuffer.hpp"
#include "Base/Logger.hpp"
#include "msdfgen.h"
#include "msdfgen-ext.h"
#include "msdf-atlas-gen/msdf-atlas-gen.h"
#include "AtlasMetadata.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
namespace OpenVulkano::Scene
{
#ifdef MSDFGEN_AVAILABLE
using namespace msdfgen;
using namespace msdf_atlas;
#endif // MSDFGEN_AVAILABLE
struct TextConfig
{
@@ -42,12 +48,18 @@ namespace OpenVulkano::Scene
{
public:
static Shader& GetDefaultShader();
static std::map<uint32_t, GlyphInfo> ReadAtlasMetadataFile(const std::string& atlasMetadataFile);
static std::map<uint32_t, GlyphInfo> ReadAtlasMetadata(const Array<char>& atlasMetadata);
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->GetAtlasInfo().empty())
@@ -56,14 +68,17 @@ namespace OpenVulkano::Scene
return;
}
m_fontAtlasGenerator = fontAtlasGenerator;
m_material.texture = const_cast<Texture*>(&m_fontAtlasGenerator->GetAtlas());
}
FontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
#endif
private:
Geometry m_geometry;
Material m_material;
UniformBuffer m_uniBuffer;
std::map<uint32_t, GlyphInfo> m_glyphs;
#ifdef MSDFGEN_AVAILABLE
FontAtlasGenerator* m_fontAtlasGenerator = nullptr;
#endif
Shader* m_shader = &GetDefaultShader();
TextConfig m_cfg;
};