1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#ifndef PKE_FONT_TYPE_HPP
#define PKE_FONT_TYPE_HPP
#include "asset-manager.hpp"
#include "components.hpp"
#include "pk.h"
#include "vendor-glm-include.hpp"
#define PKE_FONT_MAX_FONT_TYPES 64
struct FontTypeHandle : pk_bkt_arr_handle {};
struct FontRenderHandle : pk_bkt_arr_handle {};
constexpr FontTypeHandle FontTypeHandle_MAX = FontTypeHandle{ pk_bkt_arr_handle_MAX_constexpr };
constexpr FontRenderHandle FontRenderHandle_MAX = FontRenderHandle{ pk_bkt_arr_handle_MAX_constexpr };
TypeSafeInt_H(FONT_GLYPH_CHAR_FLAG, uint8_t, 0xFF);
TypeSafeInt_H(FONT_RENDER_FLAG, uint8_t, 0xFF);
TypeSafeInt_H(FONT_RENDER_SURFACE_AREA_TYPE_FLAG, uint8_t, 0xFF);
const FONT_GLYPH_CHAR_FLAG FONT_GLYPH_CHAR_FLAGS_NONE
= FONT_GLYPH_CHAR_FLAG(0u);
const FONT_GLYPH_CHAR_FLAG FONT_GLYPH_CHAR_FLAGS_CONTROL
= FONT_GLYPH_CHAR_FLAG((1u << 0));
const FONT_GLYPH_CHAR_FLAG FONT_GLYPH_CHAR_FLAGS_WHITESPACE
= FONT_GLYPH_CHAR_FLAG((1u << 1));
const FONT_GLYPH_CHAR_FLAG FONT_GLYPH_CHAR_FLAGS_ALIGN_ADVANCE
= FONT_GLYPH_CHAR_FLAG((1u << 2));
const FONT_GLYPH_CHAR_FLAG FONT_GLYPH_CHAR_FLAGS_NEW_LINE
= FONT_GLYPH_CHAR_FLAG((1u << 3));
const FONT_RENDER_FLAG FONT_RENDER_FLAG_NONE = FONT_RENDER_FLAG(0u << 0);
const FONT_RENDER_FLAG FONT_RENDER_FLAG_VISIBILITY_INVISIBLE = FONT_RENDER_FLAG(1u << 0);
const FONT_RENDER_SURFACE_AREA_TYPE_FLAG FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_NONE
= FONT_RENDER_SURFACE_AREA_TYPE_FLAG(0u);
const FONT_RENDER_SURFACE_AREA_TYPE_FLAG FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_CENTER_VERTICAL
= FONT_RENDER_SURFACE_AREA_TYPE_FLAG((1u << 0));
const FONT_RENDER_SURFACE_AREA_TYPE_FLAG FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_CENTER_HORIZONTAL
= FONT_RENDER_SURFACE_AREA_TYPE_FLAG((1u << 1));
const FONT_RENDER_SURFACE_AREA_TYPE_FLAG FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_CENTER_BOTH
= FONT_RENDER_SURFACE_AREA_TYPE_FLAG((1u << 0) | (1u << 1));
struct FontTypeRender {
FontTypeHandle font_type_handle;
FontRenderHandle font_render_handle;
};
constexpr FontTypeRender FontTypeRender_MAX = {
.font_type_handle = FontTypeHandle_MAX,
.font_render_handle = FontRenderHandle_MAX,
};
struct FontGlyphChar {
double advance;
glm::vec2 sprite_region_min;
glm::vec2 sprite_region_max;
glm::dvec4 plane_bounds;
uint32_t unicode;
FONT_GLYPH_CHAR_FLAG flags;
};
struct FontRenderSettings {
glm::vec4 color_foreground = glm::vec4(0.4, 0.9, 0.5, 0.8);
glm::vec4 color_background = glm::vec4(0.0, 0.0, 0.0, 0.0);
float char_scale = 1.f;
float line_height_scale = 1.f;
float char_spacing_scale = 1.f;
glm::ivec2 surface_area_size;
glm::ivec2 surface_area_pos;
FONT_RENDER_FLAG flags;
FONT_RENDER_SURFACE_AREA_TYPE_FLAG surface_area_type_flags;
};
struct FontRender : public Entity_Base {
uint32_t *glyph_indices = nullptr;
FontTypeHandle font_type_handle = FontTypeHandle_MAX;
FontRenderHandle font_render_handle = FontRenderHandle_MAX;
uint32_t n_glyphs = 0;
uint32_t buffer_start_index = 0;
FontRenderSettings settings{};
pk_cstr text{};
};
struct FontTypeMSDFSettings {
float minimum_scale = 0.f;
float px_range = 0.f;
};
struct FontTypeSpacing {
double geometry_scale = 0.f;
double em_size = 0.f;
double ascender_y = 0.f;
double descender_y = 0.f;
double line_height = 0.f;
double underline_y = 0.f;
double underline_thickness = 0.f;
};
struct FontType : public Entity_Base {
pk_cstr title{};
AssetHandle fontTextureAssetHandle = AssetHandle_MAX;
AssetHandle glyphDetailsAssetHandle = AssetHandle_MAX;
FontGlyphChar *glyphs = nullptr;
glm::vec2 atlas_size = glm::vec2(0,0);
uint32_t n_glyphs = 0;
pk_bkt_arr_t<FontRender> renders{};
FontTypeHandle font_type_handle = FontTypeHandle_MAX;
struct FontTypeMSDFSettings msdf_settings{};
struct FontTypeSpacing spacing{};
struct FontTypeGraphics {
VkDeviceMemory deviceMemoryVert = VK_NULL_HANDLE;
VkDeviceMemory deviceMemoryTexture = VK_NULL_HANDLE;
VkDeviceMemory deviceMemoryInst = VK_NULL_HANDLE;
VkImage textureImage = VK_NULL_HANDLE;
VkImageView textureImageView = VK_NULL_HANDLE;
VkDescriptorPool vkDescriptorPool = VK_NULL_HANDLE;
VkDescriptorSet vkDescriptorSet = VK_NULL_HANDLE;
bool should_update_instance_buffer = false;
} gr;
struct FontTypeBindings {
BufferBindingDetails bd_vertex{};
BufferBindingDetails bd_uv{};
BufferBindingDetails bd_atlas_size{};
BufferBindingDetails bd_index{};
BufferBindingDetails bd_instance{};
uint32_t index_count = 0;
uint32_t instance_counter = 0;
uint32_t instance_buffer_max_count = 0;
} bindings;
};
void FontType_Init();
void FontType_Teardown();
void FontType_Tick(double delta);
void FontType_Serialize(std::ostream &stream, FontType *ft);
void FontType_Deserialize(std::istream &stream);
FontType* FontType_Get(FontTypeHandle font_type_handle);
FontType* FontType_GetByTitle(const pk_cstr title);
pk_bkt_arr* FontType_GetFonts();
FontTypeHandle FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle, AssetHandle glyphsHandle, FontTypeMSDFSettings *msdf_settings, FontTypeSpacing *spacing);
FontTypeRender FontType_AddStringRender(FontTypeHandle font_type_handle, const pk_cstr &&str, FontRenderSettings *settings, Entity_Base *parent = nullptr, pk_uuid uuid = pk_uuid_zed);
FontRender *FontType_GetFontRender(FontTypeRender ftr);
void FontType_UpdateStringRender(FontTypeRender ftr, FontRenderSettings *settings);
void FontType_UpdateStringRenderText(FontTypeRender ftr, pk_cstr &&cstr);
void FontType_RemoveStringRender(FontTypeRender ftr);
#endif /* PKE_FONT_TYPE_HPP */
|