Files
OpenVulkano/openVulkanoCpp/Scene/TextDrawable.hpp
2024-08-07 21:55:58 +03:00

64 lines
2.2 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>
namespace OpenVulkano::Scene
{
class FontAtlasGenerator;
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& GetDefaultShader();
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(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; }
Shader* GetShader() { return m_shader; }
void SetFontAtlasGenerator(FontAtlasGenerator* fontAtlasGenerator);
FontAtlasGenerator* 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;
FontAtlasGenerator* m_fontAtlasGenerator = nullptr;
Shader* m_shader = &GetDefaultShader();
TextConfig m_cfg;
};
}