Text rendering is now around parity (if not better) than what was done before with raylib

Performance still sucks since the rendering implementation is subpar
This commit is contained in:
2024-06-24 23:19:08 -04:00
parent 321bbfd772
commit 6f722026ce
9 changed files with 217 additions and 161 deletions

View File

@ -289,7 +289,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
ui_floating_startup( & screen_ui.floating, 1 * Kilobyte, 1 * Kilobyte, persistent_slab_allocator(), "screen ui floating manager" )
using screen_ui
menu_bar.pos = { -60, 0 }
menu_bar.pos = { -260, -200 }
// menu_bar.pos = Vec2(app_window.extent) * { -1, 1 }
menu_bar.size = {140, 40}
@ -498,14 +498,14 @@ tick_work_frame :: #force_inline proc( host_delta_time_ms : f64 ) -> b32
// rl.PollInputEvents()
debug.draw_ui_box_bounds_points = false
debug.draw_UI_padding_bounds = false
debug.draw_ui_padding_bounds = false
debug.draw_ui_content_bounds = false
// 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

@ -173,10 +173,10 @@ render_mode_screenspace :: proc()
}
profile("debug_text_vis")
fps_size : f32 = 14.0
fps_size : f32 = 16.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 * 2, fps_msg_size.y }
fps_msg_pos := screen_get_corners().top_right - { fps_msg_size.x, fps_msg_size.y }
debug_draw_text( fps_msg, fps_msg_pos, fps_size, color = Color_Red )
debug_text( "Screen Width : %v", screen_size.x )
@ -466,6 +466,10 @@ render_ui_via_box_tree :: proc( root : ^UI_Box, cam : ^Camera = nil )
debug := get_state().debug
default_font := get_state().default_font
cam_zoom_ratio := cam != nil ? 1.0 / cam.zoom : 1.0
circle_radius := cam != nil ? cam_zoom_ratio * 3 : 3
for box := root.first; box != nil; box = ui_box_tranverse_next_depth_based( box )
{
text_enqueued : b32 = false
@ -496,13 +500,25 @@ render_ui_via_box_tree :: proc( root : ^UI_Box, cam : ^Camera = nil )
shape_enqueued = true
}
line_thickness := 1 * cam_zoom_ratio
if debug.draw_ui_padding_bounds && equal_range2( computed.content, computed.padding )
{
render_set_color( RGBA8_Debug_UI_Padding_Bounds )
draw_rect_border( computed.padding, line_thickness )
}
else if debug.draw_ui_content_bounds {
render_set_color( RGBA8_Debug_UI_Content_Bounds )
draw_rect_border( computed.content, line_thickness )
}
if debug.draw_ui_box_bounds_points
{
render_set_color(Color_Red)
draw_filled_circle(bounds.min.x, bounds.min.y, 3, 24)
draw_filled_circle(bounds.min.x, bounds.min.y, circle_radius, 24)
render_set_color(Color_Blue)
draw_filled_circle(bounds.max.x, bounds.max.y, 3, 24)
draw_filled_circle(bounds.max.x, bounds.max.y, circle_radius, 24)
shape_enqueued = true
}
}
@ -644,8 +660,8 @@ draw_text_string_pos_norm :: proc( content : string, id : FontID, size : f32, po
width := app_window.extent.x * 2
height := app_window.extent.y * 2
ve_id := font_provider_resolve_draw_id( id, size )
color_norm := normalize_rgba8(color)
ve_id, resolved_size := font_provider_resolve_draw_id( id, size )
color_norm := normalize_rgba8(color)
ve.set_colour( & font_provider_data.ve_font_cache, color_norm )
ve.draw_text( & font_provider_data.ve_font_cache, ve_id, content, pos, Vec2{1 / width, 1 / height} * scale )
@ -665,21 +681,47 @@ draw_text_string_pos_extent :: proc( content : string, id : FontID, size : f32,
draw_text_string_pos_extent_zoomed :: proc( content : string, id : FontID, size : f32, pos : Vec2, cam : Camera, color := Color_White )
{
state := get_state(); using state
// profile(#procedure)
cam_offset := Vec2 {
cam.position.x,
cam.position.y,
}
pos_offset := pos + cam_offset * cam.zoom
pos_offset := (pos + cam_offset)
cam_zoom_ratio := 1 / cam.zoom
state := get_state(); using state
screen_size := app_window.extent * 2
render_pos := screen_to_render_pos(pos_offset)
normalized_pos := render_pos * (1.0 / screen_size)
draw_text_string_pos_norm( content, id, size * cam.zoom, normalized_pos, color, cam.zoom )
screen_scale := (1.0 / screen_size)
render_pos := ws_view_to_render_pos(pos)
normalized_pos := render_pos * screen_scale
// Oversample font-size for any render under a camera
over_sample : f32 = 2.0
zoom_adjust_size := size * cam.zoom
zoom_adjust_size *= over_sample
ve_id, resolved_size := font_provider_resolve_draw_id( id, zoom_adjust_size )
text_scale : Vec2 = screen_scale
// if config.cam_zoom_mode == .Smooth
{
f32_resolved_size := f32(resolved_size)
diff_scalar := 1 + (zoom_adjust_size - f32_resolved_size) / f32_resolved_size
text_scale = diff_scalar * screen_scale
text_scale.x = clamp( text_scale.x, 0, screen_size.x )
text_scale.y = clamp( text_scale.y, 0, screen_size.y )
}
// Downsample back
text_scale /= over_sample
color_norm := normalize_rgba8(color)
// logf("zoom_adjust_size: %v", zoom_adjust_size)
ve.set_colour( & font_provider_data.ve_font_cache, color_norm )
ve.draw_text( & font_provider_data.ve_font_cache, ve_id, content, normalized_pos, text_scale )
}
// TODO(Ed): Eventually the workspace will need a viewport for drawing text

View File

@ -164,10 +164,10 @@ update :: proc( delta_time : f64 ) -> b32
workspace.zoom_target = cam.zoom
}
config.cam_max_zoom = 30
config.cam_zoom_sensitivity_digital = 0.04
// config.cam_min_zoom = 0.04
config.cam_zoom_sensitivity_smooth = 0.02
config.cam_max_zoom = 10
config.cam_min_zoom = 0.10
config.cam_zoom_sensitivity_digital = 0.05
config.cam_zoom_sensitivity_smooth = 2.0
config.cam_zoom_mode = .Smooth
switch config.cam_zoom_mode
{
@ -181,7 +181,7 @@ update :: proc( delta_time : f64 ) -> b32
cam.zoom += (workspace.zoom_target - cam.zoom) * lerp_factor * f32(delta_time)
cam.zoom = clamp(cam.zoom, config.cam_min_zoom, config.cam_max_zoom) // Ensure cam.zoom stays within bounds
case .Digital:
zoom_delta := input.mouse.scroll.y * config.cam_zoom_sensitivity_digital
zoom_delta := clamp(input.mouse.scroll.y, -1, 1) * config.cam_zoom_sensitivity_digital
workspace.zoom_target = clamp(workspace.zoom_target + zoom_delta, config.cam_min_zoom, config.cam_max_zoom)
cam.zoom = workspace.zoom_target
}
@ -225,7 +225,7 @@ update :: proc( delta_time : f64 ) -> b32
flags = frame_style_flags,
anchor = {},
// alignment = { 0.5, 0.5 },
font_size = 30,
font_size = 12,
text_alignment = { 0.0, 0.0 },
// corner_radii = { 0.2, 0.2, 0.2, 0.2 },
pos = { 0, 0 },
@ -249,7 +249,7 @@ update :: proc( delta_time : f64 ) -> b32
// test_draggable()
// test_text_box()
// test_parenting( & default_layout, & frame_style_default )
// test_whitespace_ast( & default_layout, & frame_style_default )
test_whitespace_ast( & default_layout, & frame_style_default )
}
//endregion Workspace Imgui Tick