From f1649953a4c24075389237416d10dc513d21da14 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Fri, 13 Feb 2026 08:05:24 +0100 Subject: meshing --- src/text.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/text.cc') diff --git a/src/text.cc b/src/text.cc index fab8cbb..2ad57f3 100644 --- a/src/text.cc +++ b/src/text.cc @@ -236,3 +236,47 @@ void wayc_font_deinit(struct font_s* font) { wayc_atlas_deinit(&font->atlas); FT_Done_Face(font->face); } + +bool wayc_text_mesh_init(struct text_mesh_s* mesh, const char* text, + usize text_len, struct font_s* font) { + wayc_notnull(mesh); + wayc_notnull(text); + wayc_notnull(font); + memset(mesh, 0, sizeof(*mesh)); + + bool success = false; + + usize nverts = text_len * WAYC_QUAD_NVERTS; + usize nindices = text_len * WAYC_QUAD_NINDICES; + + usize bytes_verts = nverts * sizeof(struct text_vertex_s); + usize bytes_indices = nindices * sizeof(u16); + usize bytes_glyphs = text_len * sizeof(struct glyph_s); + + struct text_vertex_s* verts = (struct text_vertex_s*)mi_malloc(bytes_verts); + wayc_defer_cond(mi_free(verts), success, true); + + u16* indices = (u16*)mi_malloc(bytes_indices); + wayc_defer_cond(mi_free(indices), success, true); + + struct glyph_s* glyphs = (struct glyph_s*)mi_malloc(bytes_glyphs); + wayc_defer_cond(mi_free(glyphs), success, true); + + enum font_error_e err = + wayc_font_raster_text(font, text, text_len, glyphs, text_len); + if (err != FONT_ERROR_NONE) return false; + + return true; +} + +void wayc_text_mesh_deinit(struct text_mesh_s* mesh) { + wayc_notnull(mesh); + + if (mesh->vertices == nullptr || mesh->indices == nullptr) return; + + mi_free(mesh->vertices); + mi_free(mesh->indices); + + mesh->vertices = nullptr; + mesh->indices = nullptr; +} -- cgit v1.2.3