Files
OpenVulkano/openVulkanoCpp/Scene/TextDrawable.hpp
2025-01-04 21:16:08 +01:00

61 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 "Drawable.hpp"
#include "Texture.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 backgroundColor = { 0, 1, 0, 0 };
float threshold = 0.4f;
float smoothing = 1.f/32.f;
};
class TextDrawable : public Drawable
{
Geometry m_geometry;
UniformBuffer m_uniBuffer;
std::shared_ptr<AtlasData> m_atlasData;
Math::AABB m_bbox;
std::string m_text;
TextConfig m_cfg;
uint32_t GetFallbackGlyph() const;
public:
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());
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>& 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<AtlasData>& GetAtlasData() { return m_atlasData; }
[[nodiscard]] Geometry* GetGeometry() { return &m_geometry; }
[[nodiscard]] Texture* GetTexture() { return &m_atlasData->texture; }
[[nodiscard]] UniformBuffer* GetUniformBuffer() { return &m_uniBuffer; }
[[nodiscard]] static Shader* GetDefaultShader(FontAtlasType type);
};
}