summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-13 08:05:24 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-13 08:05:24 +0100
commitf1649953a4c24075389237416d10dc513d21da14 (patch)
treef810c9e628af68c79c399d7163970d8315fcf10e /src
parent22590b99e826b6ad16303d39b47f4925e9e45c22 (diff)
meshing
Diffstat (limited to 'src')
-rw-r--r--src/text.cc44
-rw-r--r--src/text.h11
2 files changed, 55 insertions, 0 deletions
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;
+}
diff --git a/src/text.h b/src/text.h
index 5b578d0..8840c85 100644
--- a/src/text.h
+++ b/src/text.h
@@ -71,3 +71,14 @@ enum font_error_e wayc_font_raster_text(struct font_s* font, const char* text,
usize max_glyphs);
void wayc_font_deinit(struct font_s* font);
+
+struct text_mesh_s {
+ struct text_vertex_s* vertices;
+ usize vertex_count;
+ u16* indices;
+ usize index_count;
+};
+
+bool wayc_text_mesh_init(struct text_mesh_s* mesh, const char* text,
+ usize text_len, struct font_s* font);
+void wayc_text_mesh_deinit(struct text_mesh_s* mesh);