cf_make_custom_shape¶
Category: draw
GitHub: cute_draw.h
Registers a custom SDF shape with the renderer.
| Parameters | Description |
|---|---|
sdf_src |
GLSL snippet defining float sdf(vec2 p, ShapeParams s). |
Return Value¶
A handle to draw with via cf_draw_custom_shape or cf_draw_custom_shape_fill. A zero id means registration failed (compile error, or unsupported backend).
Remarks¶
The snippet must define a signed distance function returning the distance in world
units from point p to the shape's surface (negative inside). ShapeParams carries
the 16 floats passed at draw time as eight vec2s named a through h, plus a
vec4 attributes from cf_draw_push_vertex_attributes. The builtin distance helpers
(distance_box, distance_segment, distance_triangle, distance_polygon,
distance_arrow) are available, so most shapes are a few min/max combinators:
// params: a = center, b.x = radius
float sdf(vec2 p, ShapeParams s)
{
return length(p - s.a) - s.b.x;
}
The function MUST be a true distance bound (Lipschitz constant <= 1). The renderer
trusts it for tile binning and occlusion culling; an invalid bound (e.g.
|x|+|y| - r) will drop pixels. All registered shapes batch together with builtin
shapes, sprites, and text -- no extra draw calls or pipeline switches. Antialiasing,
stroked outlines, colors, and all draw state apply automatically.
Register shapes once at init time (each registration recompiles the renderer's internal shaders), and before creating any custom draw shaders. Requires runtime shader compilation and a compute-capable backend.
Related Pages¶
CF_CustomShape
cf_draw_custom_shape
cf_draw_custom_shape_fill
cf_draw_push_vertex_attributes