rework API for text rendering

This commit is contained in:
ohyzha
2024-08-04 00:10:59 +03:00
parent dcf6e72f96
commit 232ad0a938
8 changed files with 122 additions and 129 deletions

View File

@@ -13,6 +13,10 @@
#include "SimpleDrawable.hpp"
#include "FontAtlasGenerator.hpp"
#include "Texture.hpp"
#include "Material.hpp"
#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"
@@ -37,16 +41,30 @@ namespace OpenVulkano::Scene
class TextDrawable : public SimpleDrawable
{
public:
TextDrawable() = default;
~TextDrawable();
void SetUniformBuffer(UniformBuffer* buffer) { m_uniBuffer = buffer; }
static Shader& GetDefaultShader();
TextDrawable(FontAtlasGenerator* fontAtlasGenerator, const TextConfig& config = TextConfig());
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; }
void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator) { m_fontAtlasGenerator = fontAtlasGenerator; }
Shader* GetShader() { return m_shader; }
void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator)
{
if (!fontAtlasGenerator || fontAtlasGenerator->GetAtlasInfo().empty())
{
Logger::RENDER->error("FontAtlasGenerator is either nullptr or doesn't contain glyphs info");
return;
}
m_fontAtlasGenerator = fontAtlasGenerator;
m_material.texture = const_cast<Texture*>(&m_fontAtlasGenerator->GetAtlas());
}
FontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
private:
Geometry m_geometry;
Material m_material;
UniformBuffer m_uniBuffer;
FontAtlasGenerator* m_fontAtlasGenerator = nullptr;
Shader* m_shader = &GetDefaultShader();
TextConfig m_cfg;
};
}