From 4b44d3420637076ce225c2633019f25b75bc62a1 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Fri, 20 Feb 2026 06:30:47 +0100 Subject: improving rasterization --- src/text.cc | 49 +++++++++++++------------------------------------ src/text.h | 6 +----- 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/src/text.cc b/src/text.cc index 36d842e..b76bab2 100644 --- a/src/text.cc +++ b/src/text.cc @@ -13,7 +13,8 @@ #include "shaders.h" #include "utils.h" -// Linear filtering for smooth glyph rendering, clamped UVs to prevent atlas bleeding +// Linear filtering for smooth glyph rendering, clamped UVs to prevent atlas +// bleeding static void wayc_font_context_sampler_desc(struct sg_sampler_desc* desc) { wayc_notnull(desc); @@ -219,28 +220,6 @@ enum font_error_e wayc_font_raster(struct font_s* font, codepoint_t codepoint, return FONT_ERROR_NONE; } -enum font_error_e wayc_font_raster_text(struct font_s* font, const char* text, - usize text_len, struct glyph_s* glyphs, - usize max_glyphs) { - wayc_notnull(font); - wayc_notnull(text); - wayc_notnull(glyphs); - memset(glyphs, 0, sizeof(*glyphs) * max_glyphs); - - usize count = 0; - for (usize i = 0; i < text_len && count < max_glyphs; i++) { - codepoint_t codepoint = (codepoint_t)text[i]; // TODO: handle UTF-8 - - struct glyph_s glyph; - enum font_error_e err = wayc_font_raster(font, codepoint, &glyph); - if (err != FONT_ERROR_NONE) return err; - - glyphs[count++] = glyph; - } - - return FONT_ERROR_NONE; -} - void wayc_font_deinit(struct font_s* font) { wayc_notnull(font); @@ -250,7 +229,7 @@ void wayc_font_deinit(struct font_s* font) { } bool wayc_text_mesh_init(struct text_mesh_s* mesh, const char* text, - usize text_len, struct font_s* font) { + usize text_len, struct font_s* font, vec2 position) { wayc_notnull(mesh); wayc_notnull(text); wayc_notnull(font); @@ -263,7 +242,6 @@ bool wayc_text_mesh_init(struct text_mesh_s* mesh, const char* text, 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); @@ -271,21 +249,20 @@ bool wayc_text_mesh_init(struct text_mesh_s* mesh, const char* text, u16* indices = (u16*)mi_malloc(bytes_indices); wayc_defer_cond(mi_free(indices), success, true); - // Temporary storage for glyph metrics, freed after mesh generation - struct glyph_s* glyphs = (struct glyph_s*)mi_malloc(bytes_glyphs); - wayc_defer(mi_free(glyphs)); - - enum font_error_e err = - wayc_font_raster_text(font, text, text_len, glyphs, text_len); - if (err != FONT_ERROR_NONE) return false; - // Build quads for each character, advancing cursor by glyph width - vec2 cursor = {0.0f, 0.0f}; + vec2 cursor; + glm_vec2_copy(position, cursor); for (usize i = 0; i < text_len; i++) { + codepoint_t codepoint = (codepoint_t)text[i]; // TODO: handle UTF-8 + + struct glyph_s glyph; + enum font_error_e err = wayc_font_raster(font, codepoint, &glyph); + if (err != FONT_ERROR_NONE) return false; + u16 base = (u16)(i * WAYC_QUAD_NVERTS); - wayc_text_quad(verts, &indices[i * WAYC_QUAD_NINDICES], base, &glyphs[i], + wayc_text_quad(verts, &indices[i * WAYC_QUAD_NINDICES], base, &glyph, cursor); - WAYC_X(cursor) += glyphs[i].advance; + WAYC_X(cursor) += glyph.advance; } mesh->vertices = verts; diff --git a/src/text.h b/src/text.h index 8522c93..aed11ed 100644 --- a/src/text.h +++ b/src/text.h @@ -67,10 +67,6 @@ static inline enum font_error_e wayc_font_flush(struct font_s* font) { return (enum font_error_e)wayc_max(atlas_err, FONT_ERROR_NONE); } -enum font_error_e wayc_font_raster_text(struct font_s* font, const char* text, - usize text_len, struct glyph_s* glyphs, - usize max_glyphs); - void wayc_font_deinit(struct font_s* font); struct text_mesh_s { @@ -81,5 +77,5 @@ struct text_mesh_s { }; bool wayc_text_mesh_init(struct text_mesh_s* mesh, const char* text, - usize text_len, struct font_s* font); + usize text_len, struct font_s* font, vec2 position); void wayc_text_mesh_deinit(struct text_mesh_s* mesh); -- cgit v1.2.3