working text layouting with glyph cache

This commit is contained in:
jacob 2025-12-13 13:33:16 -06:00
parent 77434a988b
commit 3eab781259
2 changed files with 17 additions and 21 deletions

View File

@ -202,7 +202,8 @@ GC_Run GC_RunFromString(Arena *arena, String str, GC_FontKey font, f32 font_size
result.font_cap = glyph->font_cap;
}
result.ready = uncached_codepoints_count == 0 && pending_glyphs_count == 0;
// result.ready = uncached_codepoints_count == 0 && pending_glyphs_count == 0;
result.ready = 1;
EndScratch(scratch);
return result;
@ -260,11 +261,7 @@ void GC_TickAsync(WaveLaneCtx *lane, AsyncTickCtx *tick)
G_Format_R8G8B8A8_Unorm_Srgb,
atlas_dims,
/* FIXME: We may need simultaneous access? */
// G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present,
G_Layout_Simultaneous,
.flags = G_ResourceFlag_HostMemory,
G_Layout_AnyQueue_ShaderRead_CopyRead_CopyWrite_Present,
);
GC.atlas_ref = G_PushTexture2DRef(gpu_perm, GC.atlas);
}
@ -315,13 +312,12 @@ void GC_TickAsync(WaveLaneCtx *lane, AsyncTickCtx *tick)
if (image_dims.x > 0 && image_dims.y > 0)
{
// G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_AsyncCopy);
G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct);
G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_AsyncCopy);
{
G_CopyCpuToTexture(
cl,
GC.atlas, VEC3I32(atlas_offset.x, atlas_offset.y, 0),
image_pixels, VEC3I32(image_dims.x, image_dims.y, 0),
image_pixels, VEC3I32(image_dims.x, image_dims.y, 1),
RNG3I32(
VEC3I32(0, 0, 0),
VEC3I32(image_dims.x, image_dims.y, 1)

View File

@ -106,17 +106,17 @@ TTF_GlyphResult TTF_RasterizeGlyphFromCodepoint(Arena *arena, u32 codepoint, Res
/* FIXME: Dynamic render target */
i32 render_target_w = 256;
i32 render_target_h = 256;
Vec2I32 rt_dims = VEC2I32(256, 256);
/* Best-guess a position in the middle of the render target based on metrics */
i32 render_target_baseline_x = (render_target_w / 2) - (advance / 2);
i32 render_target_baseline_y = (render_target_h / 2) - (font_cap / 2);
Vec2I32 rt_baseline = ZI;
rt_baseline.x = (rt_dims.x / 2) - (advance / 2);
rt_baseline.y = (rt_dims.y / 2) - (font_cap / 2);
/* Create render target */
IDWriteBitmapRenderTarget *render_target = 0;
{
hr = IDWriteGdiInterop_CreateBitmapRenderTarget(dwrite_gdi_interop, 0, (UINT32)render_target_w, (UINT32)render_target_h, &render_target);
hr = IDWriteGdiInterop_CreateBitmapRenderTarget(dwrite_gdi_interop, 0, (UINT32)rt_dims.x, (UINT32)rt_dims.y, &render_target);
hr = IDWriteBitmapRenderTarget_SetPixelsPerDip(render_target, TTF_DW_Dpi / 96.0);
}
@ -140,7 +140,7 @@ TTF_GlyphResult TTF_RasterizeGlyphFromCodepoint(Arena *arena, u32 codepoint, Res
SetDCPenColor(dc, bg_color);
SelectObject(dc, GetStockObject(DC_BRUSH));
SetDCBrushColor(dc, bg_color);
Rectangle(dc, 0, 0, render_target_w, render_target_h);
Rectangle(dc, 0, 0, rt_dims.x, rt_dims.y);
}
SelectObject(dc, original);
}
@ -185,8 +185,8 @@ TTF_GlyphResult TTF_RasterizeGlyphFromCodepoint(Arena *arena, u32 codepoint, Res
RECT bounding_box = ZI;
hr = IDWriteBitmapRenderTarget_DrawGlyphRun(
render_target,
render_target_baseline_x,
render_target_baseline_y,
rt_baseline.x,
rt_baseline.y,
DWRITE_MEASURING_MODE_NATURAL,
&glyph_run,
rendering_params,
@ -200,8 +200,8 @@ TTF_GlyphResult TTF_RasterizeGlyphFromCodepoint(Arena *arena, u32 codepoint, Res
}
rt_slice.p0.x = MaxI32(rt_slice.p0.x, 0);
rt_slice.p0.y = MaxI32(rt_slice.p0.y, 0);
rt_slice.p1.x = MinI32(rt_slice.p1.x, render_target_w);
rt_slice.p1.y = MinI32(rt_slice.p1.y, render_target_h);
rt_slice.p1.x = MinI32(rt_slice.p1.x, rt_dims.x);
rt_slice.p1.y = MinI32(rt_slice.p1.y, rt_dims.y);
Vec2I32 dst_dims = DimsFromRng2I32(rt_slice);
u32 *dst_pixels = PushStructsNoZero(arena, u32, dst_dims.x * dst_dims.y);
@ -231,8 +231,8 @@ TTF_GlyphResult TTF_RasterizeGlyphFromCodepoint(Arena *arena, u32 codepoint, Res
result.codepoint = codepoint;
result.advance = advance;
result.bounds.p0 = VEC2(0, 0);
result.bounds.p1 = Vec2FromVec(dst_dims);
result.bounds = RNG2(Vec2FromVec(rt_slice.p0), Vec2FromVec(rt_slice.p1));
result.bounds = AddRng2Vec2(result.bounds, NegVec2(Vec2FromVec(rt_baseline)));
result.font_size = font_size;
result.font_ascent = font_ascent;