mirror of
https://github.com/Ed94/VEFontCache-Odin.git
synced 2025-08-05 14:42:42 -07:00
Add assignable allocator support to stb_truetype
This commit is contained in:
@@ -596,6 +596,7 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
|
||||
error : Allocator_Error
|
||||
glyph_pack[pack_id].shape, error = parser_get_glyph_shape(entry.parser_info, shape.glyph[pack_id])
|
||||
assert(error == .None)
|
||||
assert(glyph_pack[pack_id].shape != nil)
|
||||
}
|
||||
for id, index in oversized
|
||||
{
|
||||
@@ -633,7 +634,10 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
|
||||
}
|
||||
|
||||
flush_glyph_buffer_draw_list(draw_list, & glyph_buffer.draw_list, & glyph_buffer.clear_draw_list, & glyph_buffer.allocated_x)
|
||||
for id, index in oversized do parser_free_shape(entry.parser_info, glyph_pack[id].shape)
|
||||
for pack_id, index in oversized {
|
||||
assert(glyph_pack[pack_id].shape != nil)
|
||||
parser_free_shape(entry.parser_info, glyph_pack[pack_id].shape)
|
||||
}
|
||||
}
|
||||
profile_end()
|
||||
|
||||
@@ -666,6 +670,7 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
|
||||
error : Allocator_Error
|
||||
glyph_pack[pack_id].shape, error = parser_get_glyph_shape(entry.parser_info, shape.glyph[pack_id])
|
||||
assert(error == .None)
|
||||
assert(glyph_pack[pack_id].shape != nil)
|
||||
}
|
||||
|
||||
for id, index in to_cache
|
||||
@@ -731,7 +736,10 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
|
||||
}
|
||||
|
||||
flush_glyph_buffer_draw_list(draw_list, & glyph_buffer.draw_list, & glyph_buffer.clear_draw_list, & glyph_buffer.allocated_x)
|
||||
for id, index in to_cache do parser_free_shape(entry.parser_info, glyph_pack[id].shape)
|
||||
for pack_id, index in to_cache {
|
||||
assert(glyph_pack[pack_id].shape != nil)
|
||||
parser_free_shape(entry.parser_info, glyph_pack[pack_id].shape)
|
||||
}
|
||||
|
||||
profile_begin("gen_cached_draw_list: to_cache")
|
||||
when ENABLE_DRAW_TYPE_VISUALIZATION {
|
||||
|
@@ -18,6 +18,7 @@ Already wanted to do so anyway to evaluate the shape generation implementation.
|
||||
import "base:runtime"
|
||||
import "core:c"
|
||||
import "core:math"
|
||||
import "core:mem"
|
||||
import "core:slice"
|
||||
import stbtt "thirdparty:stb/truetype"
|
||||
// import freetype "thirdparty:freetype"
|
||||
@@ -57,13 +58,44 @@ Parser_Glyph_Vertex :: struct {
|
||||
Parser_Glyph_Shape :: [dynamic]Parser_Glyph_Vertex
|
||||
|
||||
Parser_Context :: struct {
|
||||
kind : Parser_Kind,
|
||||
lib_backing : Allocator,
|
||||
kind : Parser_Kind,
|
||||
// ft_library : freetype.Library,
|
||||
}
|
||||
|
||||
parser_init :: proc( ctx : ^Parser_Context, kind : Parser_Kind )
|
||||
parser_stbtt_allocator_proc :: proc(
|
||||
allocator_data : rawptr,
|
||||
type : stbtt.gbAllocationType,
|
||||
size : c.ssize_t,
|
||||
alignment : c.ssize_t,
|
||||
old_memory : rawptr,
|
||||
old_size : c.ssize_t,
|
||||
flags : c.ulonglong
|
||||
) -> rawptr
|
||||
{
|
||||
ctx.kind = kind
|
||||
allocator := transmute(^Allocator) allocator_data
|
||||
result, error := allocator.procedure( allocator.data, cast(mem.Allocator_Mode) type, cast(int) size, cast(int) alignment, old_memory, cast(int) old_size )
|
||||
assert(error == .None)
|
||||
|
||||
if type == .Alloc || type == .Resize {
|
||||
return transmute(rawptr) & result[0]
|
||||
}
|
||||
else do return nil
|
||||
}
|
||||
|
||||
parser_init :: proc( ctx : ^Parser_Context, kind : Parser_Kind, allocator := context.allocator )
|
||||
{
|
||||
ctx.kind = kind
|
||||
ctx.lib_backing = allocator
|
||||
|
||||
stbtt_allocator := stbtt.gbAllocator { parser_stbtt_allocator_proc, & ctx.lib_backing }
|
||||
stbtt.SetAllocator( stbtt_allocator )
|
||||
}
|
||||
|
||||
parser_reload :: proc( ctx : ^Parser_Context, allocator := context.allocator) {
|
||||
ctx.lib_backing = allocator
|
||||
stbtt_allocator := stbtt.gbAllocator { parser_stbtt_allocator_proc, & ctx.lib_backing }
|
||||
stbtt.SetAllocator( stbtt_allocator )
|
||||
}
|
||||
|
||||
parser_shutdown :: proc( ctx : ^Parser_Context ) {
|
||||
|
Reference in New Issue
Block a user