mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-22 23:41:03 +01:00
Adds command-line flags --draw (force monochrome Slug path) and
--paint (force COLRv1 paint path) to hb-gpu, defaulting to
auto-detect based on hb_ot_color_has_paint(face). Threads a
draw_only bool through the demo layer so each backend compiles
exactly one fragment program (draw or paint, not both).
The paint pipeline is ~10x slower than the draw pipeline on
monochrome content; auto-detect lets monochrome fonts keep the
fast path while still exercising both code paths from the same
binary.
Plumbing:
- demo_renderer_create_{gl,metal,d3d11} and demo_font_create
take a draw_only argument.
- demo-fragment.{glsl,msl,hlsl} branch on HB_GPU_DEMO_DRAW,
calling either hb_gpu_draw or hb_gpu_paint.
- demo-shader / glstate / d3d11 / metal include only the
fragment helper for the chosen path and prepend
HB_GPU_DEMO_DRAW to the source when draw_only.
- demo-font dispatches glyph upload to hb_gpu_draw_* or
hb_gpu_paint_* and hides palette/foreground setters in
draw mode.
Web demos pass false (paint-only) for now; a runtime
re-creation hook on font change would be needed there.
Tested on desktop GL, win64 D3D11, WebGL, WebGPU.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
82 lines
1.8 KiB
C++
82 lines
1.8 KiB
C++
/*
|
|
* Copyright 2026 Behdad Esfahbod. All Rights Reserved.
|
|
*/
|
|
|
|
#ifndef DEMO_SHADERS_H
|
|
#define DEMO_SHADERS_H
|
|
|
|
#include "demo-common.h"
|
|
#include "demo-font.h"
|
|
|
|
|
|
struct glyph_vertex_t {
|
|
/* Object-space position */
|
|
GLfloat x;
|
|
GLfloat y;
|
|
/* Em-space texture coordinates */
|
|
GLfloat tx;
|
|
GLfloat ty;
|
|
/* Object-space outward normal at this vertex */
|
|
GLfloat nx;
|
|
GLfloat ny;
|
|
/* Em units per object-space unit (upem / font_size) */
|
|
GLfloat emPerPos;
|
|
/* Atlas offset (constant across glyph) */
|
|
GLuint atlas_offset;
|
|
};
|
|
|
|
static inline void
|
|
demo_shader_add_glyph_vertices (const demo_point_t &p,
|
|
double font_size,
|
|
glyph_info_t *gi,
|
|
std::vector<glyph_vertex_t> *vertices,
|
|
demo_extents_t *extents)
|
|
{
|
|
if (gi->is_empty)
|
|
return;
|
|
|
|
double scale = font_size / gi->upem;
|
|
|
|
glyph_vertex_t v[4];
|
|
|
|
for (int ci = 0; ci < 4; ci++) {
|
|
int cx = (ci >> 1) & 1;
|
|
int cy = ci & 1;
|
|
|
|
double ex = (1 - cx) * gi->extents.min_x + cx * gi->extents.max_x;
|
|
double ey = (1 - cy) * gi->extents.min_y + cy * gi->extents.max_y;
|
|
|
|
v[ci].x = (float) (p.x + scale * ex);
|
|
v[ci].y = (float) (p.y - scale * ey);
|
|
v[ci].tx = (float) ex;
|
|
v[ci].ty = (float) ey;
|
|
v[ci].nx = cx ? 1.f : -1.f;
|
|
v[ci].ny = cy ? -1.f : 1.f;
|
|
v[ci].emPerPos = (float) (1.0 / scale);
|
|
v[ci].atlas_offset = gi->atlas_offset;
|
|
}
|
|
|
|
vertices->push_back (v[0]);
|
|
vertices->push_back (v[1]);
|
|
vertices->push_back (v[2]);
|
|
|
|
vertices->push_back (v[1]);
|
|
vertices->push_back (v[2]);
|
|
vertices->push_back (v[3]);
|
|
|
|
if (extents) {
|
|
demo_extents_clear (extents);
|
|
for (int i = 0; i < 4; i++) {
|
|
demo_point_t pt = {(double) v[i].x, (double) v[i].y};
|
|
demo_extents_add (extents, &pt);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
GLuint
|
|
demo_shader_create_program (bool draw_only);
|
|
|
|
|
|
#endif /* DEMO_SHADERS_H */
|