mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-24 00:11:14 +01:00
Two paint-encoder bugs and two demo-plumbing bugs together prevented end-to-end rendering. With all four fixed, BungeeTint and similar COLRv0 fonts now render through the GL demo in their proper palette colors. ### Paint encoder 1. hb-gpu-paint-fragment.glsl: the LAYER_SOLID op's payload is a blob-relative texel offset, but the shader was passing it to hb_gpu_draw() as-is -- which treats its argument as an absolute atlas offset. Add the glyph's `base` to the payload before the draw-coverage call so the sub-blob reference resolves inside the paint blob instead of elsewhere in the atlas. 2. hb-gpu-paint.cc push_clip_glyph callback: was resetting pending_palette_index to 0. But harfbuzz's COLRv0 paint emitter calls custom_palette_color BEFORE push_clip_glyph for each layer, so the index set by custom_palette_color was being clobbered before the color callback consumed it -- every layer ended up tagged palette_index=0. Leave pending_palette_index alone in push_clip_glyph. ### Demo plumbing 3. util/gpu/demo-glstate.cc: demo_glstate_create now glUseProgram's its program immediately. The palette uniform upload reads GL_CURRENT_PROGRAM, and glyph upload happens from demo_buffer_current_line() -- which runs before demo_view_setup() would have bound the program. Without this, glGetIntegerv returned 0 and the palette was never uploaded. 4. util/gpu/demo-font.cc: adds lazy demo_font_upload_palette() on first glyph request. Also tries both "hb_gpu_palette" and "hb_gpu_palette[0]" for the uniform lookup since drivers disagree. ### Bonus util/hb-gpu-encode-all.cc: reports paint-encoded and draw-fallback counts / sizes / timings separately so you can tell where time goes in mixed-content fonts. Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
95 lines
2.1 KiB
C++
95 lines
2.1 KiB
C++
/*
|
|
* Copyright 2026 Behdad Esfahbod. All Rights Reserved.
|
|
*/
|
|
|
|
#include "demo-glstate.h"
|
|
|
|
struct demo_glstate_t {
|
|
GLuint program;
|
|
demo_atlas_t *atlas;
|
|
};
|
|
|
|
demo_glstate_t *
|
|
demo_glstate_create (void)
|
|
{
|
|
demo_glstate_t *st = (demo_glstate_t *) calloc (1, sizeof (demo_glstate_t));
|
|
|
|
st->program = demo_shader_create_program ();
|
|
st->atlas = demo_atlas_create (1024 * 1024);
|
|
|
|
/* Bind the program so demo_font_t can upload the palette
|
|
* uniform during glyph upload (which happens before the first
|
|
* render, i.e. before demo_view_setup re-binds it). */
|
|
glUseProgram (st->program);
|
|
|
|
return st;
|
|
}
|
|
|
|
void
|
|
demo_glstate_destroy (demo_glstate_t *st)
|
|
{
|
|
if (!st)
|
|
return;
|
|
|
|
demo_atlas_destroy (st->atlas);
|
|
glDeleteProgram (st->program);
|
|
|
|
free (st);
|
|
}
|
|
|
|
void
|
|
demo_glstate_setup (demo_glstate_t *st)
|
|
{
|
|
glUseProgram (st->program);
|
|
|
|
demo_atlas_set_uniforms (st->atlas);
|
|
demo_glstate_set_gamma (st, 1.f);
|
|
demo_glstate_set_foreground (st, 0.f, 0.f, 0.f, 1.f);
|
|
|
|
glEnable (GL_BLEND);
|
|
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
}
|
|
|
|
demo_atlas_t *
|
|
demo_glstate_get_atlas (demo_glstate_t *st)
|
|
{
|
|
return st->atlas;
|
|
}
|
|
|
|
void
|
|
demo_glstate_set_matrix (demo_glstate_t *st, float mat[16])
|
|
{
|
|
glUniformMatrix4fv (glGetUniformLocation (st->program, "u_matViewProjection"), 1, GL_FALSE, mat);
|
|
|
|
GLint viewport[4];
|
|
glGetIntegerv (GL_VIEWPORT, viewport);
|
|
glUniform2f (glGetUniformLocation (st->program, "u_viewport"),
|
|
(float) viewport[2], (float) viewport[3]);
|
|
}
|
|
|
|
void
|
|
demo_glstate_set_gamma (demo_glstate_t *st, float gamma)
|
|
{
|
|
glUniform1f (glGetUniformLocation (st->program, "u_gamma"), gamma);
|
|
}
|
|
|
|
void
|
|
demo_glstate_set_foreground (demo_glstate_t *st,
|
|
float r, float g, float b, float a)
|
|
{
|
|
glUniform4f (glGetUniformLocation (st->program, "u_foreground"), r, g, b, a);
|
|
}
|
|
|
|
void
|
|
demo_glstate_set_debug (demo_glstate_t *st, bool enabled)
|
|
{
|
|
glUniform1f (glGetUniformLocation (st->program, "u_debug"), enabled ? 1.f : 0.f);
|
|
}
|
|
|
|
void
|
|
demo_glstate_set_stem_darkening (demo_glstate_t *st, bool enabled)
|
|
{
|
|
glUniform1f (glGetUniformLocation (st->program, "u_stem_darkening"), enabled ? 1.f : 0.f);
|
|
}
|
|
|