summaryrefslogtreecommitdiff
path: root/src/text.cc
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-12 00:36:07 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-12 00:36:07 +0100
commitb051cf03148203cb9b03c163693d656a5630b559 (patch)
treea8dc19895cde046ef05d3805992807cbd358bd8c /src/text.cc
parent9124eea8746cd3441245f3194e9d3cb78db4f9db (diff)
fixing block generation
Diffstat (limited to 'src/text.cc')
-rw-r--r--src/text.cc46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/text.cc b/src/text.cc
index 603e6fb..d4bc378 100644
--- a/src/text.cc
+++ b/src/text.cc
@@ -136,7 +136,8 @@ void wayc_font_deinit(struct font_s* font) {
static void wayc_text_assemble_one(const struct glyph_s* glyph, vec2* pen,
f32 atlas_width, f32 atlas_height,
struct text_vertex_s* out_verts,
- text_index_t* out_indices) {
+ text_index_t* out_indices,
+ text_index_t base) {
wayc_notnull(glyph);
wayc_notnull(pen);
wayc_notnull(out_verts);
@@ -155,17 +156,18 @@ static void wayc_text_assemble_one(const struct glyph_s* glyph, vec2* pen,
struct quad_s quad;
wayc_quad_init(&quad, left, top, right, bottom);
- out_verts[0] = text_vertex_s{{left, top}, {uv_left, uv_top}};
- out_verts[1] = text_vertex_s{{right, top}, {uv_right, uv_top}};
- out_verts[2] = text_vertex_s{{right, bottom}, {uv_right, uv_bottom}};
- out_verts[3] = text_vertex_s{{left, bottom}, {uv_left, uv_bottom}};
-
- out_indices[0] = 0;
- out_indices[1] = 1;
- out_indices[2] = 2;
- out_indices[3] = 2;
- out_indices[4] = 3;
- out_indices[5] = 0;
+ out_verts[0] = {{WAYC_X(quad.vertices[0]), WAYC_Y(quad.vertices[0])},
+ {uv_left, uv_top}};
+ out_verts[1] = {{WAYC_X(quad.vertices[1]), WAYC_Y(quad.vertices[1])},
+ {uv_right, uv_top}};
+ out_verts[2] = {{WAYC_X(quad.vertices[2]), WAYC_Y(quad.vertices[2])},
+ {uv_right, uv_bottom}};
+ out_verts[3] = {{WAYC_X(quad.vertices[3]), WAYC_Y(quad.vertices[3])},
+ {uv_left, uv_bottom}};
+
+#pragma GCC unroll 6
+ for (usize i = 0; i < WAYC_QUAD_NINDICES; ++i)
+ out_indices[i] = base + (text_index_t)quad.indices[i];
}
enum text_error_e wayc_text_assemble(struct text_s* text, usize* out_size,
@@ -180,9 +182,8 @@ enum text_error_e wayc_text_assemble(struct text_s* text, usize* out_size,
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;
+ usize vertex_count = glyph_count * WAYC_QUAD_NVERTS;
+ usize index_count = glyph_count * WAYC_QUAD_NINDICES;
usize vertex_bytes = vertex_count * sizeof(struct text_vertex_s);
usize index_bytes = index_count * sizeof(text_index_t);
@@ -194,6 +195,10 @@ enum text_error_e wayc_text_assemble(struct text_s* text, usize* out_size,
text_index_t* indices = (text_index_t*)mi_malloc(index_bytes);
wayc_defer_cond(mi_free(indices), success, true);
+ struct atlas_s* atlas = text->atlas;
+ f32 atlas_width = (f32)atlas->width;
+ f32 atlas_height = (f32)atlas->height;
+
vec2 pen = {0, 0};
for (usize i = 0; i < glyph_count; i++) {
codepoint_t codepoint = text->string.data[i];
@@ -202,17 +207,16 @@ enum text_error_e wayc_text_assemble(struct text_s* text, usize* out_size,
text->packer, codepoint, &glyph);
if (err != FONT_ERROR_NONE) return TEXT_ERROR_ATLAS;
- f32 atlas_width = (f32)text->atlas->width;
- f32 atlas_height = (f32)text->atlas->height;
-
- usize vertex_offset = i * WAYC_LETTER_NVERTICES;
- usize index_offset = i * WAYC_LETTER_NTRIANGLES * WAYC_TRIANGLE_NINDICES;
+ usize vertex_offset = i * WAYC_QUAD_NVERTS;
+ usize index_offset = i * WAYC_QUAD_NINDICES;
struct text_vertex_s* vertices_writer = &vertices[vertex_offset];
text_index_t* indices_writer = &indices[index_offset];
+ text_index_t base = (text_index_t)vertex_offset;
+
wayc_text_assemble_one(&glyph, &pen, atlas_width, atlas_height,
- vertices_writer, indices_writer);
+ vertices_writer, indices_writer, base);
pen[0] += glyph.advance;
}