/* * 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 "AtlasData.hpp" #include "Image/Image.hpp" 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 { static Shader DEFAULT_SHADER_BITMAP, DEFAULT_SHADER_SDF, DEFAULT_SHADER_MSDF; public: [[nodiscard]] static Shader& GetSdfDefaultShader() { return DEFAULT_SHADER_SDF; } [[nodiscard]] static Shader& GetMsdfDefaultShader() { return DEFAULT_SHADER_MSDF; } [[nodiscard]] static Shader& GetBitmapDefaultShader() { return DEFAULT_SHADER_BITMAP; } TextDrawable(const TextConfig& config = TextConfig()); TextDrawable(const Array& 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& atlasMetadata, Texture* atlasTex, const TextConfig& config = TextConfig()); TextDrawable(const std::shared_ptr& atlasData, 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 SetAtlasData(const std::shared_ptr& atlasData); [[nodiscard]] Math::AABB& GetBoundingBox() { return m_bbox; } [[nodiscard]] TextConfig& GetConfig() { return m_cfg; } [[nodiscard]] const std::string& GetText() const { return m_text; } [[nodiscard]] const std::shared_ptr GetAtlasData() { return m_atlasData; } private: Geometry m_geometry; Material m_material; UniformBuffer m_uniBuffer; std::shared_ptr m_atlasData; Math::AABB m_bbox; std::string m_text; TextConfig m_cfg; }; }