diff --git a/code/font/VEFontCache/LRU.odin b/code/font/VEFontCache/LRU.odin index 547741b..e9a014a 100644 --- a/code/font/VEFontCache/LRU.odin +++ b/code/font/VEFontCache/LRU.odin @@ -121,15 +121,15 @@ pool_list_erase :: proc( pool : ^PoolList, iter : PoolListIter ) } } -pool_list_peek_back :: #force_inline proc "contextless" ( pool : ^PoolList ) -> PoolListValue { - // assert( pool.back != - 1 ) +pool_list_peek_back :: proc ( pool : ^PoolList ) -> PoolListValue { + assert( pool.back != - 1 ) value := pool.items.data[ pool.back ].value return value } -pool_list_pop_back :: #force_inline proc( pool : ^PoolList ) -> PoolListValue { +pool_list_pop_back :: proc( pool : ^PoolList ) -> PoolListValue { if pool.size <= 0 do return 0 - // assert( pool.back != -1 ) + assert( pool.back != -1 ) value := pool.items.data[ pool.back ].value pool_list_erase( pool, pool.back ) @@ -164,7 +164,7 @@ LRU_free :: proc( cache : ^LRU_Cache ) } -LRU_reload :: #force_inline proc( cache : ^LRU_Cache, allocator : Allocator ) +LRU_reload :: proc( cache : ^LRU_Cache, allocator : Allocator ) { reload_map( & cache.table, allocator ) pool_list_reload( & cache.key_queue, allocator ) @@ -177,7 +177,7 @@ LRU_hash_key :: #force_inline proc( key : u64 ) -> ( hash : u64 ) { return } -LRU_find :: #force_inline proc "contextless" ( cache : ^LRU_Cache, key : u64, must_find := false ) -> (LRU_Link, bool) { +LRU_find :: proc( cache : ^LRU_Cache, key : u64, must_find := false ) -> (LRU_Link, bool) { // hash := LRU_hash_key( key ) // link := get( cache.table, hash ) // if link == nil && must_find { @@ -189,7 +189,7 @@ LRU_find :: #force_inline proc "contextless" ( cache : ^LRU_Cache, key : u64, mu return link, success } -LRU_get :: #force_inline proc( cache : ^LRU_Cache, key : u64 ) -> i32 { +LRU_get :: proc( cache : ^LRU_Cache, key : u64 ) -> i32 { iter, success := LRU_find( cache, key ) if success == false { return -1 @@ -198,7 +198,7 @@ LRU_get :: #force_inline proc( cache : ^LRU_Cache, key : u64 ) -> i32 { return iter.value } -LRU_get_next_evicted :: #force_inline proc "contextless" ( cache : ^LRU_Cache ) -> u64 +LRU_get_next_evicted :: proc( cache : ^LRU_Cache ) -> u64 { if cache.key_queue.size >= cache.capacity { evict := pool_list_peek_back( & cache.key_queue ) @@ -207,7 +207,7 @@ LRU_get_next_evicted :: #force_inline proc "contextless" ( cache : ^LRU_Cache ) return 0xFFFFFFFFFFFFFFFF } -LRU_peek :: #force_inline proc ( cache : ^LRU_Cache, key : u64, must_find := false ) -> i32 { +LRU_peek :: proc( cache : ^LRU_Cache, key : u64, must_find := false ) -> i32 { iter, success := LRU_find( cache, key, must_find ) if success == false { return -1 @@ -215,7 +215,7 @@ LRU_peek :: #force_inline proc ( cache : ^LRU_Cache, key : u64, must_find := fal return iter.value } -LRU_put :: #force_inline proc ( cache : ^LRU_Cache, key : u64, value : i32 ) -> u64 +LRU_put :: proc( cache : ^LRU_Cache, key : u64, value : i32 ) -> u64 { // hash_key := LRU_hash_key( key ) iter, success := cache.table[key] diff --git a/code/font/VEFontCache/VEFontCache.odin b/code/font/VEFontCache/VEFontCache.odin index 190169b..8506922 100644 --- a/code/font/VEFontCache/VEFontCache.odin +++ b/code/font/VEFontCache/VEFontCache.odin @@ -56,7 +56,7 @@ Context :: struct { parser_ctx : ParserContext, shaper_ctx : ShaperContext, - entries : [dynamic]Entry, + entries : Array(Entry), temp_path : Array(Vec2), temp_codepoint_seen : map[u64]bool, @@ -149,10 +149,10 @@ init :: proc( ctx : ^Context, parser_kind : ParserKind, atlas_params := InitAtlasParams_Default, glyph_draw_params := InitGlyphDrawParams_Default, shape_cache_params := InitShapeCacheParams_Default, - curve_quality : u32 = 6, - entires_reserve : u32 = 512, - temp_path_reserve : u32 = 512, - temp_codepoint_seen_reserve : u32 = 512, + curve_quality : u32 = 12, + entires_reserve : u32 = Kilobyte, + temp_path_reserve : u32 = Kilobyte, + temp_codepoint_seen_reserve : u32 = 1024, ) { assert( ctx != nil, "Must provide a valid context" ) @@ -162,18 +162,18 @@ init :: proc( ctx : ^Context, parser_kind : ParserKind, context.allocator = ctx.backing if curve_quality == 0 { - curve_quality = 6 + curve_quality = 12 } ctx.curve_quality = curve_quality error : AllocatorError - entries, error = make( [dynamic]Entry, entires_reserve ) + entries, error = make( Array(Entry), u64(entires_reserve) ) assert(error == .None, "VEFontCache.init : Failed to allocate entries") temp_path, error = make( Array(Vec2), u64(temp_path_reserve) ) assert(error == .None, "VEFontCache.init : Failed to allocate temp_path") - temp_codepoint_seen, error = make( map[u64]bool, hmap_closest_prime( uint(temp_codepoint_seen_reserve)) ) + temp_codepoint_seen, error = make( map[u64]bool )//, hmap_closest_prime( uint(temp_codepoint_seen_reserve)) ) assert(error == .None, "VEFontCache.init : Failed to allocate temp_path") draw_list.vertices, error = make( Array(Vertex), 4 * Kilobyte ) @@ -277,8 +277,7 @@ hot_reload :: proc( ctx : ^Context, allocator : Allocator ) using ctx - // entries.backing = allocator - reload_array( & entries, allocator ) + entries.backing = allocator temp_path.backing = allocator reload_map( & ctx.temp_codepoint_seen, allocator ) @@ -319,7 +318,7 @@ shutdown :: proc( ctx : ^Context ) context.allocator = ctx.backing using ctx - for & entry in entries { + for & entry in array_to_slice(entries) { unload_font( ctx, entry.id ) } @@ -329,7 +328,7 @@ shutdown :: proc( ctx : ^Context ) #endregion("lifetime") // ve_fontcache_configure_snap -configure_snap :: #force_inline proc( ctx : ^Context, snap_width, snap_height : u32 ) { +configure_snap :: proc( ctx : ^Context, snap_width, snap_height : u32 ) { assert( ctx != nil ) ctx.snap_width = snap_width ctx.snap_height = snap_height @@ -345,18 +344,18 @@ load_font :: proc( ctx : ^Context, label : string, data : []byte, size_px : f32 id : i32 = -1 - for index : i32 = 0; index < i32(len(entries)); index += 1 { - if entries[index].used do continue + for index : i32 = 0; index < i32(entries.num); index += 1 { + if entries.data[index].used do continue id = index break } if id == -1 { - append_elem( & entries, Entry {}) - id = cast(i32) len(entries) - 1 + append( & entries, Entry {}) + id = cast(i32) entries.num - 1 } - assert( id >= 0 && id < i32(len(entries)) ) + assert( id >= 0 && id < i32(entries.num) ) - entry := & entries[ id ] + entry := & entries.data[ id ] { using entry @@ -375,7 +374,7 @@ load_font :: proc( ctx : ^Context, label : string, data : []byte, size_px : f32 // assert( shaper_info != nil, "VEFontCache.load_font: Failed to load font from shaper") } entry.id = FontID(id) - ctx.entries[ id ].id = FontID(id) + ctx.entries.data[ id ].id = FontID(id) font_id = FontID(id) return @@ -385,11 +384,11 @@ load_font :: proc( ctx : ^Context, label : string, data : []byte, size_px : f32 unload_font :: proc( ctx : ^Context, font : FontID ) { assert( ctx != nil ) - assert( font >= 0 && int(font) < len(ctx.entries) ) + assert( font >= 0 && u64(font) < ctx.entries.num ) context.allocator = ctx.backing using ctx - entry := & ctx.entries[ font ] + entry := & entries.data[ font ] entry.used = false parser_unload_font( & entry.parser_info ) @@ -398,10 +397,10 @@ unload_font :: proc( ctx : ^Context, font : FontID ) cache_glyph :: proc( ctx : ^Context, font : FontID, glyph_index : Glyph, scale, translate : Vec2 ) -> b32 { - // profile(#procedure) + profile(#procedure) assert( ctx != nil ) - assert( font >= 0 && int(font) < len(ctx.entries) ) - entry := & ctx.entries[ font ] + assert( font >= 0 && u64(font) < ctx.entries.num ) + entry := & ctx.entries.data[ font ] if glyph_index == Glyph(0) { // Note(Original Author): Glyph not in current hb_font return false @@ -521,10 +520,10 @@ cache_glyph :: proc( ctx : ^Context, font : FontID, glyph_index : Glyph, scale, cache_glyph_to_atlas :: proc( ctx : ^Context, font : FontID, glyph_index : Glyph ) { - // profile(#procedure) + profile(#procedure) assert( ctx != nil ) - assert( font >= 0 && int(font) < len(ctx.entries) ) - entry := & ctx.entries[ font ] + assert( font >= 0 && font < FontID(ctx.entries.num) ) + entry := & ctx.entries.data[ font ] if glyph_index == 0 do return if parser_is_glyph_empty( & entry.parser_info, glyph_index ) do return @@ -641,10 +640,10 @@ cache_glyph_to_atlas :: proc( ctx : ^Context, font : FontID, glyph_index : Glyph cache_glyph( ctx, font, glyph_index, glyph_draw_scale, glyph_draw_translate ) } -get_cursor_pos :: #force_inline proc "contextless" ( ctx : ^Context ) -> Vec2 { return ctx.cursor_pos } -set_colour :: #force_inline proc "contextless" ( ctx : ^Context, colour : Colour ) { ctx.colour = colour } +get_cursor_pos :: proc( ctx : ^Context ) -> Vec2 { return ctx.cursor_pos } +set_colour :: proc( ctx : ^Context, colour : Colour ) { ctx.colour = colour } -is_empty :: #force_inline proc ( ctx : ^Context, entry : ^Entry, glyph_index : Glyph ) -> b32 +is_empty :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph ) -> b32 { if glyph_index == 0 do return true if parser_is_glyph_empty( & entry.parser_info, glyph_index ) do return true @@ -653,15 +652,15 @@ is_empty :: #force_inline proc ( ctx : ^Context, entry : ^Entry, glyph_index : G measure_text_size :: proc( ctx : ^Context, font : FontID, text_utf8 : string ) -> (measured : Vec2) { - // profile(#procedure) + profile(#procedure) assert( ctx != nil ) - assert( font >= 0 && int(font) < len(ctx.entries) ) + assert( font >= 0 && font < FontID(ctx.entries.num) ) context.allocator = ctx.backing atlas := ctx.atlas shaped := shape_text_cached( ctx, font, text_utf8 ) - entry := & ctx.entries[ font ] + entry := & ctx.entries.data[ font ] padding := cast(f32) atlas.glyph_padding for index : i32 = 0; index < i32(shaped.glyphs.num); index += 1 @@ -670,11 +669,20 @@ measure_text_size :: proc( ctx : ^Context, font : FontID, text_utf8 : string ) - if is_empty( ctx, entry, glyph_index ) do continue bounds_0, bounds_1 := parser_get_glyph_box( & entry.parser_info, glyph_index ) - bounds_size := bounds_1 - bounds_0 + bounds_width := bounds_1.x - bounds_0.x + bounds_height := bounds_1.y - bounds_0.y - glyph_size := Vec2 { f32(bounds_size.x), f32(bounds_size.y) } * entry.size_scale + // region_kind, region, over_sample := decide_codepoint_region( ctx, entry, glyph_index ) + + glyph_size := Vec2 { + f32(bounds_width) * entry.size_scale, //+ padding, + f32(bounds_height) * entry.size_scale, //+ padding, + } + + dummy_position : Vec2 measured.y = max(measured.y, glyph_size.y) } measured.x = shaped.end_cursor_pos.x + return measured } diff --git a/code/font/VEFontCache/atlas.odin b/code/font/VEFontCache/atlas.odin index 3c48193..0d6cc4b 100644 --- a/code/font/VEFontCache/atlas.odin +++ b/code/font/VEFontCache/atlas.odin @@ -88,9 +88,9 @@ atlas_bbox :: proc( atlas : ^Atlas, region : AtlasRegionKind, local_idx : i32 ) return } -can_batch_glyph :: #force_inline proc( ctx : ^Context, font : FontID, entry : ^Entry, glyph_index : Glyph ) -> b32 +can_batch_glyph :: proc( ctx : ^Context, font : FontID, entry : ^Entry, glyph_index : Glyph ) -> b32 { - // profile(#procedure) + profile(#procedure) assert( ctx != nil ) assert( entry.id == font ) @@ -129,7 +129,7 @@ can_batch_glyph :: #force_inline proc( ctx : ^Context, font : FontID, entry : ^E return true } -decide_codepoint_region :: #force_inline proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph +decide_codepoint_region :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph ) -> (region_kind : AtlasRegionKind, region : ^AtlasRegion, over_sample : Vec2) { if parser_is_glyph_empty( & entry.parser_info, glyph_index ) { diff --git a/code/font/VEFontCache/draw.odin b/code/font/VEFontCache/draw.odin index 32fd8c3..0b1bc34 100644 --- a/code/font/VEFontCache/draw.odin +++ b/code/font/VEFontCache/draw.odin @@ -48,7 +48,7 @@ GlyphDrawBuffer :: struct { blit_quad :: proc( draw_list : ^DrawList, p0 : Vec2 = {0, 0}, p1 : Vec2 = {1, 1}, uv0 : Vec2 = {0, 0}, uv1 : Vec2 = {1, 1} ) { - // profile(#procedure) + profile(#procedure) // logf("Blitting: xy0: %0.2f, %0.2f xy1: %0.2f, %0.2f uv0: %0.2f, %0.2f uv1: %0.2f, %0.2f", // p0.x, p0.y, p1.x, p1.y, uv0.x, uv0.y, uv1.x, uv1.y); v_offset := cast(u32) draw_list.vertices.num @@ -90,7 +90,7 @@ blit_quad :: proc( draw_list : ^DrawList, p0 : Vec2 = {0, 0}, p1 : Vec2 = {1, 1} } // ve_fontcache_clear_drawlist -clear_draw_list :: #force_inline proc ( draw_list : ^DrawList ) { +clear_draw_list :: proc( draw_list : ^DrawList ) { clear( draw_list.calls ) clear( draw_list.indices ) clear( draw_list.vertices ) @@ -98,7 +98,7 @@ clear_draw_list :: #force_inline proc ( draw_list : ^DrawList ) { directly_draw_massive_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph : Glyph, bounds_0 : Vec2i, bounds_width, bounds_height : i32, over_sample, position, scale : Vec2 ) { - // profile(#procedure) + profile(#procedure) flush_glyph_buffer_to_atlas( ctx ) // Draw un-antialiased glyph to update FBO. @@ -156,7 +156,7 @@ directly_draw_massive_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph : Gly draw_cached_glyph :: proc( ctx : ^Context, entry : ^Entry, glyph_index : Glyph, position, scale : Vec2 ) -> b32 { - // profile(#procedure) + profile(#procedure) // Glyph not in current font if glyph_index == 0 do return true if parser_is_glyph_empty( & entry.parser_info, glyph_index ) do return true @@ -286,9 +286,9 @@ draw_filled_path :: proc( draw_list : ^DrawList, outside_point : Vec2, path : [] // From there we should maek a 'draw text shape' that breaks up the batch text draws for each of the shapes. draw_text :: proc( ctx : ^Context, font : FontID, text_utf8 : string, position : Vec2, scale : Vec2 ) -> b32 { - // profile(#procedure) + profile(#procedure) assert( ctx != nil ) - assert( font >= 0 && int(font) < len(ctx.entries) ) + assert( font >= 0 && font < FontID(ctx.entries.num) ) context.allocator = ctx.backing @@ -298,7 +298,7 @@ draw_text :: proc( ctx : ^Context, font : FontID, text_utf8 : string, position : 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[ font ] + entry := & ctx.entries.data[ font ] // entry.size_scale = parser_scale( & entry.parser_info, entry.size ) @@ -415,7 +415,7 @@ draw_text_batch :: proc( ctx : ^Context, entry : ^Entry, shaped : ^ShapedText, b flush_glyph_buffer_to_atlas( ctx ) for index := batch_start_idx; index < batch_end_idx; index += 1 { - // profile(#procedure) + profile(#procedure) glyph_index := shaped.glyphs.data[ index ] shaped_position := shaped.positions.data[index] glyph_translate := position + shaped_position * scale @@ -428,7 +428,7 @@ draw_text_batch :: proc( ctx : ^Context, entry : ^Entry, shaped : ^ShapedText, b // Helper for draw_text, all raw text content should be confirmed to be either formatting or visible shapes before getting cached. draw_text_shape :: proc( ctx : ^Context, font : FontID, entry : ^Entry, shaped : ^ShapedText, position, scale : Vec2, snap_width, snap_height : f32 ) -> (cursor_pos : Vec2) { - // profile(#procedure) + profile(#procedure) batch_start_idx : i32 = 0 for index : i32 = 0; index < i32(shaped.glyphs.num); index += 1 { @@ -463,7 +463,7 @@ flush_draw_list :: proc( ctx : ^Context ) { flush_glyph_buffer_to_atlas :: proc( ctx : ^Context ) { - // profile(#procedure) + profile(#procedure) // Flush drawcalls to draw list merge_draw_list( & ctx.draw_list, & ctx.atlas.clear_draw_list ) merge_draw_list( & ctx.draw_list, & ctx.atlas.draw_list) @@ -498,7 +498,7 @@ flush_layer :: proc( draw_list : ^DrawList ) {} // ve_fontcache_merge_drawlist merge_draw_list :: proc( dst, src : ^DrawList ) { - // profile(#procedure) + profile(#procedure) error : AllocatorError v_offset := cast(u32) dst.vertices.num @@ -526,7 +526,7 @@ merge_draw_list :: proc( dst, src : ^DrawList ) optimize_draw_list :: proc( draw_list : ^DrawList, call_offset : u64 ) { - // profile(#procedure) + profile(#procedure) assert( draw_list != nil ) calls := array_to_slice(draw_list.calls) diff --git a/code/font/VEFontCache/mappings.odin b/code/font/VEFontCache/mappings.odin index d8b506a..c7fb414 100644 --- a/code/font/VEFontCache/mappings.odin +++ b/code/font/VEFontCache/mappings.odin @@ -62,6 +62,8 @@ hmap_zpl_reload :: grime.hmap_zpl_reload hmap_zpl_remove :: grime.hmap_zpl_remove hmap_zpl_set :: grime.hmap_zpl_set +reload_map :: grime.reload_map + // Pool :: grime.Pool StackFixed :: grime.StackFixed @@ -79,17 +81,12 @@ logf :: grime.logf profile :: grime.profile -reload_array :: grime.reload_array -reload_map :: grime.reload_map - //#region("Proc overload mappings") append :: proc { grime.array_append_array, grime.array_append_slice, grime.array_append_value, - - // append_elem, append_elems, append_elem_string, } append_at :: proc { @@ -118,10 +115,6 @@ make :: proc { hmap_chained_init, hmap_zpl_init, make_map, - - make_dynamic_array, - make_dynamic_array_len, - make_dynamic_array_len_cap, } // reload :: proc { diff --git a/code/font/VEFontCache/misc.odin b/code/font/VEFontCache/misc.odin index d3f5f5f..a9b7477 100644 --- a/code/font/VEFontCache/misc.odin +++ b/code/font/VEFontCache/misc.odin @@ -1,6 +1,6 @@ package VEFontCache -font_glyph_lru_code :: #force_inline proc "contextless" ( font : FontID, glyph_index : Glyph ) -> (lru_code : u64) +font_glyph_lru_code :: #force_inline proc( font : FontID, glyph_index : Glyph ) -> (lru_code : u64) { // font := font // glyph_index := glyph_index @@ -17,7 +17,7 @@ font_glyph_lru_code :: #force_inline proc "contextless" ( font : FontID, glyph_i return } -shape_lru_hash :: #force_inline proc "contextless" ( label : string ) -> u64 { +shape_lru_hash :: #force_inline proc( label : string ) -> u64 { hash : u64 for str_byte in transmute([]byte) label { hash = ((hash << 8) + hash) + u64(str_byte) @@ -28,7 +28,7 @@ shape_lru_hash :: #force_inline proc "contextless" ( label : string ) -> u64 { // For a provided alpha value, // allows the function to calculate the position of a point along the curve at any given fraction of its total length // ve_fontcache_eval_bezier (quadratic) -eval_point_on_bezier3 :: #force_inline proc "contextless" ( p0, p1, p2 : Vec2, alpha : f32 ) -> Vec2 +eval_point_on_bezier3 :: proc( p0, p1, p2 : Vec2, alpha : f32 ) -> Vec2 { // p0 := vec2_64_from_vec2(p0) // p1 := vec2_64_from_vec2(p1) @@ -50,7 +50,7 @@ eval_point_on_bezier3 :: #force_inline proc "contextless" ( p0, p1, p2 : Vec2, a // For a provided alpha value, // allows the function to calculate the position of a point along the curve at any given fraction of its total length // ve_fontcache_eval_bezier (cubic) -eval_point_on_bezier4 :: #force_inline proc "contextless" ( p0, p1, p2, p3 : Vec2, alpha : f32 ) -> Vec2 +eval_point_on_bezier4 :: proc( p0, p1, p2, p3 : Vec2, alpha : f32 ) -> Vec2 { // p0 := vec2_64_from_vec2(p0) // p1 := vec2_64_from_vec2(p1) @@ -72,60 +72,37 @@ eval_point_on_bezier4 :: #force_inline proc "contextless" ( p0, p1, p2, p3 : Vec return { f32(point.x), f32(point.y) } } -reset_batch_codepoint_state :: #force_inline proc( ctx : ^Context ) { +reset_batch_codepoint_state :: proc( ctx : ^Context ) { clear_map( & ctx.temp_codepoint_seen ) ctx.temp_codepoint_seen_num = 0 } -screenspace_x_form :: #force_inline proc "contextless" ( position, scale : ^Vec2, width, height : f32 ) { - when false - { - pos_64 := vec2_64_from_vec2(position^) - scale_64 := vec2_64_from_vec2(scale^) - width := f64(width) - height := f64(height) +screenspace_x_form :: proc( position, scale : ^Vec2, width, height : f32 ) { + pos_64 := vec2_64_from_vec2(position^) + scale_64 := vec2_64_from_vec2(scale^) + width := f64(width) + height := f64(height) - quotient : Vec2_64 = 1.0 / { width, height } - pos_64 = pos_64 * quotient * 2.0 - 1.0 - scale_64 = scale_64 * quotient * 2.0 + quotient : Vec2_64 = 1.0 / { width, height } + // quotient : Vec2 = 1.0 / { width, height } + pos_64 = pos_64 * quotient * 2.0 - 1.0 + scale_64 = scale_64 * quotient * 2.0 - (position^) = { f32(pos_64.x), f32(pos_64.y) } - (scale^) = { f32(scale_64.x), f32(scale_64.y) } - } - else - { - quotient : Vec2 = 1.0 / { width, height } - pos := position^ * quotient * 2.0 - 1.0 - s := scale^ * quotient * 2.0 - (position^) = { f32(pos.x), f32(pos.y) } - (scale^) = { f32(s.x), f32(s.y) } - } + (position^) = { f32(pos_64.x), f32(pos_64.y) } + (scale^) = { f32(scale_64.x), f32(scale_64.y) } } -textspace_x_form :: #force_inline proc "contextless" ( position, scale : ^Vec2, width, height : f32 ) { - when false - { - pos_64 := vec2_64_from_vec2(position^) - scale_64 := vec2_64_from_vec2(scale^) - width := f64(width) - height := f64(height) +textspace_x_form :: proc( position, scale : ^Vec2, width, height : f32 ) { + pos_64 := vec2_64_from_vec2(position^) + scale_64 := vec2_64_from_vec2(scale^) + width := f64(width) + height := f64(height) - quotient : Vec2_64 = 1.0 / { width, height } - pos_64 *= quotient - scale_64 *= quotient + quotient : Vec2_64 = 1.0 / { width, height } + // quotient : Vec2 = 1.0 / { width, height } + pos_64 *= quotient + scale_64 *= quotient - (position^) = { f32(pos_64.x), f32(pos_64.y) } - (scale^) = { f32(scale_64.x), f32(scale_64.y) } - } - else - { - pos := position^ - s := scale^ - - quotient : Vec2 = 1.0 / { width, height } - pos *= quotient - s *= quotient - (position^) = { f32(pos.x), f32(pos.y) } - (scale^) = { f32(s.x), f32(s.y) } - } + (position^) = { f32(pos_64.x), f32(pos_64.y) } + (scale^) = { f32(scale_64.x), f32(scale_64.y) } } diff --git a/code/font/VEFontCache/parser.odin b/code/font/VEFontCache/parser.odin index fb97400..b4c9b78 100644 --- a/code/font/VEFontCache/parser.odin +++ b/code/font/VEFontCache/parser.odin @@ -113,7 +113,7 @@ parser_unload_font :: proc( font : ^ParserFontInfo ) } } -parser_find_glyph_index :: #force_inline proc "contextless" ( font : ^ParserFontInfo, codepoint : rune ) -> (glyph_index : Glyph) +parser_find_glyph_index :: proc( font : ^ParserFontInfo, codepoint : rune ) -> (glyph_index : Glyph) { switch font.kind { @@ -140,7 +140,7 @@ parser_free_shape :: proc( font : ^ParserFontInfo, shape : ParserGlyphShape ) } } -parser_get_codepoint_horizontal_metrics :: #force_inline proc "contextless" ( font : ^ParserFontInfo, codepoint : rune ) -> ( advance, to_left_side_glyph : i32 ) +parser_get_codepoint_horizontal_metrics :: proc( font : ^ParserFontInfo, codepoint : rune ) -> ( advance, to_left_side_glyph : i32 ) { switch font.kind { @@ -164,7 +164,7 @@ parser_get_codepoint_horizontal_metrics :: #force_inline proc "contextless" ( fo return } -parser_get_codepoint_kern_advance :: #force_inline proc "contextless" ( font : ^ParserFontInfo, prev_codepoint, codepoint : rune ) -> i32 +parser_get_codepoint_kern_advance :: proc( font : ^ParserFontInfo, prev_codepoint, codepoint : rune ) -> i32 { switch font.kind { @@ -184,7 +184,7 @@ parser_get_codepoint_kern_advance :: #force_inline proc "contextless" ( font : ^ return -1 } -parser_get_font_vertical_metrics :: #force_inline proc "contextless" ( font : ^ParserFontInfo ) -> (ascent, descent, line_gap : i32 ) +parser_get_font_vertical_metrics :: proc( font : ^ParserFontInfo ) -> (ascent, descent, line_gap : i32 ) { switch font.kind { @@ -196,7 +196,7 @@ parser_get_font_vertical_metrics :: #force_inline proc "contextless" ( font : ^P return } -parser_get_glyph_box :: #force_inline proc ( font : ^ParserFontInfo, glyph_index : Glyph ) -> (bounds_0, bounds_1 : Vec2i) +parser_get_glyph_box :: proc( font : ^ParserFontInfo, glyph_index : Glyph ) -> (bounds_0, bounds_1 : Vec2i) { switch font.kind { @@ -370,7 +370,7 @@ parser_get_glyph_shape :: proc( font : ^ParserFontInfo, glyph_index : Glyph ) -> return } -parser_is_glyph_empty :: #force_inline proc "contextless" ( font : ^ParserFontInfo, glyph_index : Glyph ) -> b32 +parser_is_glyph_empty :: proc( font : ^ParserFontInfo, glyph_index : Glyph ) -> b32 { switch font.kind { @@ -393,7 +393,7 @@ parser_is_glyph_empty :: #force_inline proc "contextless" ( font : ^ParserFontIn return false } -parser_scale :: #force_inline proc "contextless" ( font : ^ParserFontInfo, size : f32 ) -> f32 +parser_scale :: #force_inline proc( font : ^ParserFontInfo, size : f32 ) -> f32 { size_scale := size < 0.0 ? \ parser_scale_for_pixel_height( font, -size ) \ @@ -402,7 +402,7 @@ parser_scale :: #force_inline proc "contextless" ( font : ^ParserFontInfo, size return size_scale } -parser_scale_for_pixel_height :: #force_inline proc "contextless" ( font : ^ParserFontInfo, size : f32 ) -> f32 +parser_scale_for_pixel_height :: proc( font : ^ParserFontInfo, size : f32 ) -> f32 { switch font.kind { case .Freetype: @@ -416,7 +416,7 @@ parser_scale_for_pixel_height :: #force_inline proc "contextless" ( font : ^Pars return 0 } -parser_scale_for_mapping_em_to_pixels :: #force_inline proc "contextless" ( font : ^ParserFontInfo, size : f32 ) -> f32 +parser_scale_for_mapping_em_to_pixels :: proc( font : ^ParserFontInfo, size : f32 ) -> f32 { switch font.kind { case .Freetype: diff --git a/code/font/VEFontCache/shaped_text.odin b/code/font/VEFontCache/shaped_text.odin index a48b9ac..d085c22 100644 --- a/code/font/VEFontCache/shaped_text.odin +++ b/code/font/VEFontCache/shaped_text.odin @@ -16,7 +16,7 @@ ShapedTextCache :: struct { shape_text_cached :: proc( ctx : ^Context, font : FontID, text_utf8 : string ) -> ^ShapedText { - // profile(#procedure) + profile(#procedure) @static buffer : [64 * Kilobyte]byte font := font @@ -62,12 +62,12 @@ shape_text_cached :: proc( ctx : ^Context, font : FontID, text_utf8 : string ) - shape_text_uncached :: proc( ctx : ^Context, font : FontID, output : ^ShapedText, text_utf8 : string ) { - // profile(#procedure) + profile(#procedure) assert( ctx != nil ) - assert( font >= 0 && int(font) < len(ctx.entries) ) + assert( font >= 0 && font < FontID(ctx.entries.num) ) use_full_text_shape := ctx.text_shape_adv - entry := & ctx.entries[ font ] + entry := & ctx.entries.data[ font ] clear( output.glyphs ) clear( output.positions )