From 6af2e2b1ebd22641d7749fcebe43f3ba9bad1a17 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 30 Jun 2024 21:04:52 -0400 Subject: [PATCH] Reduce shape cache reserve length, possible improvemnet in positioning in draw_text_batch, shape_text_uncached --- VEFontCache/VEFontCache.odin | 8 ++------ VEFontCache/draw.odin | 5 +++-- VEFontCache/shaped_text.odin | 6 +++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/VEFontCache/VEFontCache.odin b/VEFontCache/VEFontCache.odin index 528efcf..b1864e9 100644 --- a/VEFontCache/VEFontCache.odin +++ b/VEFontCache/VEFontCache.odin @@ -1,11 +1,7 @@ /* A port of (https://github.com/hypernewbie/VEFontCache) to Odin. -Changes: -- Font Parser & Glyph Shaper are abstracted to their own interface -- Font Face parser info stored separately from entries -- ve_fontcache_loadfile not ported (just use odin's core:os or os2), then call load_font -- Macro defines have been made (mostly) into runtime parameters +See: https://github.com/Ed94/VEFontCache-Odin */ package VEFontCache @@ -130,7 +126,7 @@ InitShapeCacheParams :: struct { InitShapeCacheParams_Default :: InitShapeCacheParams { capacity = 8 * 1024, - reserve_length = 1 * 1024, + reserve_length = 256, } // ve_fontcache_init diff --git a/VEFontCache/draw.odin b/VEFontCache/draw.odin index 5679bbf..537f7ea 100644 --- a/VEFontCache/draw.odin +++ b/VEFontCache/draw.odin @@ -29,6 +29,7 @@ DrawList :: struct { calls : [dynamic]DrawCall, } +// TODO(Ed): This was a rough translation of the raw values the orignal was using, need to give better names... FrameBufferPass :: enum u32 { None = 0, Glyph = 1, @@ -489,8 +490,8 @@ draw_text_batch :: proc(ctx: ^Context, entry: ^Entry, shaped: ^ShapedText, // Draw cacxhed glyph slot_position, _ := atlas_bbox( atlas, region_kind, atlas_index ) glyph_scale := bounds_size * entry.size_scale + glyph_padding - bounds_0_scaled := ceil( vbounds_0 * entry.size_scale ) - dst := glyph_translate + (bounds_0_scaled - glyph_padding) * scale + bounds_0_scaled := ceil(vbounds_0 * entry.size_scale) + dst := glyph_translate + bounds_0_scaled * scale dst_scale := glyph_scale * scale textspace_x_form( & slot_position, & glyph_scale, atlas_size ) diff --git a/VEFontCache/shaped_text.odin b/VEFontCache/shaped_text.odin index 1ac55c2..96b8cd1 100644 --- a/VEFontCache/shaped_text.odin +++ b/VEFontCache/shaped_text.odin @@ -111,7 +111,7 @@ shape_text_uncached :: proc( ctx : ^Context, font : FontID, text_utf8 : string, continue } if abs( entry.size ) <= Advance_Snap_Smallfont_Size { - position.x = ceil( position.x ) + position.x = position.x } append( & output.glyphs, parser_find_glyph_index( & entry.parser_info, codepoint )) @@ -122,14 +122,14 @@ shape_text_uncached :: proc( ctx : ^Context, font : FontID, text_utf8 : string, position.y }) - position.x += f32(advance) * entry.size_scale + position.x += ceil(f32(advance) * entry.size_scale) prev_codepoint = codepoint } output.end_cursor_pos = position max_line_width = max(max_line_width, position.x) - output.size.x = max_line_width + output.size.x = ceil(max_line_width) output.size.y = f32(line_count) * line_height } }