Files
OpenVulkano/openVulkanoCpp/Scene/TextDrawable.hpp

77 lines
2.6 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;
};
struct AtlasData
{
std::map<uint32_t, GlyphInfo> glyphs;
AtlasMetadata meta;
std::unique_ptr<Image::Image> img;
Texture texture;
};
class TextDrawable : public SimpleDrawable
{
public:
static Shader& GetSdfDefaultShader();
static Shader& GetMsdfDefaultShader();
TextDrawable(const TextConfig& config = TextConfig());
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::shared_ptr<AtlasData>& atlasData, 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; }
void SetAtlasData(const std::shared_ptr<AtlasData>& atlasData);
Math::AABB& GetBoundingBox() { return m_bbox; }
TextConfig& GetConfig() { return m_cfg; }
Shader* GetShader() { return m_shader; }
std::shared_ptr<AtlasData> GetAtlasData() { return m_atlasData; }
void SetFontAtlasGenerator(IFontAtlasGenerator* fontAtlasGenerator);
IFontAtlasGenerator* GetFontAtlasGenerator() { return m_fontAtlasGenerator; }
private:
Geometry m_geometry;
Material m_material;
UniformBuffer m_uniBuffer;
std::shared_ptr<AtlasData> m_atlasData;
Math::AABB m_bbox;
IFontAtlasGenerator* m_fontAtlasGenerator = nullptr;
Shader* m_shader = nullptr;
TextConfig m_cfg;
};
}