Skip to main content

SSScene

Struct SSScene 

Source
pub struct SSScene { /* private fields */ }
Expand description

The per-target, per-frame half — what one render target’s worth of geometry looks like this frame.

Borrow model: owns neither the Device/Queue, the render target, nor the SSRenderer. It holds the projection (which is a property of the target) and the frame’s arena, primitive table, mesh stream and draw calls.

One of these serves every player drawing into the same target.

Implementations§

Source§

impl SSScene

Source

pub fn new(device: &Device, config: &SceneConfig) -> Self

Build the target-scoped resources: the projection uniform. The rest of group(0) is this frame’s geometry, so its bind group is built in end_frame — against whichever renderer is drawing the frame — once the buffers are sized. That is why no SSRenderer is needed here.

Source

pub fn stats(&self) -> SceneStats

What the last frame cost.

Counts are always populated. gpu_pass_time_ns needs the device to have been created with Features::TIMESTAMP_QUERY, and the host to attach SSScene::timestamp_writes to its render pass and call SSScene::resolve_timestamps after it.

Source

pub fn timestamp_writes(&self) -> Option<RenderPassTimestampWrites<'_>>

Timestamp writes for the host’s RenderPassDescriptor, or None when the device cannot time.

The host opens the pass (borrow model), so it is the only place these can be attached — the scene can only hand them over.

Source

pub fn resolve_timestamps(&mut self, encoder: &mut CommandEncoder)

Copy this frame’s timestamps back toward the CPU. Call on the same encoder as the pass, after it ends. No-op without the feature.

Source

pub fn encode_offscreen( &mut self, renderer: &mut SSRenderer, device: &Device, encoder: &mut CommandEncoder, )

Draw everything this frame draws outside the host’s pass: the coverage bitmaps, then one layer per player drawn with group alpha.

Call between SSScene::update and SSScene::draw, every frame, on the same encoder the host will open its own pass with. Passes recorded into one encoder execute in order, so what this draws is what the very next pass reads — which is why this player has none of the one-frame lag that engines whose offscreen targets are only readable next frame have to work around. Do not split the two across encoders or frames.

It opens passes of its own and never the host’s, so the host’s target is still drawn in the one pass. Nothing to do — another backend than MaskBackend::Coverage with group alpha off, or a frame where nothing masks or fades — opens none.

Source

pub fn set_group_alpha(&mut self, on: bool)

Draw each player whose alpha is below 1 as one layer, composited at its alpha, rather than fading each of its parts: where two parts overlap, half a character then reads half, not three quarters. What the WebGL player does for every faded player.

Off by default, for what it costs: a render pass per faded player per frame, a layer the size of the target for each faded at once — about 8 MiB at 1920x1080 — and one composite over the target apiece. SceneStats::group_layers counts them. Turning it off frees them at the next update; a frame already built with layers still draws them.

The host calls SSScene::encode_offscreen every frame, which is what draws the layers. Each update reads whether it was called since the one before: a scene it is not called on draws its faded players part by part, as with this off, and so does the first frame after a host starts calling it. A host that stops draws one frame of them unfaded. Players past max_texture_array_layers faded at once are drawn part by part too.

Inside a layer the parts blend against transparency, not against what is behind the player: an Add, Mul or Screen part composites with the player’s own parts alone, and a Mul part over nothing reads black. Its masks clip within the player, as they always do. A crowd is one player, so it fades as one layer; its members’ own alphas still apply part by part.

Source

pub fn group_alpha(&self) -> bool

Whether faded players are drawn as one layer each; see SSScene::set_group_alpha.

Source

pub fn stencil_enabled(&self) -> bool

Whether the hardware stencil is in use for this target. Also what decides whether draw sets a stencil reference and whether pipelines carry a depth-stencil state.

Source

pub fn mask_backend(&self) -> MaskBackend

How this target draws masks.

Source

pub fn config(&self) -> SceneConfig

The config this scene was built from. Retained so a lost device can be replaced by a scene targeting the same formats without the caller having to remember them.

Source

pub fn set_viewport( &mut self, queue: &Queue, width: f32, height: f32, y_down: bool, )

Set the projection to the render target’s pixel dimensions. Remembered, so SSScene::restore_device can re-apply it to a rebuilt buffer. The same viewport again writes nothing, so a host may call this every frame.

Source

pub fn restore_device(&mut self, device: &Device, queue: &Queue)

Rebuild this target’s GPU state against a freshly created device after the previous one was lost. The host calls SSRenderer::restore_device first — that covers pipelines and textures for the whole device — then this once per render target, then crate::SSPlayer::restore_textures once per player.

Source

pub fn update( &mut self, renderer: &mut SSRenderer, device: &Device, queue: &Queue, delta_secs: f32, players: &mut [&mut SSPlayer], )

Advance every player and build this target’s frame.

This is the frame boundary: one begin_frame / end_frame pair spans all the players sharing the target, so their geometry lands in one frame buffer and their draws can be recorded back to back.

Players are drawn in ascending crate::SSPlayer::order, ties keeping the order the caller passed them in; players itself is left as it was. The scene borrows them rather than owning them, so they can live wherever the host keeps them — a Vec, an ECS, an engine’s scene graph — and a host that keeps them in a collection of its own hands that over through SSScene::update_with instead. Each player appends its geometry straight to the frame, in that order.

Source

pub fn update_with<P>( &mut self, renderer: &mut SSRenderer, device: &Device, queue: &Queue, delta_secs: f32, players: &mut [P], player: impl Fn(&mut P) -> Option<&mut SSPlayer>, )

SSScene::update over a collection of the host’s own, each element’s player reached through player, which answers None for an element that holds none — a free slot, say.

For a host that keeps its cast from frame to frame: a Vec<&mut SSPlayer> collected out of it cannot outlive the borrow it holds, so update would cost a fresh one every frame. Ties in order keep the order of players.

When every player is settled — stopped, finished or held with nothing of its own still moving, and unchanged since the last frame — the frame that frame built is kept: nothing is evaluated, rebuilt or uploaded, and SSScene::draw draws it again. One player that moves rebuilds the whole frame, the settled ones with it, since they share its buffer.

Source

pub fn begin_frame(&mut self)

Reset per-frame accumulation. Call once before appending any batches.

Source

pub fn end_frame( &mut self, renderer: &mut SSRenderer, device: &Device, queue: &Queue, )

Upload the accumulated frame to the GPU. Call once after all batches.

Source

pub fn draw<'a>( &'a self, renderer: &'a SSRenderer, rpass: &mut RenderPass<'a>, ) -> usize

Record draw commands into a RenderPass opened by the host. Returns the number of draw calls issued.

Recorded fresh every frame. The draw list changes on most frames as parts appear and disappear, so a recording would be invalidated more often than it is replayed.

A player drawn with group alpha is one draw here: its layer, folded back in its place in the order.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,