summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-12 00:09:56 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-12 00:09:56 +0100
commit11dc980a40b4743b52ad4d88d91659e0cd413794 (patch)
tree4ce0fdee90ba58897d48cc9400a5e92930d85ebe
parent6013bac1556659f1685170b5e68752189f0b93ba (diff)
this drives me crazy
-rw-r--r--src/text.cc64
-rw-r--r--src/text.h7
-rw-r--r--src/utils.h4
3 files changed, 37 insertions, 38 deletions
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
diff --git a/src/text.h b/src/text.h
index 037fc2f..30a8893 100644
--- a/src/text.h
+++ b/src/text.h
@@ -16,6 +16,8 @@ struct text_vertex_s {
vec2 uv;
};
+typedef u32 text_index_t;
+
enum font_context_error_e {
FONT_CONTEXT_ERROR_NONE,
FONT_CONTEXT_ERROR_LIBRARY_LOADING,
@@ -73,5 +75,6 @@ struct text_s {
#define WAYC_TEXT_INIT(font, atlas, packer, string) \
text_s { font, atlas, packer, string }
-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);
diff --git a/src/utils.h b/src/utils.h
index 5a47c44..41eab56 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -78,6 +78,10 @@ static inline u32 wayc_min(u32 a, u32 b) { return a > b ? a : b; }
#define WAYC_Y(v) ((v)[1])
#define WAYC_TRIANGLE_NVERTS 3
+#define WAYC_TRIANGLE_NINDICES 3
+
+#define WAYC_QUAD_NVERTS 4
+#define WAYC_QUAD_NINDICES 6
static inline usize wayc_max(usize a, usize b) { return a > b ? a : b; }