Skip to content

C API reference

The reference for include/sona.h and the optional modules' headers (sona_body.h, sona_track.h, sona_npc.h, sona_xr.h, sona_editor.h, sona_xsdk.h), version 1.1 (SONA_VERSION_MAJOR 1, SONA_VERSION_MINOR 1), SONA_ABI 1. Every public function is listed once, under the part of the header that declares it, with its signature, its parameters, what it returns and its rules. Where this page and the header differ, the header wins. The same entries, with every struct and constant, are in api/api.json for tools.

Conventions are the web SDK's: metres, Y up, left-handed, avatars face -Z at turn 0 and stand about 1.8 m tall. Matrices are row-major and row-vector (v' = v * M).

The reference by area

Version

This page is version 1.1.0 of the library: sona_version() returns "1.1.0", and SONA_ABI is 1. 1.1 keeps every 1.0 call, struct and layout: a 1.0 host builds against the 1.1 header unchanged and draws the same, but for these:

  • Pictures. A new renderer starts with the web's quality defaults: 4 samples on a hardware GPU (1 on a software rasteriser), mip chains and coverage-preserving mips. sona_renderer_set_quality with msaa 1 and flags 0 draws without them.
  • GL state. With multisampling, GL and GLES also change the renderbuffer binding in sona_draw and sona_snapshot.

Within 1.x nothing breaks for two minor versions (the stable ABI). The changelog lists every addition.


Rules every function follows

  • One owner thread. All calls on one sona_ctx, and on its avatars and renderers, come from one thread at a time. The only exceptions are sona_complete and sona_http_done, which a source or an HTTP layer may call from any thread.
  • Completed exactly once. Every sona_request and every sona_http_reply is completed exactly once, and stays valid until then: after cancel (which only asks), and after sona_close. A source must complete every read it accepted, also after cancel, and the host must not unload a source's code until its reads are complete.
  • Callbacks run on the owner thread. The core calls a source's read and an HTTP layer's send only on the owner thread, inside sona_open or sona_update, so engines can start their own main-thread requests from them.
  • No blocking I/O. Work that needs bytes returns SONA_PENDING or moves an avatar through its states. Results arrive through sona_update and sona_poll_event.
  • No allocation per frame. After the first frames, sona_update, sona_pose and sona_draw do not allocate. Memory comes from the config's allocator and is counted against the budget.
  • Pointer lifetime. Pointers handed out (sona_pose_data, event strings, clip info) stay valid until the next sona_update on that ctx, unless a function says otherwise.
  • Explicit padding. Every public struct has explicit padding, so each field sits at its natural alignment on every ABI. sona_struct_size and sona_struct_offset let a binding check its mirror of every struct when it loads.

Threading and memory

  • The owner thread calls everything. Inside sona_update the core drains completed reads, commits finished jobs, runs build steps inside build_budget_ms, advances clocks and poses due avatars. sona_draw and sona_snapshot fold the palettes with their own view.
  • The device's queue. On Vulkan, sona_snapshot and sona_item_preview_snapshot submit on the VkQueue the host passed and wait for it. Vulkan requires the host to keep every other thread off that queue during those calls.
  • A loaded catalogue never changes, so any thread may read it at once, with no ctx.
  • Jobs are: decode an asset, decode a clip, bake a face sheet, build an avatar, CPU-skin a mesh slice. With workers (the core's threads or the host's sona_jobs) they run there and are committed on the owner thread in the next sona_update. With worker_threads = 0 (WASM, a single-threaded Xbox 360 host) they run inside the build budget.
  • Decoded shared data (assets, clips, textures) is immutable once committed and reference counted. Per-avatar data belongs to the avatar.
  • The idle chooser's randomness comes from config.seed. A fixed seed makes every run repeatable.
  • Every allocation goes through the config's allocator. sona_stats reports bytes in cpu_mb and gpu_mb. Eviction is idle first, oldest first. An Xbox 360 host sets budget.total (for example a budget of 96 MiB) and the caps; nothing in the core assumes a heap bigger than the budget.

Left out on purpose

  • No glTF export, for size only. The data API hands out every mesh, material and texture.
  • No pointer controls, badge element, or resize and visibility observers: those are the web's DOM pieces. Wire input to sona_camera_orbit.
  • No origin check: native apps have no origin. The licence file and the native check replace it. The WASM build keeps the web's origin check through the bridge.
  • No offline gate use. Local sources are the offline path.
  • No "do not clear" draw flag.
  • The web's samples() and benchmark() live in sona-bench.

This page as Markdown · All the docs as one file (llms-full.txt)