summaryrefslogtreecommitdiff
path: root/src/text.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/text.cc')
-rw-r--r--src/text.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/text.cc b/src/text.cc
index 51ddc9b..4a01c8e 100644
--- a/src/text.cc
+++ b/src/text.cc
@@ -289,3 +289,78 @@ void wayc_text_mesh_deinit(struct text_mesh_s* mesh) {
mesh->vertices = nullptr;
mesh->indices = nullptr;
}
+
+static inline void wayc_text_buf_desc(struct sg_buffer_desc* vbo,
+ struct sg_buffer_desc* ebo) {
+ wayc_notnull(vbo);
+ wayc_notnull(ebo);
+
+ struct sg_buffer_usage usage = {};
+ usage.vertex_buffer = true;
+ usage.dynamic_update = false;
+ usage.stream_update = true;
+ usage.immutable = false;
+
+ vbo->usage = usage;
+ usage.vertex_buffer = false;
+ usage.index_buffer = true;
+ ebo->usage = usage;
+}
+
+bool wayc_text_group_init(struct text_group_s* group, struct font_s* font,
+ usize glyph_capacity) {
+ wayc_notnull(group);
+ wayc_notnull(font);
+ memset(group, 0, sizeof(*group));
+
+ bool success = false;
+
+ usize nverts = glyph_capacity * WAYC_QUAD_NVERTS;
+ usize nindices = glyph_capacity * WAYC_QUAD_NINDICES;
+
+ usize verts_bytes = nverts * sizeof(struct text_vertex_s);
+ usize indices_bytes = nindices * sizeof(u16);
+
+ struct sg_buffer_desc vbo_desc = {};
+ struct sg_buffer_desc ebo_desc = {};
+ wayc_text_buf_desc(&vbo_desc, &ebo_desc);
+
+ vbo_desc.size = verts_bytes;
+ ebo_desc.size = indices_bytes;
+
+ struct sg_buffer vbuf = sg_make_buffer(&vbo_desc);
+ if (sg_query_buffer_state(vbuf) != SG_RESOURCESTATE_VALID) return false;
+ wayc_defer_cond(sg_destroy_buffer(vbuf), success, true);
+
+ struct sg_buffer ebuf = sg_make_buffer(&ebo_desc);
+ if (sg_query_buffer_state(ebuf) != SG_RESOURCESTATE_VALID) return false;
+ wayc_defer_cond(sg_destroy_buffer(ebuf), success, true);
+
+ group->vbuf = vbuf;
+ group->ebuf = ebuf;
+ group->glyph_capacity = glyph_capacity;
+ group->font = font;
+
+ success = true;
+ return success;
+}
+
+void wayc_text_group_begin(struct text_group_s* group) {
+ wayc_notnull(group);
+
+ group->index_count = 0;
+ group->glyph_count = 0;
+}
+
+void wayc_text_group_end(struct text_group_s* group,
+ struct font_context_s* context) {
+ wayc_notnull(group);
+ wayc_notnull(context);
+}
+
+void wayc_text_group_deinit(struct text_group_s* group) {
+ wayc_notnull(group);
+
+ sg_destroy_buffer(group->vbuf);
+ sg_destroy_buffer(group->ebuf);
+}