diff --git a/code/font/VEFontCache/VEFontCache.odin b/code/font/VEFontCache/VEFontCache.odin index 2aff1eb..1b39fa9 100644 --- a/code/font/VEFontCache/VEFontCache.odin +++ b/code/font/VEFontCache/VEFontCache.odin @@ -25,7 +25,7 @@ Glyph :: distinct i32 Colour :: [4]f32 Vec2 :: [2]f32 -Vec2i :: [2]u32 +Vec2i :: [2]i32 AtlasRegionKind :: enum u8 { None = 0x00, @@ -139,10 +139,15 @@ eval_point_on_bezier3 :: proc( p0, p1, p2 : Vec2, alpha : f32 ) -> Vec2 // ve_fontcache_eval_bezier (cubic) eval_point_on_bezier4 :: proc( p0, p1, p2, p3 : Vec2, alpha : f32 ) -> Vec2 { - start_point := p0 * (1 - alpha) * (1 - alpha) * (1 - alpha) - control_a := p1 * 3 * (1 - alpha) * (1 - alpha) * alpha - control_b := p2 * 3 * (1 - alpha) * alpha * alpha - end_point := p3 * alpha * alpha * alpha + weight_start := (1 - alpha) * (1 - alpha) * (1 - alpha) + weight_c_a := 3 * (1 - alpha) * (1 - alpha) * alpha + weight_c_b := 3 * (1 - alpha) * alpha * alpha + weight_end := alpha * alpha * alpha + + start_point := p0 * weight_start + control_a := p1 * weight_c_a + control_b := p2 * weight_c_b + end_point := p3 * weight_end point := start_point + control_a + control_b + end_point return point @@ -265,26 +270,26 @@ init :: proc( ctx : ^Context, parser_kind : ParserKind, draw_list.calls, error = make( Array(DrawCall), 512 ) assert(error == .None, "VEFontCache.init : Failed to allocate draw_list.calls") - init_atlas_region :: proc( region : ^AtlasRegion, params : InitAtlasParams, region_params : InitAtlasRegionParams, factor : Vec2i, expected_cap : u32 ) { + init_atlas_region :: proc( region : ^AtlasRegion, params : InitAtlasParams, region_params : InitAtlasRegionParams, factor : Vec2i, expected_cap : i32 ) { using region next_idx = 0; width = region_params.width height = region_params.height size = { - params.width / factor.x, - params.height / factor.y, + i32(params.width) / factor.x, + i32(params.height) / factor.y, } capacity = { - size.x / width, - size.y / height, + size.x / i32(width), + size.y / i32(height), } assert( capacity.x * capacity.y == expected_cap ) error : AllocatorError // state.cache, error = make( HMapChained(LRU_Link), uint(capacity.x * capacity.y) ) // assert( error == .None, "VEFontCache.init_atlas_region : Failed to allocate state.cache") - LRU_init( & state, capacity.x * capacity.y ) + LRU_init( & state, u32(capacity.x * capacity.y) ) } init_atlas_region( & atlas.region_a, atlas_params, atlas_params.region_a, { 4, 2}, 1024 ) init_atlas_region( & atlas.region_b, atlas_params, atlas_params.region_b, { 4, 2}, 512 ) @@ -300,7 +305,7 @@ init :: proc( ctx : ^Context, parser_kind : ParserKind, atlas.region_b.offset.y = atlas.region_a.size.y atlas.region_c.offset.x = atlas.region_a.size.x atlas.region_c.offset.y = 0 - atlas.region_d.offset.x = atlas.width / 2 + atlas.region_d.offset.x = i32(atlas.width) / 2 atlas.region_d.offset.y = 0 LRU_init( & shape_cache.state, shape_cache_params.capacity ) @@ -606,7 +611,7 @@ cache_glyph_to_atlas :: proc( ctx : ^Context, font : FontID, glyph_index : Glyph // Draw oversized glyph to update FBO glyph_draw_scale := over_sample * entry.size_scale - glyph_draw_translate := Vec2 { f32(-bounds_0.x), f32(-bounds_0.y) } * glyph_draw_scale + Vec2{ glyph_padding, glyph_padding } + glyph_draw_translate := Vec2 { -f32(bounds_0.x), -f32(bounds_0.y) } * glyph_draw_scale + Vec2{ glyph_padding, glyph_padding } glyph_draw_translate.x = cast(f32) (i32(glyph_draw_translate.x + 0.9999999)) glyph_draw_translate.y = cast(f32) (i32(glyph_draw_translate.y + 0.9999999)) @@ -617,7 +622,7 @@ cache_glyph_to_atlas :: proc( ctx : ^Context, font : FontID, glyph_index : Glyph } // Calculate the src and destination regions - dst_position, dst_width, dst_height := atlas_bbox( atlas, region_kind, u32(atlas_index) ) + dst_position, dst_width, dst_height := atlas_bbox( atlas, region_kind, atlas_index ) dst_glyph_position := dst_position + { glyph_padding, glyph_padding } dst_glyph_width := f32(bounds_width) * entry.size_scale dst_glyph_height := f32(bounds_height) * entry.size_scale diff --git a/code/font/VEFontCache/atlas.odin b/code/font/VEFontCache/atlas.odin index a178b54..67584ad 100644 --- a/code/font/VEFontCache/atlas.odin +++ b/code/font/VEFontCache/atlas.odin @@ -27,7 +27,7 @@ Atlas :: struct { using glyph_update_batch : GlyphDrawBuffer, } -atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : u32 ) -> (position : Vec2, width, height : f32) +atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : i32 ) -> (position : Vec2, width, height : f32) { switch region { @@ -35,8 +35,8 @@ atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : u32 ) width = f32(atlas.region_a.width) height = f32(atlas.region_b.height) - position.x = cast(f32) (( local_idx % atlas.region_a.capacity.x ) * atlas.region_a.width) - position.y = cast(f32) (( local_idx / atlas.region_a.capacity.x ) * atlas.region_a.height) + position.x = cast(f32) (( local_idx % atlas.region_a.capacity.x ) * i32(atlas.region_a.width)) + position.y = cast(f32) (( local_idx / atlas.region_a.capacity.x ) * i32(atlas.region_a.height)) position.x += f32(atlas.region_a.offset.x) position.y += f32(atlas.region_a.offset.y) @@ -45,8 +45,8 @@ atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : u32 ) width = f32(atlas.region_b.width) height = f32(atlas.region_b.height) - position.x = cast(f32) (( local_idx % atlas.region_b.capacity.x ) * atlas.region_b.width) - position.y = cast(f32) (( local_idx / atlas.region_b.capacity.x ) * atlas.region_b.height) + position.x = cast(f32) (( local_idx % atlas.region_b.capacity.x ) * i32(atlas.region_b.width)) + position.y = cast(f32) (( local_idx / atlas.region_b.capacity.x ) * i32(atlas.region_b.height)) position.x += f32(atlas.region_b.offset.x) position.y += f32(atlas.region_b.offset.y) @@ -55,8 +55,8 @@ atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : u32 ) width = f32(atlas.region_c.width) height = f32(atlas.region_c.height) - position.x = cast(f32) (( local_idx % atlas.region_c.capacity.x ) * atlas.region_c.width) - position.y = cast(f32) (( local_idx / atlas.region_c.capacity.x ) * atlas.region_c.height) + position.x = cast(f32) (( local_idx % atlas.region_c.capacity.x ) * i32(atlas.region_c.width)) + position.y = cast(f32) (( local_idx / atlas.region_c.capacity.x ) * i32(atlas.region_c.height)) position.x += f32(atlas.region_c.offset.x) position.y += f32(atlas.region_c.offset.y) @@ -65,8 +65,8 @@ atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : u32 ) width = f32(atlas.region_d.width) height = f32(atlas.region_d.height) - position.x = cast(f32) (( local_idx % atlas.region_d.capacity.x ) * atlas.region_d.width) - position.y = cast(f32) (( local_idx / atlas.region_d.capacity.x ) * atlas.region_d.height) + position.x = cast(f32) (( local_idx % atlas.region_d.capacity.x ) * i32(atlas.region_d.width)) + position.y = cast(f32) (( local_idx / atlas.region_d.capacity.x ) * i32(atlas.region_d.height)) position.x += f32(atlas.region_d.offset.x) position.y += f32(atlas.region_d.offset.y) diff --git a/code/font/VEFontCache/draw.odin b/code/font/VEFontCache/draw.odin index 8cc4022..f43576e 100644 --- a/code/font/VEFontCache/draw.odin +++ b/code/font/VEFontCache/draw.odin @@ -93,13 +93,13 @@ clear_draw_list :: proc( draw_list : ^DrawList ) { clear( draw_list.vertices ) } -directly_draw_massive_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph : Glyph, bounds_0 : Vec2i, bounds_width, bounds_height : u32, over_sample, position, scale : Vec2 ) +directly_draw_massive_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph : Glyph, bounds_0 : Vec2i, bounds_width, bounds_height : i32, over_sample, position, scale : Vec2 ) { flush_glyph_buffer_to_atlas( ctx ) // Draw un-antialiased glyph to update FBO. glyph_draw_scale := over_sample * entry.size_scale - glyph_draw_translate := Vec2{ f32(-bounds_0.x), f32(-bounds_0.y)} * glyph_draw_scale + Vec2{ f32(ctx.atlas.glyph_padding), f32(ctx.atlas.glyph_padding) } + glyph_draw_translate := Vec2{ -f32(bounds_0.x), -f32(bounds_0.y)} * glyph_draw_scale + Vec2{ f32(ctx.atlas.glyph_padding), f32(ctx.atlas.glyph_padding) } screenspace_x_form( & glyph_draw_translate, & glyph_draw_scale, f32(ctx.atlas.buffer_width), f32(ctx.atlas.buffer_height) ) cache_glyph( ctx, entry.id, glyph, glyph_draw_scale, glyph_draw_translate ) @@ -182,7 +182,7 @@ draw_cached_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph, atlas := & ctx.atlas // Figure out the source bounding box in the atlas texture - atlas_position, atlas_width, atlas_height := atlas_bbox( atlas, region_kind, u32(atlas_index) ) + atlas_position, atlas_width, atlas_height := atlas_bbox( atlas, region_kind, atlas_index ) glyph_position := atlas_position glyph_width := f32(bounds_width) * entry.size_scale diff --git a/code/font/VEFontCache/parser.odin b/code/font/VEFontCache/parser.odin index fed113b..0ceae88 100644 --- a/code/font/VEFontCache/parser.odin +++ b/code/font/VEFontCache/parser.odin @@ -203,16 +203,16 @@ parser_get_glyph_box :: proc( font : ^ParserFontInfo, glyph_index : Glyph ) -> ( metrics := font.freetype_info.glyph.metrics - bounds_0 = {u32(metrics.hori_bearing_x), u32(metrics.hori_bearing_y - metrics.height)} - bounds_1 = {u32(metrics.hori_bearing_x + metrics.width), u32(metrics.hori_bearing_y)} + bounds_0 = {i32(metrics.hori_bearing_x), i32(metrics.hori_bearing_y - metrics.height)} + bounds_1 = {i32(metrics.hori_bearing_x + metrics.width), i32(metrics.hori_bearing_y)} case .STB_TrueType: x0, y0, x1, y1 : i32 success := cast(bool) stbtt.GetGlyphBox( & font.stbtt_info, i32(glyph_index), & x0, & y0, & x1, & y1 ) assert( success ) - bounds_0 = { u32(x0), u32(y0) } - bounds_1 = { u32(x1), u32(y1) } + bounds_0 = { i32(x0), i32(y0) } + bounds_1 = { i32(x1), i32(y1) } } return } diff --git a/code/sectr/engine/render_vefc.odin b/code/sectr/engine/render_vefc.odin index 616366f..61bf153 100644 --- a/code/sectr/engine/render_vefc.odin +++ b/code/sectr/engine/render_vefc.odin @@ -81,7 +81,7 @@ render :: proc() { // text_test_str := str_fmt("frametime: %v", frametime_avg_ms) // text_test_str := str_fmt("HELLO VE FONT CACHE!!!!!") - text_test_str := str_fmt("AB") + text_test_str := str_fmt("C") // font_provider := & state.font_provider_data fdef := hmap_chained_get( font_cache, default_font.key ) @@ -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.2, 0.4}, Vec2{1 / width, 1 / height} ) + ve.draw_text( & ve_font_cache, fdef.ve_id, text_test_str, {0.1, 0.2}, Vec2{1 / width, 1 / height} ) } // Process the draw calls for drawing text @@ -111,7 +111,6 @@ render :: proc() { watch := draw_call profile("ve draw call") - if (draw_call.end_index - draw_call.start_index) == 0 do continue switch draw_call.pass { @@ -236,8 +235,10 @@ render :: proc() }) } - num_indices := draw_call.end_index - draw_call.start_index - sokol_gfx.draw( draw_call.start_index, num_indices, 1 ) + if (draw_call.end_index - draw_call.start_index) != 0 { + num_indices := draw_call.end_index - draw_call.start_index + sokol_gfx.draw( draw_call.start_index, num_indices, 1 ) + } sokol_gfx.end_pass() } diff --git a/code/sectr/font/provider_VEFontCache.odin b/code/sectr/font/provider_VEFontCache.odin index 2c4489c..889dc48 100644 --- a/code/sectr/font/provider_VEFontCache.odin +++ b/code/sectr/font/provider_VEFontCache.odin @@ -241,7 +241,7 @@ font_provider_startup :: proc() glyph_action := PassAction { colors = { 0 = { - load_action = .CLEAR, + load_action = .LOAD, store_action = .STORE, // clear_value = {0.01,0.01,0.01,1}, clear_value = {0.00, 0.00, 0.00, 1.00}, @@ -506,7 +506,7 @@ font_load :: proc(path_file : string, def.path_file = path_file // TODO(Ed): Load even sizes from 8px to upper bound. - def.ve_id = ve.load_font( & provider_data.ve_font_cache, desired_id, font_data, 200.0 ) + def.ve_id = ve.load_font( & provider_data.ve_font_cache, desired_id, font_data, 120.0 ) fid := FontID { key, desired_id } return fid