75 lines
1.6 KiB
C++
75 lines
1.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 "Base/Wrapper.hpp"
|
|
#include "Math/Math.hpp"
|
|
#include "Image/Image.hpp"
|
|
#include "Scene/Texture.hpp"
|
|
#include <string_view>
|
|
#include <map>
|
|
#include <magic_enum.hpp>
|
|
|
|
namespace OpenVulkano::Scene
|
|
{
|
|
struct GlyphInfo
|
|
{
|
|
//GlyphGeometry geometry;
|
|
//GlyphBox glyphBox;
|
|
Math::Vector2f_SIMD pos[4] = {};
|
|
Math::Vector2f_SIMD uv[4] = {};
|
|
double advance = 0;
|
|
};
|
|
|
|
class FontAtlasType
|
|
{
|
|
public:
|
|
enum Type : int16_t
|
|
{
|
|
SDF = 0,
|
|
MSDF,
|
|
BITMAP,
|
|
UNKNOWN
|
|
};
|
|
|
|
static constexpr std::string_view DEFAULT_FG_SHADERS[] = { "Shader/sdfText", "Shader/msdfText", "Shader/text" };
|
|
|
|
constexpr FontAtlasType(Type type) : m_type(type) {}
|
|
|
|
[[nodiscard]] constexpr Type GetType() const { return m_type; }
|
|
|
|
[[nodiscard]] constexpr auto GetName() const { return magic_enum::enum_name(m_type); }
|
|
|
|
[[nodiscard]] constexpr const std::string_view& GetDefaultFragmentShader() const
|
|
{
|
|
return DEFAULT_FG_SHADERS[static_cast<int>(m_type)];
|
|
}
|
|
|
|
[[nodiscard]] constexpr operator Type() const { return m_type; }
|
|
|
|
private:
|
|
Type m_type;
|
|
};
|
|
|
|
struct AtlasMetadata
|
|
{
|
|
// vertical difference between baselines
|
|
double lineHeight = 0;
|
|
FontAtlasType atlasType = FontAtlasType::UNKNOWN;
|
|
};
|
|
|
|
struct AtlasData
|
|
{
|
|
std::map<uint32_t, GlyphInfo> glyphs;
|
|
AtlasMetadata meta;
|
|
Unique<Image::Image> img;
|
|
Texture texture;
|
|
|
|
operator bool() const { return !glyphs.empty() && texture.textureBuffer; }
|
|
};
|
|
|
|
} |