WIP - VEFontCache: Working on getting font size usage and super-sampling via scaling working on library side...

This commit is contained in:
2025-01-06 11:00:55 -05:00
parent c0b439bc30
commit 840e6053ff
12 changed files with 304 additions and 216 deletions

View File

@ -4,7 +4,7 @@ package sectr
import sokol_gfx "thirdparty:sokol/gfx"
DebugData :: struct {
ScratchData :: struct {
square_size : i32,
square_pos : Vec2,
@ -33,11 +33,4 @@ DebugData :: struct {
path_lorem : string,
lorem_content : []byte,
lorem_parse : PWS_ParseResult,
gfx_clear_demo_pass_action : sokol_gfx.Pass_Action,
gfx_tri_demo_state : struct {
pipeline : sokol_gfx.Pipeline,
bindings : sokol_gfx.Bindings,
pass_action : sokol_gfx.Pass_Action,
},
}

View File

@ -221,7 +221,7 @@ State :: struct {
staged_input_events : Array(InputEvent),
// TODO(Ed): Add a multi-threaded guard for accessing or mutating staged_input_events.
debug : DebugData,
debug : ScratchData,
project : Project,
@ -252,7 +252,6 @@ State :: struct {
font_rec_mono_semicasual_reg : FontID,
default_font : FontID,
// Context tracking
// These are used as implicit contextual states when doing immediate mode interfaces
// or for event callbacks that need their context assigned
@ -281,7 +280,7 @@ frametime_delta32 :: #force_inline proc "contextless" () -> f32 {
app_config :: #force_inline proc "contextless" () -> AppConfig { return get_state().config }
app_color_theme :: #force_inline proc "contextless" () -> AppColorTheme { return get_state().config.color_theme }
debug_data :: #force_inline proc "contextless" () -> DebugData { return get_state().debug }
debug_data :: #force_inline proc "contextless" () -> ScratchData { return get_state().debug }
get_frametime :: #force_inline proc "contextless" () -> FrameTime { return get_state().frametime }
get_default_font :: #force_inline proc "contextless" () -> FontID { return get_state().default_font }
get_input_state :: #force_inline proc "contextless" () -> InputState { return (get_state().input ^) }

View File

@ -152,8 +152,8 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
color_theme = App_Thm_Dusk
font_size_screen_scalar = 2.0
font_size_canvas_scalar = 2.0
font_size_screen_scalar = 1.0
font_size_canvas_scalar = 1.0
}
Desired_OS_Scheduler_MS :: 1
@ -265,43 +265,44 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
if true
{
font_provider_startup( & font_provider_ctx )
path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" })
font_rec_mono_semicasual_reg = font_load( path_rec_mono_semicasual_reg, 16.0, "RecMonoSemiCasual_Regular" )
// path_squidgy_slimes := strings.concatenate( { Path_Assets, "Squidgy Slimes.ttf" } )
// font_squidgy_slimes = font_load( path_squidgy_slimes, 32.0, "Squidgy_Slime" )
// Load default font
path_fira_cousine := strings.concatenate( { Path_Assets, "FiraCousine-Regular.ttf" } )
font_fira_cousine = font_load( path_fira_cousine, "Fira Cousine", 16.0 )
default_font = font_fira_cousine
// Aysnc load the others
// path_arial_unicode_ms := strings.concatenate( { Path_Assets, "Arial Unicode MS.ttf" } )
// font_arial_unicode_ms = font_load( path_arial_unicode_ms, "Arial_Unicode_MS", 16.0 )
// path_firacode := strings.concatenate( { Path_Assets, "FiraCode-Regular.ttf" } )
// font_firacode = font_load( path_firacode, 16.0, "FiraCode" )
path_fira_cousine := strings.concatenate( { Path_Assets, "FiraCousine-Regular.ttf" } )
font_fira_cousine = font_load( path_fira_cousine, 16.0, "Fira Cousine" )
// path_open_sans := strings.concatenate( { Path_Assets, "OpenSans-Regular.ttf" } )
// font_open_sans = font_load( path_open_sans, 16.0, "OpenSans" )
// path_noto_sans := strings.concatenate( { Path_Assets, "NotoSans-Regular.ttf" } )
// font_noto_sans = font_load( path_noto_sans, 16.0, "NotoSans" )
// font_firacode = font_load( path_firacode, "FiraCode", 16.0 )
// path_neodgm_code := strings.concatenate( { Path_Assets, "neodgm_code.ttf"} )
// font_neodgm_code = font_load( path_neodgm_code, 32.0, "NeoDunggeunmo Code" )
// font_neodgm_code = font_load( path_neodgm_code, "NeoDunggeunmo Code", 32.0 )
// path_noto_sans := strings.concatenate( { Path_Assets, "NotoSans-Regular.ttf" } )
// font_noto_sans = font_load( path_noto_sans, "NotoSans", 16.0 )
// path_open_sans := strings.concatenate( { Path_Assets, "OpenSans-Regular.ttf" } )
// font_open_sans = font_load( path_open_sans, "OpenSans", 16.0 )
// path_rec_mono_linear := strings.concatenate( { Path_Assets, "RecMonoLinear-Regular-1.084.ttf" })
// font_rec_mono_linear = font_load( path_rec_mono_linear, 16.0, "RecMonoLinear Regular" )
// font_rec_mono_linear = font_load( path_rec_mono_linear, "RecMonoLinear Regular", 32.0 )
// path_roboto_regular := strings.concatenate( { Path_Assets, "Roboto-Regular.ttf"} )
// font_roboto_regular = font_load( path_roboto_regular, 32.0, "Roboto Regular" )
// font_roboto_regular = font_load( path_roboto_regular, "Roboto Regular", 32.0 )
// path_roboto_mono_regular := strings.concatenate( { Path_Assets, "RobotoMono-Regular.ttf"} )
// font_roboto_mono_regular = font_load( path_roboto_mono_regular, 32.0, "Roboto Mono Regular" )
// font_roboto_mono_regular = font_load( path_roboto_mono_regular, "Roboto Mono Regular", 32.0 )
// path_arial_unicode_ms := strings.concatenate( { Path_Assets, "Arial Unicode MS.ttf" } )
// font_arial_unicode_ms = font_load( path_arial_unicode_ms, 16.0, "Arial_Unicode_MS" )
// path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" })
// font_rec_mono_semicasual_reg = font_load( path_rec_mono_semicasual_reg, "RecMonoSemiCasual_Regular", 16 )
// path_arial_unicode_ms := strings.concatenate( { Path_Assets, "Arial Unicode MS.ttf" } )
// font_arial_unicode_ms = font_load( path_arial_unicode_ms, 16.0, "Arial_Unicode_MS" )
// path_squidgy_slimes := strings.concatenate( { Path_Assets, "Squidgy Slimes.ttf" } )
// font_squidgy_slimes = font_load( path_squidgy_slimes, "Squidgy_Slime", 32.0 )
default_font = font_fira_cousine
log( "Default font loaded" )
}
@ -451,6 +452,9 @@ hot_reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_
slab_reload( persistent_slab, persistent_allocator() )
str_cache_reload( & string_cache, persistent_allocator(), persistent_allocator() )
str_cache_set_module_ctx( & string_cache )
// input_reload()
{
using input_events
@ -463,9 +467,6 @@ hot_reload :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_
font_provider_reload( & font_provider_ctx )
str_cache_reload( & string_cache, persistent_allocator(), persistent_allocator() )
str_cache_set_module_ctx( & string_cache )
slab_reload( frame_slab, frame_allocator())
slab_reload( transient_slab, transient_allocator())
@ -532,8 +533,8 @@ tick_work_frame :: #force_inline proc( host_delta_time_ms : f64 ) -> b32
// config.engine_refresh_hz = 165
// config.color_theme = App_Thm_Light
config.color_theme = App_Thm_Dusk
// config.color_theme = App_Thm_Dark
// config.color_theme = App_Thm_Dusk
config.color_theme = App_Thm_Dark
sokol_width := sokol_app.widthf()
sokol_height := sokol_app.heightf()

View File

@ -116,7 +116,7 @@ render_mode_2d_workspace :: proc( screen_extent : Vec2, cam : Camera, input : In
}
}
render_mode_screenspace :: proc( screen_extent : Extents2, screen_ui : ^UI_State, ve_ctx : ^ve.Context, ve_render : VE_RenderData, config : AppConfig, debug : ^DebugData )
render_mode_screenspace :: proc( screen_extent : Extents2, screen_ui : ^UI_State, ve_ctx : ^ve.Context, ve_render : VE_RenderData, config : AppConfig, debug : ^ScratchData )
{
profile(#procedure)
screen_size := screen_extent * 2
@ -158,7 +158,7 @@ render_mode_screenspace :: proc( screen_extent : Extents2, screen_ui : ^UI_State
font := font
if font.key == Font_Default.key do font = default_font
shape := shape_text_cached( content, font, size, app_config().font_size_screen_scalar )
shape := shape_text_cached( content, font, size, 1.0 )
draw_text_shape_pos_extent( shape, font, size, pos, color )
}
@ -174,14 +174,14 @@ render_mode_screenspace :: proc( screen_extent : Extents2, screen_ui : ^UI_State
position.y -= debug.draw_debug_text_y
content := str_fmt( format, ..args )
text_size := measure_text_size( content, default_font, 14.0, 0.0 )
debug_draw_text( content, position, 12.0 )
text_size := measure_text_size( content, default_font, 16.0, 0.0 )
debug_draw_text( content, position, 16.0 )
debug.draw_debug_text_y += text_size.y
}
profile("debug_text_vis")
if true {
fps_size : f32 = 14.0
fps_size : f32 = 20.0
fps_msg := str_fmt( "FPS: %0.2f", fps_avg)
fps_msg_size := measure_text_size( fps_msg, default_font, fps_size, 0.0 )
fps_msg_pos := screen_get_corners().top_right - { fps_msg_size.x, fps_msg_size.y }
@ -906,13 +906,16 @@ 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 * config.font_size_screen_scalar )
ve_id, resolved_size := font_provider_resolve_draw_id( id, font_size )
color_norm := normalize_rgba8(color)
screen_size_norm := Vec2{1 / width, 1 / height}
screen_size_norm := 1 / Vec2 { width, height }
draw_scale := screen_size_norm * scale
// ve.set_px_scalar( & font_provider_ctx.ve_ctx, config.font_size_screen_scalar )
ve.set_colour( & font_provider_ctx.ve_ctx, color_norm )
ve.draw_text( & font_provider_ctx.ve_ctx, ve_id, f32(resolved_size), pos, screen_size_norm * scale * (1 / config.font_size_screen_scalar), text )
ve.draw_text( & font_provider_ctx.ve_ctx, ve_id, f32(resolved_size), pos, draw_scale, text )
return
}
@ -934,13 +937,14 @@ draw_text_shape_pos_norm :: #force_inline proc( shape : ShapedText, id : FontID,
width := app_window.extent.x * 2
height := app_window.extent.y * 2
ve_id, resolved_size := font_provider_resolve_draw_id( id, font_size * config.font_size_screen_scalar )
ve_id, resolved_size := font_provider_resolve_draw_id( id, font_size )
color_norm := normalize_rgba8(color)
screen_size_norm := Vec2 { 1 / width, 1 / height }
// ve.set_px_scalar( & font_provider_ctx.ve_ctx, config.font_size_screen_scalar )
ve.set_colour( & font_provider_ctx.ve_ctx, color_norm )
ve.draw_text_shape( & font_provider_ctx.ve_ctx, ve_id, f32(resolved_size), pos, screen_size_norm * scale * (1 / config.font_size_screen_scalar), shape )
ve.draw_text_shape( & font_provider_ctx.ve_ctx, ve_id, f32(resolved_size), pos, screen_size_norm * scale, shape )
return
}
@ -964,8 +968,8 @@ draw_text_string_pos_extent_zoomed :: #force_inline proc( text : string, id : Fo
zoom_adjust_size := size * zoom
// Over-sample font-size for any render under a camera
over_sample : f32 = f32(config.font_size_canvas_scalar)
zoom_adjust_size *= over_sample
// over_sample : f32 = f32(config.font_size_canvas_scalar)
// zoom_adjust_size *= over_sample
pos_offset := (pos + cam_offset)
render_pos := ws_view_to_render_pos(pos)
@ -984,9 +988,10 @@ draw_text_string_pos_extent_zoomed :: #force_inline proc( text : string, id : Fo
}
// Down-sample back
text_scale /= over_sample
// text_scale /= over_sample
color_norm := normalize_rgba8(color)
// ve.set_px_scalar( & get_state().font_provider_ctx.ve_ctx, config.font_size_canvas_scalar )
ve.set_colour( & get_state().font_provider_ctx.ve_ctx, color_norm )
ve.draw_text( & get_state().font_provider_ctx.ve_ctx, ve_id, f32(resolved_size), normalized_pos, text_scale, text )
}
@ -1000,7 +1005,7 @@ draw_text_shape_pos_extent_zoomed :: #force_inline proc( shape : ShapedText, id
// Over-sample font-size for any render under a camera
over_sample : f32 = f32(state.config.font_size_canvas_scalar)
zoom_adjust_size *= over_sample
// zoom_adjust_size *= over_sample
pos_offset := (pos + cam_offset)
render_pos := ws_view_to_render_pos(pos)
@ -1019,9 +1024,10 @@ draw_text_shape_pos_extent_zoomed :: #force_inline proc( shape : ShapedText, id
}
// Down-sample back
text_scale /= over_sample
// text_scale /= over_sample
color_norm := normalize_rgba8(color)
// ve.set_px_scalar( & get_state().font_provider_ctx.ve_ctx, config.font_size_canvas_scalar )
ve.set_colour( & font_provider_ctx.ve_ctx, color_norm )
ve.draw_text_shape( & font_provider_ctx.ve_ctx, ve_id, f32_resolved_size, normalized_pos, text_scale, shape )
}

