67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "SimpleDrawable.hpp"
|
|
#include "Texture.hpp"
|
|
#include "Material.hpp"
|
|
#include "Geometry.hpp"
|
|
#include "UniformBuffer.hpp"
|
|
#include "AtlasMetadata.hpp"
|
|
#include "Image/Image.hpp"
|
|
#include <map>
|
|
#include <optional>
|
|
|
|
namespace OpenVulkano::Scene
|
|
{
|
|
|
|
class IFontAtlasGenerator;
|
|
|
|
struct TextConfig
|
|
{
|
|
Math::Vector4f textColor = { 1, 1, 1, 1 };
|
|
Math::Vector4f borderColor = { 1, 0, 0, 1 };
|
|
Math::Vector4f backgroundColor = { 0, 1, 0, 0 };
|
|
float threshold = 0.4f;
|
|
float borderSize = 0.05f;
|
|
float smoothing = 1.f/32.f;
|
|
uint32_t applyBorder = false;
|
|
//bool sdfMultiChannel = false;
|
|
};
|
|
|
|
class TextDrawable : public SimpleDrawable
|
|
{
|
|
public:
|
|
static Shader& GetSdfDefaultShader();
|
|
static Shader& GetMsdfDefaultShader();
|
|
TextDrawable(const Array<char>& atlasMetadata, const TextConfig& config = TextConfig());
|
|
TextDrawable(const std::string& atlasMetadataFile, const TextConfig& config = TextConfig());
|
|
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());
|
|
TextDrawable(IFontAtlasGenerator* 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; }
|
|
Shader* GetShader() { return m_shader; }
|
|
void SetFontAtlasGenerator(IFontAtlasGenerator* fontAtlasGenerator);
|
|
IFontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
|
|
private:
|
|
Geometry m_geometry;
|
|
Material m_material;
|
|
UniformBuffer m_uniBuffer;
|
|
std::map<uint32_t, GlyphInfo> m_glyphs;
|
|
AtlasMetadata m_meta;
|
|
std::unique_ptr<Image::Image> m_img;
|
|
std::optional<Texture> m_texture;
|
|
IFontAtlasGenerator* m_fontAtlasGenerator = nullptr;
|
|
Shader* m_shader = nullptr;
|
|
TextConfig m_cfg;
|
|
};
|
|
}
|