fix hot-reload, starting to setup proper rendering again.

* Added hot_reload, measure_text_size to VEFontCache
This commit is contained in:
2024-06-19 02:34:02 -04:00
parent 4b8c4d0c2c
commit 59ed4d9dd6
12 changed files with 549 additions and 58 deletions

View File

@ -49,6 +49,17 @@ pool_list_init :: proc( pool : ^PoolList, capacity : u32 )
back = -1
}
pool_list_free :: proc( pool : ^PoolList )
{
}
pool_list_reload :: proc( pool : ^PoolList, allocator : Allocator )
{
pool.items.backing = allocator
pool.free_list.backing = allocator
}
pool_list_push_front :: proc( pool : ^PoolList, value : PoolListValue )
{
using pool
@ -134,6 +145,17 @@ LRU_init :: proc( cache : ^LRU_Cache, capacity : u32 ) {
pool_list_init( & cache.key_queue, capacity )
}
LRU_free :: proc( cache : ^LRU_Cache )
{
}
LRU_reload :: proc( cache : ^LRU_Cache, allocator : Allocator )
{
hmap_zpl_reload( & cache.table, allocator )
pool_list_reload( & cache.key_queue, allocator )
}
LRU_hash_key :: #force_inline proc( key : u64 ) -> ( hash : u64 ) {
bytes := transmute( [8]byte ) key
hash = fnv64a( bytes[:] )
@ -172,7 +194,8 @@ LRU_peek :: proc( cache : ^LRU_Cache, key : u64 ) -> i32 {
return iter.value
}
LRU_put :: proc( cache : ^LRU_Cache, key : u64, value : i32 ) -> u64 {
LRU_put :: proc( cache : ^LRU_Cache, key : u64, value : i32 ) -> u64
{
hash_key := LRU_hash_key( key )
iter := get( & cache.table, hash_key )
if iter != nil {

View File

@ -355,6 +355,43 @@ init :: proc( ctx : ^Context, parser_kind : ParserKind,
shaper_init( & shaper_ctx )
}
hot_reload :: proc( ctx : ^Context, allocator : Allocator )
{
ctx.backing = allocator
context.allocator = ctx.backing
using ctx
entries.backing = allocator
temp_path.backing = allocator
hmap_zpl_reload( & temp_codepoint_seen, allocator )
draw_list.vertices.backing = allocator
draw_list.indices.backing = allocator
draw_list.calls.backing = allocator
LRU_reload( & atlas.region_a.state, allocator)
LRU_reload( & atlas.region_b.state, allocator)
LRU_reload( & atlas.region_c.state, allocator)
LRU_reload( & atlas.region_d.state, allocator)
LRU_reload( & shape_cache.state, allocator )
for idx : u32 = 0; idx < u32(shape_cache.storage.capacity); idx += 1 {
stroage_entry := & shape_cache.storage.data[idx]
using stroage_entry
glyphs.backing = allocator
positions.backing = allocator
}
atlas.draw_list.calls.backing = allocator
atlas.draw_list.indices.backing = allocator
atlas.draw_list.vertices.backing = allocator
atlas.clear_draw_list.calls.backing = allocator
atlas.clear_draw_list.indices.backing = allocator
atlas.clear_draw_list.vertices.backing = allocator
}
// ve_foncache_shutdown
shutdown :: proc( ctx : ^Context )
{
@ -679,6 +716,37 @@ is_empty :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph ) -> b32
return false
}
measure_text_size :: proc( ctx : ^Context, font : FontID, text_utf8 : string ) -> (measured : Vec2)
{
assert( ctx != nil )
assert( font >= 0 && font < FontID(ctx.entries.num) )
atlas := ctx.atlas
shaped := shape_text_cached( ctx, font, text_utf8 )
entry := & ctx.entries.data[ font ]
batch_start_idx : i32 = 0
for index : i32 = 0; index < i32(shaped.glyphs.num); index += 1
{
glyph_index := shaped.glyphs.data[ index ]
if is_empty( ctx, entry, glyph_index ) do continue
bounds_0, bounds_1 := parser_get_glyph_box( & entry.parser_info, glyph_index )
bounds_width := bounds_1.x - bounds_0.x
bounds_height := bounds_1.y - bounds_0.y
bounds := Vec2 {
cast(f32) cast(u32) (f32(bounds_width) * entry.size_scale - f32(atlas.glyph_padding)),
cast(f32) cast(u32) (f32(bounds_height) * entry.size_scale - f32(atlas.glyph_padding)),
}
measured += bounds
}
return measured
}
reset_batch_codepoint_state :: proc( ctx : ^Context ) {
clear( & ctx.temp_codepoint_seen )
ctx.temp_codepoint_seen_num = 0

View File

@ -289,6 +289,8 @@ draw_text :: proc( ctx : ^Context, font : FontID, text_utf8 : string, position :
assert( ctx != nil )
assert( font >= 0 && font < FontID(ctx.entries.num) )
context.allocator = ctx.backing
shaped := shape_text_cached( ctx, font, text_utf8 )
snap_width := f32(ctx.snap_width)

View File

@ -108,6 +108,10 @@ make :: proc {
hmap_zpl_init,
}
// reload :: proc {
// }
remove_at :: proc {
array_remove_at,
}