View File

@ -302,11 +302,13 @@ update :: proc( delta_time : f64 ) -> b32
// TODO(Ed): We need input buffer so that we can consume input actions based on the UI with priority
font_provider_set_px_scalar( app_config().font_size_screen_scalar )
ui_screen_tick( & get_state().screen_ui )
//region WorkspaceImgui Tick
if true
{
font_provider_set_px_scalar( app_config().font_size_canvas_scalar )
profile("Workspace Imgui")
// Creates the root box node, set its as the first parent.

View File

@ -66,8 +66,8 @@ font_provider_shutdown :: proc( ctx : ^FontProviderContext )
}
font_load :: proc(path_file : string,
desired_id : string = Font_Load_Gen_ID,
default_size : i32 = Font_Load_Use_Default_Size,
desired_id : string = Font_Load_Gen_ID
) -> FontID
{
provider_data := & get_state().font_provider_ctx; using provider_data
@ -108,7 +108,7 @@ font_load :: proc(path_file : string,
// 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 := ve.load_font( & ve_ctx, desired_id, font_data, f32(font_size) )
ve_ret_id, error := ve.load_font( & ve_ctx, desired_id, font_data )
(ve_id^) = ve_ret_id
}
@ -116,6 +116,10 @@ font_load :: proc(path_file : string,
return fid
}
font_provider_set_px_scalar :: #force_inline proc( scalar : f32 ) {
ve.set_px_scalar( & get_state().font_provider_ctx.ve_ctx, scalar )
}
Font_Use_Default_Size :: f32(0.0)
font_provider_resolve_draw_id :: #force_inline proc( id : FontID, size := Font_Use_Default_Size ) -> (ve_id :ve.Font_ID, resolved_size : i32)