Reduce shape cache reserve length, possible improvemnet in positioning in draw_text_batch, shape_text_uncached

This commit is contained in:
2024-06-30 21:04:52 -04:00
parent 69f95efaac
commit 6af2e2b1eb
3 changed files with 8 additions and 11 deletions

View File

@@ -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

View File

@@ -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 )

View File

@@ -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
}
}