From 11dc980a40b4743b52ad4d88d91659e0cd413794 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Thu, 12 Feb 2026 00:09:56 +0100 Subject: this drives me crazy --- src/text.cc | 64 +++++++++++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 36 deletions(-) (limited to 'src/text.cc') diff --git a/src/text.cc b/src/text.cc index 4306f91..ab812c2 100644 --- a/src/text.cc +++ b/src/text.cc @@ -128,54 +128,46 @@ void wayc_font_deinit(struct font_s* font) { mi_free(font->data); } -enum text_error_e wayc_text_vertices(struct text_s* text, - struct text_vertex_s** out) { +enum text_error_e wayc_text_assemble(struct text_s* text, usize* out_size, + text_index_t** out_indices, + struct text_vertex_s** out_verts) { wayc_notnull(text); - wayc_notnull(out); + wayc_notnull(out_size); + wayc_notnull(out_indices); + wayc_notnull(out_verts); bool success = false; - usize nverts = WAYC_LETTER_NVERTICES * wayc_string_length(&text->string); - usize verts_bytes = nverts * sizeof(struct text_vertex_s); + usize glyph_count = wayc_string_length(&text->string); + + usize vertex_count = glyph_count * WAYC_LETTER_NVERTICES; + usize index_count = + glyph_count * WAYC_LETTER_NTRIANGLES * WAYC_TRIANGLE_NINDICES; - struct text_vertex_s* verts = (struct text_vertex_s*)mi_malloc(verts_bytes); - wayc_defer_cond(mi_free(verts), success, true); + usize vertex_bytes = vertex_count * sizeof(struct text_vertex_s); + usize index_bytes = index_count * sizeof(text_index_t); - vec2 pen = GLM_VEC2_ZERO_INIT; - usize idx = 0; - for (usize i = 0; i < wayc_string_length(&text->string); i++) { - codepoint_t codep = - wayc_string_data(&text->string)[i]; // TODO: do proper UTF-8 decoding + struct text_vertex_s* vertices = + (struct text_vertex_s*)mi_malloc(vertex_bytes); + wayc_defer_cond(mi_free(vertices), success, true); + text_index_t* indices = (text_index_t*)mi_malloc(index_bytes); + wayc_defer_cond(mi_free(indices), success, true); + + for (usize i = 0; i < glyph_count; i++) { + codepoint_t codepoint = text->string.data[i]; struct glyph_s glyph; - enum font_error_e err = - wayc_font_lookup(text->font, text->atlas, text->packer, codep, &glyph); + enum font_error_e err = wayc_font_lookup(text->font, text->atlas, + text->packer, codepoint, &glyph); if (err != FONT_ERROR_NONE) return TEXT_ERROR_ATLAS; - f32 x0 = WAYC_X(pen) + glyph.bearing_x; - f32 y0 = WAYC_Y(pen) - glyph.bearing_y; - f32 x1 = x0 + WAYC_X(glyph.uv1) - WAYC_X(glyph.uv0); - f32 y1 = y0 + WAYC_Y(glyph.uv1) - WAYC_Y(glyph.uv0); - - f32 u0 = (f32)WAYC_X(glyph.uv0) / text->atlas->width; - f32 v0 = (f32)WAYC_Y(glyph.uv0) / text->atlas->height; - f32 u1 = (f32)WAYC_X(glyph.uv1) / text->atlas->width; - f32 v1 = (f32)WAYC_Y(glyph.uv1) / text->atlas->height; - - struct text_vertex_s ps0 = {{x0, y0}, {u0, v0}}; - struct text_vertex_s ps1 = {{x0, y1}, {u0, v1}}; - struct text_vertex_s ps2 = {{x1, y1}, {u1, v1}}; - struct text_vertex_s ps3 = {{x1, y0}, {u1, v0}}; - - verts[idx++] = ps0; - verts[idx++] = ps1; - verts[idx++] = ps2; - verts[idx++] = ps0; - verts[idx++] = ps2; - verts[idx++] = ps3; + wayc_panic("unimplemented"); } + *out_size = index_bytes; + *out_indices = indices; + *out_verts = vertices; + success = true; - *out = verts; return TEXT_ERROR_NONE; } \ No newline at end of file -- cgit v1.2.3