LRU cache now as templated key type

Was testing to see if 16-bit cach emade a diff for the glyphs (it did not)
This commit is contained in:
2025-01-06 21:18:39 -05:00
parent bf38087d8e
commit a9080fe1f3
12 changed files with 185 additions and 120 deletions

View File

@ -354,8 +354,8 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (197).txt", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/Lorem Ipsum (1022).txt", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/sokol_gp.h", allocator = persistent_slab_allocator())
debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/ve_fontcache.h", allocator = persistent_slab_allocator())
debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/sokol_gp.h", allocator = persistent_slab_allocator())
// debug.path_lorem = str_fmt("C:/projects/SectrPrototype/examples/ve_fontcache.h", allocator = persistent_slab_allocator())
alloc_error : AllocatorError; success : bool
debug.lorem_content, success = os.read_entire_file( debug.path_lorem, persistent_slab_allocator() )
@ -528,8 +528,8 @@ tick_work_frame :: #force_inline proc( host_delta_time_ms : f64 ) -> b32
debug.draw_ui_padding_bounds = false
debug.draw_ui_content_bounds = false
font_provider_set_alpha_sharpen(0.15)
font_provider_set_snap_glyph_pos(false)
font_provider_set_alpha_sharpen(0.25)
font_provider_set_snap_glyph_pos(true)
// config.engine_refresh_hz = 165

View File

@ -57,6 +57,7 @@ render_mode_2d_workspace :: proc( screen_extent : Vec2, cam : Camera, input : In
screen_size := screen_extent * 2
// TODO(Ed): Eventually will be the viewport extents
ve.set_px_scalar( ve_ctx, app_config().font_size_canvas_scalar )
ve.configure_snap( ve_ctx, u32(screen_size.x), u32(screen_size.y) )
// ve.configure_snap( ve_ctx, 0, 0 )
@ -122,6 +123,7 @@ render_mode_screenspace :: proc( screen_extent : Extents2, screen_ui : ^UI_State
screen_size := screen_extent * 2
screen_ratio := screen_size.x * ( 1.0 / screen_size.y )
ve.set_px_scalar( ve_ctx, app_config().font_size_screen_scalar )
ve.configure_snap( ve_ctx, u32(screen_size.x), u32(screen_size.y) )
render_screen_ui( screen_extent, screen_ui, ve_ctx, ve_render )
@ -917,12 +919,18 @@ draw_text_string_pos_norm :: #force_inline proc( text : string, id : FontID, fon
width := app_window.extent.x * 2
height := app_window.extent.y * 2
ve_id, resolved_size := font_provider_resolve_draw_id( id, font_size )
// over_sample : f32 = f32(config.font_size_screen_scalar)
target_size := font_size
// target_size *= over_sample
ve_id, resolved_size := font_provider_resolve_draw_id( id, target_size )
color_norm := normalize_rgba8(color)
screen_size_norm := 1 / Vec2 { width, height }
draw_scale := screen_size_norm * scale
// draw_scale /= over_sample
// ve.set_px_scalar( & font_provider_ctx.ve_ctx, config.font_size_screen_scalar )
ve.set_colour( & font_provider_ctx.ve_ctx, color_norm )
@ -938,6 +946,7 @@ draw_text_string_pos_extent :: #force_inline proc( text : string, id : FontID, f
screen_size := app_window.extent * 2
render_pos := screen_to_render_pos(pos)
normalized_pos := render_pos * (1.0 / screen_size)
draw_text_string_pos_norm( text, id, font_size, normalized_pos, color )
}

View File

@ -23,7 +23,8 @@ FontID :: struct {
FontDef :: struct {
path_file : string,
default_size : i32,
size_table : [Font_Largest_Px_Size / Font_Size_Interval] ve.Font_ID,
ve_id : ve.Font_ID
// size_table : [Font_Largest_Px_Size / Font_Size_Interval] ve.Font_ID,
}
FontProviderContext :: struct
@ -76,6 +77,7 @@ font_load :: proc(path_file : string,
profile(msg)
log(msg)
font_data, read_succeded : = os.read_entire_file( path_file, persistent_allocator() )
verify( b32(read_succeded), str_fmt("Failed to read font file for: %v", path_file) )
font_data_size := cast(i32) len(font_data)
@ -103,14 +105,8 @@ font_load :: proc(path_file : string,
def.path_file = path_file
def.default_size = default_size
for font_size : i32 = clamp( Font_Size_Interval, 2, Font_Size_Interval ); font_size <= Font_Largest_Px_Size; font_size += Font_Size_Interval
{
// logf("Loading at size %v", font_size)
id := (font_size / Font_Size_Interval) + (font_size % Font_Size_Interval)
ve_id := & def.size_table[id - 1]
ve_ret_id, error := ve.load_font( & ve_ctx, desired_id, font_data )
(ve_id^) = ve_ret_id
}
error : ve.Load_Font_Error
def.ve_id, error = ve.load_font( & ve_ctx, desired_id, font_data )
fid := FontID { key, desired_id }
return fid
@ -118,20 +114,14 @@ font_load :: proc(path_file : string,
font_provider_set_alpha_sharpen :: #force_inline proc( scalar : f32 ) {
ve.set_alpha_scalar( & get_state().font_provider_ctx.ve_ctx, scalar )
// ve.clear_atlas_region_caches(& ctx.ve_ctx)
// ve.clear_shape_cache(& ctx.ve_ctx)
}
font_provider_set_px_scalar :: #force_inline proc( scalar : f32 ) {
ve.set_px_scalar( & get_state().font_provider_ctx.ve_ctx, scalar )
// ve.clear_atlas_region_caches(& ctx.ve_ctx)
// ve.clear_shape_cache(& ctx.ve_ctx)
}
font_provider_set_snap_glyph_pos :: #force_inline proc( should_snap : b32 ) {
ve.set_snap_glyph_pos( & get_state().font_provider_ctx.ve_ctx, should_snap )
// ve.clear_atlas_region_caches(& ctx.ve_ctx)
// ve.clear_shape_cache(& ctx.ve_ctx)
}
Font_Use_Default_Size :: f32(0.0)
@ -146,7 +136,7 @@ font_provider_resolve_draw_id :: #force_inline proc( id : FontID, size := Font_U
resolved_size = clamp( i32( even_size), 2, Font_Largest_Px_Size )
id := (resolved_size / Font_Size_Interval) + (resolved_size % Font_Size_Interval)
ve_id = def.size_table[ id - 1 ]
ve_id = def.ve_id
return
}