From 83b7098ce99691edb60569c672e96ff77712f649 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 4 Jan 2025 10:16:22 -0500 Subject: [PATCH] WIP : trying to fix oversized yet again... --- code/font/vefontcache/draw.odin | 47 ++++++++++++++------------ code/font/vefontcache/mappings.odin | 1 + code/font/vefontcache/vefontcache.odin | 8 ++--- code/grime/slab_allocator.odin | 3 ++ 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/code/font/vefontcache/draw.odin b/code/font/vefontcache/draw.odin index 276d273..54b0570 100644 --- a/code/font/vefontcache/draw.odin +++ b/code/font/vefontcache/draw.odin @@ -237,9 +237,6 @@ generate_glyph_pass_draw_list :: proc(draw_list : ^Draw_List, path : ^[dynamic]V alpha := index * step append( path, Vertex { pos = eval_point_on_bezier4(p0, p1, p2, p3, alpha) } ) } - - // case: - // assert(false, "WTF") } if len(path) > 0 { @@ -366,7 +363,7 @@ generate_shape_draw_list :: #force_no_inline proc( draw_list : ^Draw_List, shape } atlas_glyph_pad := atlas.glyph_padding - atlas_size := Vec2 { f32(atlas.width), f32(atlas.height) } + atlas_size := Vec2 { f32(atlas.width), f32(atlas.height) } glyph_buffer_size := Vec2 { f32(glyph_buffer.width), f32(glyph_buffer.height) } // Make sure the packs are large enough for the shape @@ -499,22 +496,25 @@ generate_shape_draw_list :: #force_no_inline proc( draw_list : ^Draw_List, shape } profile_end() - // Last batch pass - batch_generate_glyphs_draw_list( draw_list, glyph_pack, sub_slice(cached), sub_slice(to_cache), sub_slice(oversized), - atlas, - glyph_buffer, - atlas_size, - glyph_buffer_size, - entry, - colour, - font_scale, - target_scale - ) + if len(oversized) > 0 || glyph_buffer.batch_cache.num > 0 + { + // Last batch pass + batch_generate_glyphs_draw_list( draw_list, glyph_pack, sub_slice(cached), sub_slice(to_cache), sub_slice(oversized), + atlas, + glyph_buffer, + atlas_size, + glyph_buffer_size, + entry, + colour, + font_scale, + target_scale + ) + } reset_batch( & glyph_buffer.batch_cache) - clear(oversized) - clear(to_cache) - clear(cached) + // clear(oversized) + // clear(to_cache) + // clear(cached) cursor_pos = target_position + shape.end_cursor_pos * target_scale return @@ -588,11 +588,14 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List, // Quad to draw during target pass, every quad := & glyph.draw_quad - quad.dst_pos = glyph.position + glyph.bounds_scaled.p0 * target_scale - glyph_padding * target_scale - quad.dst_scale = (glyph.bounds_size_scaled + glyph_padding) * target_scale + quad.dst_pos = glyph.position + (glyph.bounds_scaled.p0 - glyph_padding) * target_scale //- ({0, 0.5}) * target_scale + quad.dst_scale = (glyph.bounds_size_scaled + glyph_padding) * target_scale quad.src_pos = {} - quad.src_scale = glyph.bounds_size_scaled * glyph.over_sample + glyph_padding + quad.src_scale = glyph.bounds_size_scaled * glyph.over_sample - glyph_padding to_target_space( & quad.src_pos, & quad.src_scale, glyph_buffer_size ) + + dummy := 0 + dummy += 1 } profile_end() @@ -685,7 +688,7 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List, generate_glyph_pass_draw_list( draw_list, & glyph_buffer.shape_gen_scratch, glyph_pack[id].shape, entry.curve_quality, - glyph_pack[id].bounds, + glyph_pack[id].bounds_scaled, glyph_pack[id].draw_transform.scale, glyph_pack[id].draw_transform.pos ) diff --git a/code/font/vefontcache/mappings.odin b/code/font/vefontcache/mappings.odin index bd61b8d..8f8a275 100644 --- a/code/font/vefontcache/mappings.odin +++ b/code/font/vefontcache/mappings.odin @@ -134,3 +134,4 @@ profile_end :: #force_inline proc "contextless" () { } //#endregion("Proc overload mappings") + diff --git a/code/font/vefontcache/vefontcache.odin b/code/font/vefontcache/vefontcache.odin index 174c0ec..cbd242c 100644 --- a/code/font/vefontcache/vefontcache.odin +++ b/code/font/vefontcache/vefontcache.odin @@ -299,10 +299,10 @@ startup :: proc( ctx : ^Context, parser_kind : Parser_Kind = .STB_TrueType, batch_cache.table, error = make( map[u32]b8, uint(glyph_draw_params.shape_gen_scratch_reserve) ) assert(error == .None, "VEFontCache.init : Failed to allocate batch_cache") - glyph_pack,error = make_soa( #soa[dynamic]Glyph_Pack_Entry, length = 0, capacity = 1 * Kilobyte, allocator = context.temp_allocator ) - oversized, error = make( [dynamic]i32, len = 0, cap = 1 * Kilobyte, allocator = context.temp_allocator ) - to_cache, error = make( [dynamic]i32, len = 0, cap = 1 * Kilobyte, allocator = context.temp_allocator ) - cached, error = make( [dynamic]i32, len = 0, cap = 1 * Kilobyte, allocator = context.temp_allocator ) + glyph_pack,error = make_soa( #soa[dynamic]Glyph_Pack_Entry, length = 0, capacity = 1 * Kilobyte ) + oversized, error = make( [dynamic]i32, len = 0, cap = 1 * Kilobyte ) + to_cache, error = make( [dynamic]i32, len = 0, cap = 1 * Kilobyte ) + cached, error = make( [dynamic]i32, len = 0, cap = 1 * Kilobyte ) } parser_init( & parser_ctx, parser_kind ) diff --git a/code/grime/slab_allocator.odin b/code/grime/slab_allocator.odin index 8c7dd0f..30849e3 100644 --- a/code/grime/slab_allocator.odin +++ b/code/grime/slab_allocator.odin @@ -331,6 +331,9 @@ slab_allocator_proc :: proc( return slab_alloc( slab, size, alignment, (mode != .Alloc_Non_Zeroed), loc) case .Free: + if old_memory == nil { + return + } slab_free( slab, byte_slice( old_memory, int(old_size)), loc ) case .Free_All: