Skip to content

cf_query_max_canvas_targets

Category: graphics
GitHub: cute_graphics.h


Returns how many color targets a canvas can have on the current device.

int cf_query_max_canvas_targets(void);

Return Value

A value from 4 to CF_MAX_CANVAS_TARGETS.

Remarks

cf_make_canvas fails with an assert and returns an invalid canvas when target_count exceeds this. Per backend:

  • D3D12 and Metal: 8.
  • Vulkan: 4. Vulkan only guarantees four color attachments, and SDL_GPU doesn't expose the device's real limit, so CF reports the guarantee.
  • GLES/WebGL2: the smaller of GL_MAX_DRAW_BUFFERS and GL_MAX_COLOR_ATTACHMENTS, capped at 8. GLES 3.0 and WebGL2 only guarantee four.
  • WebGPU: the smaller of maxColorAttachments and maxColorAttachmentBytesPerSample / 8 (an RGBA8 target costs 8 bytes per sample), capped at 8. The spec guarantees four. Wider formats cost more, so a canvas of 16- or 32-bit float targets may fit fewer.

Check this before making a canvas with more than four targets, and fall back to fewer targets (or more passes) when it comes up short. Requires a running app.

CF_MAX_CANVAS_TARGETS
CF_CanvasParams
cf_make_canvas
cf_query_backend