//////////////////////////////////////////////////////////// //~ Key types Struct(GC_FontKey) { ResourceKey r; }; //////////////////////////////////////////////////////////// //~ Atlas types Struct(GC_Atlas) { GC_Atlas *next; Vec2I32 dims; G_ResourceHandle tex; G_Texture2DRef tex_ref; Vec2I32 cur_pos; i32 cur_row_height; }; //////////////////////////////////////////////////////////// //~ Glyph types Struct(GC_GlyphDesc) { GC_FontKey font; f32 font_size; u32 codepoint; }; Struct(GC_Glyph) { GC_Glyph *next; GC_GlyphDesc desc; u64 hash; Atomic64 async_copy_completion_target; /* Font info */ f32 font_size; f32 font_ascent; f32 font_descent; f32 font_cap; /* Layout info */ f32 advance; Rng2 bounds; /* Atlas info */ GC_Atlas *atlas; Rng2I32 tex_slice; Rng2 tex_slice_uv; }; Struct(GC_GlyphBin) { GC_Glyph *first; }; //////////////////////////////////////////////////////////// //~ Run types Struct(GC_RunRect) { Rng2 bounds; /* Visual bounds in relation to the baseline */ f32 baseline_pos; /* Horizontal distance from start of baseline */ f32 advance; G_Texture2DRef tex; Rng2I32 tex_slice; Rng2 tex_slice_uv; }; Struct(GC_Run) { /* Run data */ Rng2 bounds; /* Visual bounds of the run in relation to the baseline */ f32 baseline_length; u64 rects_count; GC_RunRect *rects; /* Font info */ f32 font_size; f32 font_ascent; f32 font_descent; f32 font_cap; b32 ready; }; //////////////////////////////////////////////////////////// //~ Cmd types Struct(GC_Cmd) { GC_Glyph *glyph; /* Async temporary data */ TTF_GlyphResult rasterized; }; Struct(GC_CmdNode) { GC_CmdNode *next; GC_Cmd cmd; }; //////////////////////////////////////////////////////////// //~ Context types Struct(GC_AsyncCtx) { struct { u64 count; GC_Cmd *v; } cmds; }; Struct(GC_Ctx) { Mutex glyphs_mutex; GC_GlyphBin glyph_bins[16384]; u64 atlases_count; GC_Atlas *first_atlas; struct { Mutex mutex; u64 count; GC_CmdNode *first; GC_CmdNode *last; GC_CmdNode *first_free; } submit; GC_AsyncCtx async_ctx; }; extern GC_Ctx GC; //////////////////////////////////////////////////////////// //~ Bootstrap void GC_Bootstrap(void); //////////////////////////////////////////////////////////// //~ Key helpers GC_FontKey GC_FontKeyFromResource(ResourceKey resource); u64 GC_HashFromGlyphDesc(GC_GlyphDesc desc); //////////////////////////////////////////////////////////// //~ Run GC_Run GC_RunFromString(Arena *arena, String str, GC_FontKey font, f32 font_size); //////////////////////////////////////////////////////////// //~ Async void GC_TickAsync(WaveLaneCtx *lane, AsyncTickCtx *ctx);