diff --git a/code/font/VEFontCache/VEFontCache.odin b/code/font/VEFontCache/VEFontCache.odin index e941a6c..cfd4468 100644 --- a/code/font/VEFontCache/VEFontCache.odin +++ b/code/font/VEFontCache/VEFontCache.odin @@ -122,9 +122,13 @@ font_key_from_label :: #force_inline proc( label : string ) -> u64 { // ve_fontcache_eval_bezier (quadratic) eval_point_on_bezier3 :: proc( p0, p1, p2 : Vec2, alpha : f32 ) -> Vec2 { - starting_point := p0 * (1 - alpha) * (1 - alpha) - control_point := p1 * 2.0 * (1 - alpha) * alpha - end_point := p2 * alpha * alpha + weight_start := (1 - alpha) * (1 - alpha) + weight_control := 2.0 * (1 - alpha) * alpha + weight_end := alpha * alpha + + starting_point := p0 * weight_start + control_point := p1 * weight_control + end_point := p2 * weight_end point := starting_point + control_point + end_point return point @@ -618,15 +622,15 @@ cache_glyph_to_atlas :: proc( ctx : ^Context, font : FontID, glyph_index : Glyph dst_size := Vec2 { dst_width, dst_height } dst_glyph_size := Vec2 { dst_glyph_width, dst_glyph_height } - screenspace_x_form( & dst_glyph_position, & dst_glyph_size, f32(atlas.buffer_width), f32(atlas.buffer_height) ) - screenspace_x_form( & dst_position, & dst_size, f32(atlas.buffer_width), f32(atlas.buffer_height) ) + screenspace_x_form( & dst_glyph_position, & dst_glyph_size, f32(atlas.width), f32(atlas.height) ) + screenspace_x_form( & dst_position, & dst_size, f32(atlas.width), f32(atlas.height) ) src_position := Vec2 { f32(atlas.update_batch_x), 0 } src_size := Vec2 { f32(bounds_width) * glyph_draw_scale.x, f32(bounds_height) * glyph_draw_scale.y, } - src_size += Vec2{1,1} * 2 * over_sample * glyph_padding + src_size += 2 * over_sample * glyph_padding textspace_x_form( & src_position, & src_size, f32(atlas.buffer_width), f32(atlas.buffer_height) ) // Advance glyph_update_batch_x and calculate final glyph drawing transform @@ -781,5 +785,7 @@ shape_text_uncached :: proc( ctx : ^Context, font : FontID, output : ^ShapedText position.x += f32(advance) * entry.size_scale prev_codepoint = codepoint } + + output.end_cursor_pos = position } } diff --git a/code/font/VEFontCache/draw.odin b/code/font/VEFontCache/draw.odin index 1e900b8..b025fd8 100644 --- a/code/font/VEFontCache/draw.odin +++ b/code/font/VEFontCache/draw.odin @@ -80,6 +80,10 @@ blit_quad :: proc( draw_list : ^DrawList, p0, p1 : Vec2, uv0, uv1 : Vec2 ) for index : i32 = 0; index < 6; index += 1 { append( & draw_list.indices, v_offset + quad_indices[ index ] ) } + + draw_list_vert_slice := array_to_slice(draw_list.vertices) + draw_list_index_slice := array_to_slice(draw_list.indices) + return } // ve_fontcache_clear_drawlist @@ -175,9 +179,9 @@ draw_cached_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph, atlas := & ctx.atlas // Figure out the source bounding box in the atlas texture - position, width, height := atlas_bbox( atlas, region_kind, u32(atlas_index) ) + atlas_position, atlas_width, atlas_height := atlas_bbox( atlas, region_kind, u32(atlas_index) ) - glyph_position := position + glyph_position := atlas_position glyph_width := f32(bounds_width) * entry.size_scale glyph_height := f32(bounds_height) * entry.size_scale @@ -186,6 +190,10 @@ draw_cached_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph, glyph_scale := Vec2 { glyph_width, glyph_height } bounds_0_scaled := Vec2{ f32(bounds_0.x), f32(bounds_0.y) } * entry.size_scale - { 0.5, 0.5 } + bounds_0_scaled = { + cast(f32) cast(i32) bounds_0_scaled.x, + cast(f32) cast(i32) bounds_0_scaled.y, + } dst := Vec2 { position.x + scale.x * bounds_0_scaled.x, position.y + scale.y * bounds_0_scaled.y, @@ -194,7 +202,7 @@ draw_cached_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph, dst_height := scale.y * glyph_height dst -= scale * { f32(atlas.glyph_padding), f32(atlas.glyph_padding) } dst_scale := Vec2 { dst_width, dst_height } - textspace_x_form( & glyph_position, & dst_scale, f32(atlas.buffer_width), f32(atlas.buffer_height) ) + textspace_x_form( & glyph_position, & glyph_scale, f32(atlas.width), f32(atlas.height) ) // Add the glyph drawcall call := DrawCall_Default @@ -209,12 +217,13 @@ draw_cached_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph, } append( & ctx.draw_list.calls, call ) + // NOTE(Ed): Never done in the original // Clear glyph_update_FBO - call.pass = .Glyph - call.start_index = 0 - call.end_index = 0 - call.clear_before_draw = true - append( & ctx.draw_list.calls, call ) + // call.pass = .Glyph + // call.start_index = 0 + // call.end_index = 0 + // call.clear_before_draw = true + // append( & ctx.draw_list.calls, call ) return true } @@ -279,8 +288,8 @@ draw_text :: proc( ctx : ^Context, font : FontID, text_utf8 : string, position : snap_height := f32(ctx.snap_height) position := position - if ctx.snap_width > 0 do position.x = (position.x * snap_width + 0.5) / snap_width - if ctx.snap_height > 0 do position.y = (position.y * snap_height + 0.5) / snap_height + if ctx.snap_width > 0 do position.x = cast(f32) cast(u32) (position.x * snap_width + 0.5) / snap_width + if ctx.snap_height > 0 do position.y = cast(f32) cast(u32) (position.y * snap_height + 0.5) / snap_height entry := & ctx.entries.data[ font ] @@ -319,9 +328,9 @@ draw_text_batch :: proc( ctx : ^Context, entry : ^Entry, shaped : ^ShapedText, b { glyph_index := shaped.glyphs.data[ index ] shaped_position := shaped.positions.data[index] - glyph_translate_x := position.x + shaped_position.x * scale.x - glyph_translate_y := position.y + shaped_position.y * scale.y - glyph_cached := draw_cached_glyph( ctx, entry, glyph_index, {glyph_translate_x, glyph_translate_y}, scale) + // glyph_translate_x := position.x + shaped_position.x * scale.x + glyph_translate := position + shaped_position * scale + glyph_cached := draw_cached_glyph( ctx, entry, glyph_index, glyph_translate, scale) assert( glyph_cached == true ) } } diff --git a/code/sectr/engine/render_vefc.odin b/code/sectr/engine/render_vefc.odin index a857cdb..48bc593 100644 --- a/code/sectr/engine/render_vefc.odin +++ b/code/sectr/engine/render_vefc.odin @@ -92,7 +92,7 @@ render :: proc() ve.set_colour( & ve_font_cache, { 1.0, 1.0, 1.0, 1.0 } ) ve.configure_snap( & ve_font_cache, u32(state.app_window.extent.x * 2.0), u32(state.app_window.extent.y * 2.0) ) - ve.draw_text( & ve_font_cache, fdef.ve_id, text_test_str, {0.4, 0.1}, Vec2{1 / width, 1 / height} ) + ve.draw_text( & ve_font_cache, fdef.ve_id, text_test_str, {0.5, 0.0}, Vec2{1 / width, 1 / height} ) } // Process the draw calls for drawing text @@ -109,6 +109,7 @@ render :: proc() draw_list_call_slice := array_to_slice(draw_list.calls) for & draw_call in array_to_slice(draw_list.calls) { + watch := draw_call profile("ve draw call") if (draw_call.end_index - draw_call.start_index) == 0 do continue @@ -128,8 +129,8 @@ render :: proc() } sokol_gfx.begin_pass( pass ) - sokol_gfx.apply_viewport( 0,0, width, height, origin_top_left = true ) - sokol_gfx.apply_scissor_rect( 0,0, width, height, origin_top_left = true ) + // sokol_gfx.apply_viewport( 0,0, width, height, origin_top_left = true ) + // sokol_gfx.apply_scissor_rect( 0,0, width, height, origin_top_left = true ) sokol_gfx.apply_pipeline( glyph_pipeline ) @@ -141,7 +142,7 @@ render :: proc() 0 = 0, }, index_buffer = draw_list_ibuf, - index_buffer_offset = i32(draw_call.start_index), + index_buffer_offset = 0,//i32(draw_call.start_index), fs = {}, } sokol_gfx.apply_bindings( bindings ) @@ -160,13 +161,13 @@ render :: proc() pass := atlas_pass if draw_call.clear_before_draw { - pass.action.colors[0].load_action = .CLEAR - // pass.action.colors[0].clear_value.a = 0.0 + pass.action.colors[0].load_action = .CLEAR + pass.action.colors[0].clear_value.a = 1.0 } sokol_gfx.begin_pass( pass ) - sokol_gfx.apply_viewport( 0, 0, width, height, origin_top_left = true ) - sokol_gfx.apply_scissor_rect( 0, 0, width, height, origin_top_left = true ) + // sokol_gfx.apply_viewport( 0, 0, width, height, origin_top_left = true ) + // sokol_gfx.apply_scissor_rect( 0, 0, width, height, origin_top_left = true ) sokol_gfx.apply_pipeline( atlas_pipeline ) @@ -181,7 +182,7 @@ render :: proc() 0 = 0, }, index_buffer = draw_list_ibuf, - index_buffer_offset = i32(draw_call.start_index), + index_buffer_offset = 0,//i32(draw_call.start_index), fs = { images = { SLOT_ve_blit_atlas_src_texture = glyph_rt_color, }, samplers = { SLOT_ve_blit_atlas_src_sampler = gfx_sampler, }, @@ -198,14 +199,14 @@ render :: proc() pass := screen_pass if ! draw_call.clear_before_draw { - pass.action.colors[0].load_action = .LOAD - // pass.action.colors[0].clear_value.a = 0.0 + pass.action.colors[0].load_action = .LOAD + pass.action.colors[0].clear_value.a = 0.0 } pass.swapchain = sokol_glue.swapchain() sokol_gfx.begin_pass( pass ) - sokol_gfx.apply_viewport( 0, 0, width, height, origin_top_left = true ) - sokol_gfx.apply_scissor_rect( 0, 0, width, height, origin_top_left = true ) + // sokol_gfx.apply_viewport( 0, 0, width, height, origin_top_left = true ) + // sokol_gfx.apply_scissor_rect( 0, 0, width, height, origin_top_left = true ) sokol_gfx.apply_pipeline( screen_pipeline ) @@ -222,7 +223,7 @@ render :: proc() 0 = 0, }, index_buffer = draw_list_ibuf, - index_buffer_offset = i32(draw_call.start_index), + index_buffer_offset = 0,//i32(draw_call.start_index), fs = { images = { SLOT_ve_draw_text_src_texture = src_rt, }, samplers = { SLOT_ve_draw_text_src_sampler = gfx_sampler, }, diff --git a/code/sectr/font/provider_VEFontCache.odin b/code/sectr/font/provider_VEFontCache.odin index 6ea5a2a..2efd944 100644 --- a/code/sectr/font/provider_VEFontCache.odin +++ b/code/sectr/font/provider_VEFontCache.odin @@ -164,8 +164,6 @@ font_provider_startup :: proc() enabled = true, src_factor_rgb = .ONE_MINUS_DST_COLOR, dst_factor_rgb = .ONE_MINUS_SRC_COLOR, - // src_factor_rgb = .SRC_ALPHA, - // dst_factor_rgb = .ONE_MINUS_SRC_ALPHA, op_rgb = BlendOp.ADD, src_factor_alpha = BlendFactor.ONE, dst_factor_alpha = BlendFactor.ZERO, @@ -183,6 +181,7 @@ font_provider_startup :: proc() color_count = 1, depth = { pixel_format = .DEPTH, + // compare = .ALWAYS, }, // sample_count = 1, // label = @@ -237,9 +236,10 @@ font_provider_startup :: proc() glyph_action := PassAction { colors = { 0 = { - load_action = .DONTCARE, + load_action = .CLEAR, store_action = .STORE, - clear_value = {0,0,0,1}, + clear_value = {0.01,0.01,0.01,1}, + // clear_value = {0.00, 0.00, 0.00, 0.00}, } } } @@ -296,6 +296,7 @@ font_provider_startup :: proc() color_count = 1, depth = { pixel_format = .DEPTH, + compare = .ALWAYS, }, // sample_count = 1, }) @@ -351,7 +352,7 @@ font_provider_startup :: proc() 0 = { load_action = .LOAD, store_action = .STORE, - clear_value = {0,0,0,1}, + clear_value = {0,0,0,1.0}, } } } @@ -418,7 +419,7 @@ font_provider_startup :: proc() 0 = { load_action = .CLEAR, store_action = .STORE, - clear_value = {0,0,0,0}, + clear_value = {1.0,0.0,0.0,1.0}, } } } diff --git a/code/sectr/shaders/ve_draw_text.odin b/code/sectr/shaders/ve_draw_text.odin index 886f2fe..a3a5fce 100644 --- a/code/sectr/shaders/ve_draw_text.odin +++ b/code/sectr/shaders/ve_draw_text.odin @@ -389,10 +389,10 @@ ve_draw_text_shader_desc :: proc (backend: sg.Backend) -> sg.Shader_Desc { desc.fs.uniform_blocks[0].layout = .STD140 desc.fs.uniform_blocks[0].uniforms[0].name = "_31.down_sample" desc.fs.uniform_blocks[0].uniforms[0].type = .INT - // array_count = desc.fs.uniform_blocks[0].uniforms[0] + // .array_count = desc.fs.uniform_blocks[0].uniforms[0] desc.fs.uniform_blocks[0].uniforms[1].name = "_31.colour" desc.fs.uniform_blocks[0].uniforms[1].type = .FLOAT4 - // array_count = desc.fs.uniform_blocks[0].uniforms[1] + // .array_count = desc.fs.uniform_blocks[0].uniforms[1] desc.fs.images[0].used = true desc.fs.images[0].multisampled = false desc.fs.images[0].image_type = ._2D