Skip to main content

Module portal

Module portal 

Source
Expand description

The portal host element: a UI rectangle that displays an offscreen render target — the live (or snapshot) output of a Bevy camera drawing into a GPU texture.

It is the GPU sibling of crate::canvas: both are a styled ImageNode whose backing Image this crate manages. Where the canvas CPU-rasterizes a display list, a portal’s image is a render target a secondary camera draws into (render-to-texture), so a portal can embed a minimap, a picture-in-picture, or a per-item 3D preview directly inside the React UI.

§Ownership split

This crate owns only the texture registry (RenderTargets) and the portal↔texture binding. The consuming app owns the cameras, meshes, and render layers: it creates a named target, spawns a camera pointed at RenderTarget::camera_target, tags that camera with PortalCamera, and (for snapshots) invalidates or set_modes it. React never invents target names — it receives them from the app over the typed event channel and echoes them back as <portal target={name} />.

§Render model

Each target is RenderMode::Live (its camera renders every frame — minimaps, rotating previews) or RenderMode::Snapshot (renders once when registered or invalidated, then its camera is deactivated and the texture reused — cheap for static thumbnails). drive_render_targets toggles Camera::is_active.

§Resolution

Each target’s Resolution is Auto (the texture is sized to the binding portal’s laid-out box, like the canvas — crisp output and correct camera aspect for free) or Fixed (a fixed cost, for a target shared by several portals).

Structs§

PortalCamera
Marks a camera as the renderer for a named target, so drive_render_targets can control its activity for RenderMode::Snapshot. The app inserts it on the camera it spawns for a target.
PortalPlaceholder
A shared 1×1 transparent texture a portal shows until (and after) it is bound to a live target. Held in a resource so every unbound portal shares one image.
RPortal
Marks a reconciler node as a <portal> displaying the named target. The bevy-react reconciler inserts it; bind_portals keeps the node’s ImageNode pointed at the registry’s texture for this name.
RenderTarget
A handle to a freshly created target. Use camera_target to point a camera at it.
RenderTargetSpec
Parameters for RenderTargets::create.
RenderTargets
The registry of named offscreen render targets. Insert it (the plugin does) and have app systems create targets as game state demands.

Enums§

RenderMode
How often a target’s camera renders into its texture.
Resolution
How a target’s texture resolution is chosen.

Functions§

bind_portals
Point every <portal>’s ImageNode at the texture for its target name (or the placeholder when the name isn’t registered), and record the portal as the target’s binder for Resolution::Auto sizing. Only writes image when it actually changes, so it doesn’t needlessly re-extract the node every frame.
blank_portal_image
A 1×1 transparent image, mirroring crate::canvas::blank_canvas_image.
drive_render_targets
Drive resolution and the snapshot lifecycle each frame:
init_portal_placeholder
Create the shared PortalPlaceholder image at startup.