diff options
Diffstat (limited to 'src/font.hpp')
| -rw-r--r-- | src/font.hpp | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/src/font.hpp b/src/font.hpp index cdbc309..001745b 100644 --- a/src/font.hpp +++ b/src/font.hpp @@ -9,9 +9,10 @@ #define PKE_FONT_MAX_FONT_TYPES 64 -TypeSafeInt_H(FontTypeIndex, uint16_t, 0xFFFF); +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); @@ -42,13 +43,13 @@ const FONT_RENDER_SURFACE_AREA_TYPE_FLAG FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_CEN = FONT_RENDER_SURFACE_AREA_TYPE_FLAG((1u << 0) | (1u << 1)); struct FontTypeRender { - FontTypeIndex index_ft; - FontRenderHandle handle_fr; + FontTypeHandle font_type_handle; + FontRenderHandle font_render_handle; }; constexpr FontTypeRender FontTypeRender_MAX = { - .index_ft = FontTypeIndex_MAX, - .handle_fr = { pk_bkt_arr_handle_MAX }, + .font_type_handle = FontTypeHandle_MAX, + .font_render_handle = FontRenderHandle_MAX, }; struct FontGlyphChar { @@ -72,37 +73,37 @@ struct FontRenderSettings { }; struct FontRender : public Entity_Base { uint32_t *glyph_indices = nullptr; - FontTypeIndex index_ft = FontTypeIndex{0}; - FontRenderHandle fr_handle = FontRenderHandle_MAX; + 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; - float px_range; + float minimum_scale = 0.f; + float px_range = 0.f; }; struct FontTypeSpacing { - double geometry_scale; - double em_size; - double ascender_y; - double descender_y; - double line_height; - double underline_y; - double underline_thickness; + 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 glyphDetailsAssetHandle; - FontGlyphChar *glyphs; - glm::vec2 atlas_size; - uint32_t n_glyphs; - pk_bkt_arr_t<FontRender> renders; - FontTypeIndex index_ft = FontTypeIndex{0}; - struct FontTypeMSDFSettings msdf_settings; - struct FontTypeSpacing spacing; + 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; @@ -111,14 +112,14 @@ struct FontType : public Entity_Base { VkImageView textureImageView = VK_NULL_HANDLE; VkDescriptorPool vkDescriptorPool = VK_NULL_HANDLE; VkDescriptorSet vkDescriptorSet = VK_NULL_HANDLE; - bool should_update_instance_buffer; + 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; + 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; @@ -130,14 +131,14 @@ 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(FontTypeIndex idx); +FontType* FontType_Get(FontTypeHandle font_type_handle); FontType* FontType_GetByTitle(const pk_cstr title); -FontType* FontType_GetFonts(uint64_t &idx_unused); -FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle, AssetHandle glyphsHandle, FontTypeMSDFSettings *msdf_settings, FontTypeSpacing *spacing); -FontTypeRender FontType_AddStringRender(FontTypeIndex idx_ft, const pk_cstr &&str, FontRenderSettings *settings, Entity_Base *parent = nullptr, pk_uuid uuid = pk_uuid_zed); -FontRender *FontType_GetFontRender(FontTypeRender frh); -void FontType_UpdateStringRender(FontTypeRender frh, FontRenderSettings *settings); -void FontType_UpdateStringRenderText(FontTypeRender frh, pk_cstr &&cstr); -void FontType_RemoveStringRender(FontTypeRender frh); +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 */ |
