Rendering Streams
The render sender is how your application's pixels reach the room. You create one sender per target, then drive a simple loop: begin frame → render into the provided textures → show frame. QAROS takes care of encoding, transport, and — via the mixer — warping and compositing your content into every viewer's personal view.
Finding rendering targets
Your application decides which targets it renders for: one, some or all of them. QAROS does not choose for it, not even for an app it launches. Find the targets in the peer list:
- Watch peers with
qar_peer_subscribe_updates(), and list the ones already there once withqar_query_peer_specs(). Subscribe first, so a target joining in between is not missed. - A peer whose role (
qar_peer_spec_get_role()) isQAR_PEER_ROLE_TARGETand whose presence (qar_peer_spec_get_presence()) isQAR_PEER_PRESENCE_ONLINE, orQAR_PEER_PRESENCE_UNKNOWNon a hub that has not reconciled it, is a target you can render for: a headset, a visualizer receiver, a camera's view in the visualizer. Its category, device name and family say which one (Working with Peers). - Create the app volume first, then one sender and one camera per target you serve. The sender attaches its target to your app volume, and that is what makes the target ask for your content. Use each sender's own per-frame eye poses and FOV to draw the same scene for that user.
- Callbacks run asynchronously. Queue the target ID for your render thread, synchronize the handoff, and keep callback state alive through session/subscription teardown.
- See the standalone
vulkan_cubesource for the complete dynamic-loading, local-app onboarding and multi-camera loop.
static void on_peer(QarPeerSpec* peer, void* user_state)
{
QarPeerRole role = QAR_PEER_ROLE_INTERNAL;
QarPeerPresence presence = QAR_PEER_PRESENCE_UNKNOWN;
QarPeerId target_peer_id = qar_peer_id_default();
if(qar_result_is_error(qar_peer_spec_get_role(peer, &role)) || role != QAR_PEER_ROLE_TARGET
|| qar_result_is_error(qar_peer_spec_get_presence(peer, &presence))
|| (presence != QAR_PEER_PRESENCE_ONLINE && presence != QAR_PEER_PRESENCE_UNKNOWN)
|| qar_result_is_error(qar_peer_spec_get_id(peer, &target_peer_id)))
return;
/* Not served yet? Hand target_peer_id to your render thread, which
creates its sender - see "Creating a sender" below. A served target
whose presence turns OFFLINE, LEAVING or RETIRED is gone: stop its
sender; an OFFLINE one may come back ONLINE. UNKNOWN is a hub that
has not reconciled the peer: render for it. */
}
qar_result_log_if_error(
qar_peer_subscribe_updates(session, on_peer, NULL, subscription_token));
qar_render_sender_subscribe_requests() reports targets that already request your content. A target requests it only once it is attached to your app volume, and nothing is attached to a new application's own volume. So it is not a way to find targets: a sender for the target is what attaches it.
Creating a sender
QarRenderSenderInit init = qar_render_sender_init_default();
init.peer_id = target_peer_id; /* who receives this stream */
init.enable_auto_reconnects = true; /* survive network hiccups */
init.app_volume_id = &volume_id; /* composite into our app volume */
init.graphics_api = QAR_GRAPHICS_API_CPU;
init.color_format = QAR_PIXEL_FORMAT_R8G8B8A8;
init.depth_format = QAR_PIXEL_FORMAT_R32_FLOAT;
/* Describe the views inside one video frame: stereo color + depth. */
init.texture_layout = QAR_FRAME_LAYOUT_SIDE_BY_SIDE;
init.frame_views[0] = (QarRenderFrameView){
.data_type = QAR_VIDEO_FRAME_VIEW_TYPE_COLOR,
.eye = QAR_VIDEO_FRAME_VIEW_EYE_LEFT,
.texture_index = 0 };
/* ... one entry per view (right eye, depth views, ...) ... */
init.frame_views_count = 4;
QarRenderSender* sender = NULL;
qar_result_log_if_error(
qar_render_sender_create(session, &init, NULL, &sender));
The C# snippet above is illustrative — it tracks the Quaternar.Qaros binding surface but
is not yet compiled from a published sample project.
Key choices:
- Target peer — a sender streams to one peer: a target app from the peer list above, or one you invited yourself.
- App volume — required. Create the volume first and pass its ID so the mixer composites the stream inside that box; a stream without one is not placed in the scene. See App Volumes.
- Graphics API —
QAR_GRAPHICS_API_CPU(portable, always available, no extension), or a GPU API with exactly one matching extension ininit.header.next:QAR_GRAPHICS_API_D3D11+QarStreamParamsD3D11,QAR_GRAPHICS_API_VULKAN+QarStreamParamsVulkan, orQAR_GRAPHICS_API_OPENGL+ theQarStreamParamsOpenGl*struct matching your context (EGL, WGL or GLX). GPU frame textures are created on the session's adapter (see choosing the GPU). - Frame views — the order you declare in
frame_viewsis guaranteed: the layout (qar_render_sender_layout) and every frame list their views in exactly that order, each with theeyeanddata_typeyou declared at that position. Textures come in the order the views first use them (one per view forSEPARATED_TEXTURES, one per data type for side by side and layered); each view'stexture_indexnames its texture. A view the layout provides that you did not declare follows yours. - Frame layout — how views pack into textures:
SIDE_BY_SIDE(both eyes in one texture),SEPARATED_TEXTURES, orLAYERED(texture array). The negotiated layout can be queried (qar_render_sender_layout) and changed at runtime (qar_render_sender_change_layout). - Depth matters. Sending real depth (not just color) is what enables correct occlusion between app volumes and low-latency warping. Send it whenever you can.
- Alpha mode — what your color's alpha channel means. See Transparency below.
Color encoding
Every QAROS device shows the stream's 8-bit color as sRGB-encoded, the way a display expects it. The textures a sender gives you are plain UNORM, so the numbers you write are stored as they are. If your renderer shades in linear light, do one of these:
- Encode in your last shader pass: convert linear color to sRGB before writing it. Best quality, since the encoding happens at full precision.
- Declare linear color and let QAROS encode it: chain a
QarRenderSenderColorEncodingExtwithQAR_COLOR_ENCODING_LINEAR(qar_render_sender_color_encoding_ext_default()); in C# setRenderSenderOptions.ColorEncoding = ColorEncoding.Linear, in RustRenderSenderConfig::color_encoding = ColorEncoding::Linear. It costs one GPU pass per frame in your process. Send linear color asQAR_PIXEL_FORMAT_R16G16B16A16: in an 8-bit format the darks band slightly, because 8-bit linear values have already lost precision there.
Linear values sent without either look too dark on every device. Alpha is never encoded. Premultiplied color is premultiplied in linear light, then encoded: what an sRGB render target produces when you blend over a transparent-black clear.
If you render into a texture of your own first and then copy into the sender's texture, an sRGB render target (for example DXGI_FORMAT_B8G8R8A8_UNORM_SRGB) gives you encoded bytes with no extra work.
Render loop
By default a sender is request-driven: begin-frame waits for the receiver's render request and gives you the poses for the display time it names. If your application renders from a loop of its own, at its own rate, declare a free-running loop instead: chain a QarRenderSenderRenderLoopExt with QAR_RENDER_LOOP_FREE_RUNNING (qar_render_sender_render_loop_ext_default()); in C# set RenderSenderOptions.RenderLoop = RenderLoop.FreeRunning, in Rust RenderSenderConfig::render_loop = RenderLoop::FreeRunning.
| Render loop | Begin-frame waits for | Poses |
|---|---|---|
QAR_RENDER_LOOP_REQUEST_DRIVEN / RequestDriven (no extension) | The receiver's render request | For the display time the request names |
QAR_RENDER_LOOP_FREE_RUNNING / FreeRunning | Only a destination, which the receiver keeps ready | Predicted from the newest head pose for when the frame will be shown |
A free-running application takes its poses before it begins the frame, so it renders while the receiver hands the frame's destination back. Each frame:
- Take the poses:
qar_render_sender_next_render_pose(C#RenderSender.NextRenderPose, RustRenderSender::next_render_pose) gives each view's pose and field of view, predicted for when the frame will be shown. - Render into your own target with them.
- Begin the frame:
qar_render_sender_begin_frame, or pollqar_render_sender_try_begin_frame(C#TryBeginFrame, Rusttry_begin_owned_frame). It waits only for the receiver's destination, never for a render request, and opens the frame with exactly the poses of step 1. - Copy your target into the sender's frame.
- Show the frame.
- A blocking begin-frame also throttles a renderer that runs faster than the mixer consumes frames: it waits until the receiver hands a destination back.
- Before the viewer's first head pose, step 1 fails with
QAR_STATUS_RENDERING_PRODUCER_MISSING_POSE_DATA(C#RenderingProducerMissingPoseData, RustStatusCode::RENDERING_MISSING_POSE_DATA); retry on the next iteration. On a request-driven sender it fails withQAR_STATUS_LOGIC_ERROR. - A second call before begin-frame replaces the poses.
- A render loop value the runtime does not know is refused with
QAR_STATUS_ARGUMENT_NOT_SUPPORTED. - How to drive senders for several viewers in each mode, blocking or not, and which loop to choose: Render Loops.
Transparency
A sender declares what its color's alpha means, and the mixer composites the stream by it. Chain a QarRenderSenderAlphaModeExt (qar_render_sender_alpha_mode_ext_default(), then set alpha_mode) on init.header.next; in C# set RenderSenderOptions.AlphaMode, in Rust RenderSenderConfig::alpha_mode (ColorAlphaMode).
| Alpha mode | Means | The mixer |
|---|---|---|
QAR_COLOR_ALPHA_MODE_UNSPECIFIED / Unspecified (default) | Nothing declared | Draws the stream opaque, unless the operator turns on mixerSourceAlpha for undeclared streams |
QAR_COLOR_ALPHA_MODE_OPAQUE / Opaque | The alpha channel means nothing | Every pixel fully covers what is behind it |
QAR_COLOR_ALPHA_MODE_PREMULTIPLIED / Premultiplied | Color is premultiplied by alpha, and alpha is the pixel's coverage | Blends each pixel over what is behind it by its coverage |
QAR_COLOR_ALPHA_MODE_STRAIGHT / Straight | Color is not multiplied by alpha, and alpha is the pixel's coverage | As Premultiplied: QAROS premultiplies the color before the frame leaves your application |
- Premultiplied is what a renderer produces when it clears to transparent black (0, 0, 0, 0) and draws with ordinary alpha blending. Declare it only if the alpha channel stays correct up to the frame you send: a post-processing pass that overwrites alpha makes your content disappear. Declare
Opaquethen. - Translucent pixels that write depth are blended at their depth. Pixels with coverage but no depth (most transparent materials) are placed at the middle of your app volume along each view ray, so they show and occlude there, without parallax.
- Color brighter than its alpha — glow, bloom, additive particles, even with alpha 0 — adds light over what is behind it.
- Alpha crosses the network for a
Premultipliedstream, at half resolution, so hard edges are slightly softer than on one machine. Both ends must run the same QAROS version. - Straight costs one GPU pass per frame in your process, even when the frame would otherwise be copied unchanged. If your renderer can produce premultiplied color directly, declare
Premultipliedinstead. - Depth format — the format of the depth textures the sender creates for you. Pick the one your renderer already draws depth in; see Choosing a depth format.
Choosing a depth format
The sender creates its depth textures in depth_format (C# DepthFormat, Rust RenderSenderConfig::depth_format), so render straight into them in your renderer's own format. Receivers always get 32-bit float depth: D16 and D24 are widened before the frame leaves your application, and the stencil of a depth-stencil format is dropped.
depth_format | CPU | D3D11 | OpenGL, Vulkan |
|---|---|---|---|
QAR_PIXEL_FORMAT_R32_FLOAT, QAR_PIXEL_FORMAT_D32_FLOAT | yes | yes | yes |
QAR_PIXEL_FORMAT_D16_UNORM | yes | yes | yes |
QAR_PIXEL_FORMAT_D24_UNORM_S8_UINT, QAR_PIXEL_FORMAT_D32_FLOAT_S8X24_UINT | no | no | yes, if the GPU can create it |
- D3D11 has no depth-stencil formats. A D3D11 sender's textures are shared with QAROS through a keyed-mutex handle, and D3D11 cannot share a D24S8 or D32S8 texture. A D3D11 renderer with a D24S8 target copies or converts its depth to D16, D32 or R32.
- D32 works everywhere. Some GPUs cannot create D24S8 at all (AMD has no
D24_UNORM_S8_UINTin Vulkan). - CPU frames: a D16 texel is 2 bytes, but rows keep the frame's
pitch, which is at least 4 bytes a pixel.
A format the graphics API or the GPU cannot take fails qar_render_sender_create at once with QAR_STATUS_RENDERING_PRODUCER_DEPTH_FORMAT_NOT_SUPPORTED (Rust StatusCode::RENDERING_DEPTH_FORMAT_NOT_SUPPORTED), before any receiver is waited for. Trying your renderer's own format first therefore costs nothing:
init.depth_format = QAR_PIXEL_FORMAT_D24_UNORM_S8_UINT;
QarResult r = qar_render_sender_create(session, &init, NULL, &sender);
if (qar_result_has_code(&r, QAR_STATUS_RENDERING_PRODUCER_DEPTH_FORMAT_NOT_SUPPORTED))
{
/* This GPU cannot create D24S8: render depth into D32 instead. */
init.depth_format = QAR_PIXEL_FORMAT_D32_FLOAT;
r = qar_render_sender_create(session, &init, NULL, &sender);
}
To render into a depth-stencil texture, attach it as a depth-stencil target:
- Vulkan — the image has depth-stencil attachment usage. Its layout barriers name
VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, including the release toVK_QUEUE_FAMILY_EXTERNALbeforeshow_frame. Hand the frame back as for any format: set each texture'slayoutandqueue_family_indexand signalsynchronization.semaphore. - OpenGL — attach the texture at
GL_DEPTH_STENCIL_ATTACHMENT; it is aGL_TEXTURE_2D_ARRAY, so useglFramebufferTextureLayer.
The frame loop
for (;;)
{
/* 1. Begin: get the poses/FOVs you must render with. */
QarRenderFrameInfo* info = NULL;
QarResult r = qar_render_sender_begin_frame(sender, NULL, &info);
if (qar_result_is_error(r)) { /* reconnecting? volume unresolved? */ continue; }
QarPose pose; QarFov fov;
qar_render_frame_info_get_view_pose(info, 0, &pose);
qar_render_frame_info_get_view_fov(info, 0, &fov);
/* ... same for the other views ... */
/* 2. Get the frame's textures and render into them. */
QarVideoFrameCpu frame;
qar_render_sender_frame_cpu(sender, &frame);
/* frame.textures[i].texture_data / .pitch / .size — write your pixels.
frame.texture_views[i] is the view you declared at frame_views[i];
its texture_index names the texture it lives in. */
render_my_scene(&frame, &pose, &fov);
/* 3. Show: submit with the projection metadata you used. */
QarRenderFrameShow show = qar_render_frame_show_default();
show.rendered_near_far.near_plane = 0.1f;
show.rendered_near_far.far_plane = 100.0f;
show.depth_scale = 1.0f;
qar_result_log_if_error(qar_render_sender_show_frame(sender, &show));
qar_render_frame_info_handle_destroy(info);
}
begin_frame fails with the recoverable QAR_STATUS_RENDERING_PRODUCER_APP_VOLUME_UNRESOLVED until the sender's app volume resolves (and again if it is closed): there is no app content space to hand poses out in yet, and no room-space pose is given instead. Keep calling — the call waits about 16 ms, so the loop does not spin — and recreate a volume you closed.
The contract to respect: render with the pose and FOV that begin_frame gives you, and report the near/far you actually used in show_frame. The mixer uses exactly this metadata (plus your depth buffer) to re-project your frame to the viewer's latest head pose — wrong metadata shows up as swimming or misplaced content, not as an error code.
Per-frame overrides are possible when you must deviate: chain a QarRenderFrameShowViewOverridesExt into show.header.next with per-view pose/FOV overrides.
Beginning a frame without blocking
qar_render_sender_begin_frame_async begins the frame in the background, so a render thread can pipeline instead of blocking: same poses, failures and wait through a paused stream as qar_render_sender_begin_frame.
static void on_frame(QarResult status, QarRenderFrameInfo* frame_info, void* user_state)
{
/* A library thread, exactly once: the frame, or QAR_STATUS_TIMEOUT once the
* token is cancelled or destroyed. Hand frame_info to the render thread; it
* owns it and destroys it with qar_render_frame_info_handle_destroy. */
}
QarResult r = qar_render_sender_begin_frame_async(sender, on_frame, &slot, token);
/* An error here: the callback never fires. */
- One frame at a time. Begin the next frame only after showing (or dropping) this one.
- Destroying the sender (or its session) cancels a pending begin-frame and waits for its callback, unless it is made from that very callback.
The D3D11 path
On Windows, request QAR_GRAPHICS_API_D3D11 and chain QarStreamParamsD3D11:
QarStreamParamsD3D11 d3d = qar_stream_params_d3d11_default();
d3d.d3d11_device = my_device1;
d3d.d3d11_context = my_context1;
d3d.color_bind_flags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
d3d.depth_bind_flags = D3D11_BIND_DEPTH_STENCIL;
d3d.acquire_keyed_mutex_sync = true; /* let QAROS manage keyed-mutex sync */
init.header.next = &d3d.header;
qar_render_sender_frame_d3d11 then hands you shared D3D11 textures to render into directly — no CPU copy (D3D11 Rendering tutorial). Set acquire_keyed_mutex_sync = false only if you need to manage the keyed-mutex acquire/release chain yourself (e.g. when copying through a chain of shared textures).
Reading back the viewer: hand tracking
The stream is bidirectional: the target device reports input, and you can read the viewer's hands each frame:
QarDeviceHandsWithJoints hands;
if (qar_result_is_success(qar_render_sender_last_hands(sender, &hands)))
{
/* 26 joints per hand, with locations and velocities, in app content
space: the same space your view poses are in */
}
Hand poses, joint radii and velocities come in app content space, the space you render in (app units, under the volume's app pose and scale), so hit-test them against your content directly. pose is the hand's aim pose (its −Z is the hand ray). The last sample repeats for up to 1 s, then the hand reports untracked: poll once per frame. While the app volume is unresolved, both hands report untracked.
Hand data another peer publishes on a data stream is different: it is in that publisher's room space and is never converted for you.
This is how a source application implements grabbing, pointing, and touch against its own content (combine with gesture events for higher-level interactions).
Lifecycle and failure
enable_auto_reconnects = truemakes the sender survive network drops and target restarts transparently — frame calls fail while disconnected (typicallyQAR_STATUS_MEDIA_STREAMING_STREAM_IS_RECONNECTING) and recover on their own. A receiver that pauses (its display is not visible) makes them fail withQAR_STATUS_MEDIA_STREAMING_STREAM_IS_PAUSEDuntil it resumes; keep the sender. A dead peer is noticed within about 2 s, and a killed and restarted peer streams again within a few seconds.- When the stream is closed for good,
begin_framereturnsQAR_STATUS_RENDERING_PRODUCER_STREAM_IS_CLOSED: the sender has closed itself, so destroy it. Create a new sender if the target is still in the peer list and you still want to serve it. A restarted target keeps its peer id and stays online, so the peer list reports no change: do not wait for an update to recreate it. When a Target Restarts has the pattern and code. - If your application is killed and relaunched, its new sender takes the stream over from the dead instance within about 2-3 s. A second, concurrently running instance is refused while the first is still live.
- Destroy with
qar_render_stream_handle_destroy(sender). - Rendering senders are per target. For several users viewing the same scene, create a sender and camera for each target you serve from the peer list (Finding rendering targets); use each target's poses and FOV even when the scene objects are shared.
Compiled tutorial
This page is backed by the compiled example cpu_rendering_visualizer.c, which obtains a session, finds its targets in the peer list, and streams CPU-rendered frames to them:
- Source:
qaros/qar-streaming-c/examples/cpu_rendering_visualizer.c - Example walkthrough: CPU Rendering with a Visualizer
- Rust walkthrough: CPU Rendering
The D3D11 path is backed by d3d11_render_sender.c, which picks its target the same way, chains a D3D11.1 device into the sender and clears each colour view of the shared textures on the GPU:
- Source:
qaros/qar-streaming-c/examples/d3d11_render_sender.c - Example walkthrough: D3D11 Rendering
- Rust walkthrough: D3D11 Rendering