diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-20 06:30:47 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-20 06:30:47 +0100 |
| commit | 4b44d3420637076ce225c2633019f25b75bc62a1 (patch) | |
| tree | ff8a43b30ad5a4f1b7f975cd1b2ef67dd8507962 | |
| parent | 027efb4c89e54f88f8a519a773ca803ec258c369 (diff) | |
improving rasterization
| -rw-r--r-- | src/text.cc | 49 | ||||
| -rw-r--r-- | 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; @@ -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); |
