Progress on fleshing out rendering (Getting ui ready to render in "layer batches")

This commit is contained in:
2024-06-23 02:47:13 -04:00
parent 136fef65c4
commit ce1d31f0d4
11 changed files with 317 additions and 80 deletions

View File

@ -241,6 +241,10 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
load_action = .CLEAR,
clear_value = { 0, 0, 0, 1 }
}
render_data.pass_actions.empty_action.colors[0] = sokol_gfx.Color_Attachment_Action {
load_action = .LOAD,
clear_value = { 0, 0, 0, 1 }
}
}
// Setup sokol_gp
@ -277,7 +281,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
}
// Setup the screen ui state
if false
if true
{
ui_startup( & screen_ui.base, cache_allocator = persistent_slab_allocator() )
ui_floating_startup( & screen_ui.floating, 1 * Kilobyte, 1 * Kilobyte, persistent_slab_allocator(), "screen ui floating manager" )
@ -292,7 +296,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem
// Demo project setup
// TODO(Ed): This will eventually have to occur when the user either creates or loads a workspace. I don't know
if false
if true
{
using project
path = str_intern("./")

View File

@ -11,13 +11,45 @@ import gp "thirdparty:sokol/gp"
PassActions :: struct {
bg_clear_black : gfx.Pass_Action,
empty_action : gfx.Pass_Action,
}
RenderState :: struct {
pass_actions : PassActions,
}
gp_set_color :: #force_inline proc( color : RGBA8 ) {
color := normalize_rgba8(color);
gp.set_color( color.r, color.g, color.b, color.a )
}
draw_filled_circle :: proc(x, y, radius: f32, edges: int) {
if edges < 3 do return // Need at least 3 edges to form a shape
triangles := make([]gp.Triangle, edges)
// defer delete(triangles)
center := gp.Point{x, y}
for i in 0..<edges {
angle1 := 2 * math.PI * f32(i) / f32(edges)
angle2 := 2 * math.PI * f32(i+1) / f32(edges)
p1 := gp.Point{
x + radius * math.cos(angle1),
y + radius * math.sin(angle1),
}
p2 := gp.Point{
x + radius * math.cos(angle2),
y + radius * math.sin(angle2),
}
triangles[i] = gp.Triangle{center, p1, p2}
}
gp.draw_filled_triangles(raw_data(triangles), u32(len(triangles)))
}
// Draw text using a string and normalized screen coordinates
draw_text_string_pos_norm :: proc( content : string, id : FontID, size : f32, pos : Vec2, color := Color_White )
{
@ -69,6 +101,28 @@ render_mode_2d_workspace :: proc()
profile(#procedure)
state := get_state(); using state // TODO(Ed): Prefer passing static context to through the callstack
cam := & project.workspace.cam
screen_extent := app_window.extent
screen_size := app_window.extent * 2
screen_ratio := screen_size.x * ( 1.0 / screen_size.y )
cam_zoom_ratio := 1.0 / cam.zoom
gp.begin( i32(screen_size.x), i32(screen_size.y) )
gp.viewport(0, 0, i32(screen_size.x), i32(screen_size.y))
gp.project( -screen_extent.x, screen_extent.x, screen_extent.y, -screen_extent.y )
gp.translate( cam.position.x * cam.zoom, cam.position.y * cam.zoom )
gp.scale( cam.zoom, cam.zoom )
gp_set_color(Color_White)
draw_filled_circle(0, 0, 4, 24)
// Enqueue gp pass to sokol gfx
gfx.begin_pass( gfx.Pass { action = render_data.pass_actions.empty_action, swapchain = sokol_glue.swapchain() })
gp.flush()
gp.end()
gfx.end_pass()
}
render_mode_screenspace :: proc()
@ -83,6 +137,23 @@ render_mode_screenspace :: proc()
render_screen_ui()
screen_extent := app_window.extent
screen_size := app_window.extent * 2
screen_ratio := screen_size.x * ( 1.0 / screen_size.y )
gp.begin( i32(screen_size.x), i32(screen_size.y) )
gp.viewport(0, 0, i32(screen_size.x), i32(screen_size.y))
gp.project( -screen_extent.x, screen_extent.x, screen_extent.y, -screen_extent.y )
gp_set_color(Color_Screen_Center_Dot)
draw_filled_circle(0, 0, 2, 24)
gfx.begin_pass( gfx.Pass { action = render_data.pass_actions.empty_action, swapchain = sokol_glue.swapchain() })
gp.flush()
gp.end()
gfx.end_pass()
debug_draw_text :: proc( content : string, pos : Vec2, size : f32, color := Color_White, font : FontID = Font_Default )
{
state := get_state(); using state
@ -125,7 +196,7 @@ render_mode_screenspace :: proc()
debug.debug_text_vis = true
if debug.debug_text_vis
{
fps_msg := str_fmt( "FPS: %d", frame)
fps_msg := str_fmt( "FPS: %0.2f", fps_avg)
fps_msg_width := measure_text_size( fps_msg, default_font, 12.0, 0.0 ).x
fps_msg_pos := screen_get_corners().top_right - { fps_msg_width, 0 } - { 5, 5 }
debug_draw_text( fps_msg, fps_msg_pos, 38.0, color = Color_Red )
@ -133,7 +204,7 @@ render_mode_screenspace :: proc()
// debug_text( "Screen Width : %v", rl.GetScreenWidth () )
// debug_text( "Screen Height: %v", rl.GetScreenHeight() )
// debug_text( "frametime_target_ms : %f ms", frametime_target_ms )
debug_text( "frametime : %d ms", frame )
debug_text( "frametime : %0.3f ms", frametime_delta32() )
// debug_text( "frametime_last_elapsed_ms : %f ms", frametime_elapsed_ms )
if replay.mode == ReplayMode.Record {
debug_text( "Recording Input")
@ -153,6 +224,40 @@ render_mode_screenspace :: proc()
// rl.DrawCircleV( screen_to_render_pos(input.mouse.pos), 2, Color_BG )
}
if false
{
ui := & project.workspace.ui
debug_text("Box Count (Workspace): %v", ui.built_box_count )
hot_box := ui_box_from_key( ui.curr_cache, ui.hot )
active_box := ui_box_from_key( ui.curr_cache, ui.active )
if hot_box != nil {
debug_text("Worksapce Hot Box : %v", hot_box.label.str )
debug_text("Workspace Hot Range2: %v", hot_box.computed.bounds.pts)
}
if active_box != nil{
debug_text("Workspace Active Box: %v", active_box.label.str )
}
}
if false
{
ui := & screen_ui
debug_text("Box Count: %v", ui.built_box_count )
hot_box := ui_box_from_key( ui.curr_cache, ui.hot )
active_box := ui_box_from_key( ui.curr_cache, ui.active )
if hot_box != nil {
debug_text("Hot Box : %v", hot_box.label.str )
debug_text("Hot Range2: %v", hot_box.computed.bounds.pts)
}
if active_box != nil{
debug_text("Active Box: %v", active_box.label.str )
}
}
render_text_layer()
}

View File

@ -166,8 +166,8 @@ update :: proc( delta_time : f64 ) -> b32
config.cam_max_zoom = 30
config.cam_zoom_sensitivity_digital = 0.04
config.cam_min_zoom = 0.04
config.cam_zoom_mode = .Digital
// config.cam_min_zoom = 0.04
config.cam_zoom_mode = .Smooth
switch config.cam_zoom_mode
{
case .Smooth:
@ -196,7 +196,7 @@ update :: proc( delta_time : f64 ) -> b32
{
if is_within_screenspace(input.mouse.pos) {
pan_velocity := input.mouse.delta * vec2(1, -1) * ( 1 / cam.zoom )
cam.position -= pan_velocity
cam.position += pan_velocity
}
}
}