Commit: 541b0c45d05a1fc54fc98824b8ca8b202e480aa9
Parent: 5ffa479a7573f04097b7b4ba7112da1e6dfda25b
Author: Randy Palamar
Date: Mon, 4 Nov 2024 19:46:10 -0700
push_s8: make sure all text starts on nearest pixel
we are not currently doing subpixel rendering since this makes it
difficult to cache so this is important to make sure overlay text
doesn't look nasty.
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/vtgl.c b/vtgl.c
@@ -269,6 +269,10 @@ push_s8(RenderCtx *rc, v2 pos, v4 colour, u32 font_id, s8 s)
v2 start, end, text_size = {0};
v2 scale = {.x = 1.0f / rc->gl->glyph_bitmap_dim.x, .y = 1.0f / rc->gl->glyph_bitmap_dim.y};
+ /* TODO: implement GPU based glyph rasterizing */
+ pos.x = (u32)pos.x;
+ pos.y = (u32)pos.y;
+
while (s.len) {
u32 cp = get_utf8(&s);
if (cp == (u32)-1)
@@ -299,14 +303,16 @@ push_s8(RenderCtx *rc, v2 pos, v4 colour, u32 font_id, s8 s)
static v2
measure_text(RenderCtx *rc, u32 font_id, s8 text)
{
+ BEGIN_TIMED_BLOCK();
+
v2 result = {0};
CachedGlyph *cg;
- u32 cp = 0;
while (text.len) {
- cp = get_utf8(&text);
+ u32 cp = get_utf8(&text);
if (cp == (u32)-1)
break;
+
get_gpu_glyph_index(rc->a, rc->gl, rc->fa, cp, font_id, FS_NORMAL, &cg);
if (cg->height > result.y)
result.y = cg->height;
@@ -315,6 +321,8 @@ measure_text(RenderCtx *rc, u32 font_id, s8 text)
result.x -= cg->advance;
result.x += cg->width;
+ END_TIMED_BLOCK();
+
return result;
}