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
impl SSScene
Sourcepub fn new(device: &Device, config: &SceneConfig) -> Self
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.
Sourcepub fn stats(&self) -> SceneStats
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.
Sourcepub fn timestamp_writes(&self) -> Option<RenderPassTimestampWrites<'_>>
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.
Sourcepub fn resolve_timestamps(&mut self, encoder: &mut CommandEncoder)
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.
Sourcepub fn encode_offscreen(
&mut self,
renderer: &mut SSRenderer,
device: &Device,
encoder: &mut CommandEncoder,
)
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.
Sourcepub fn set_group_alpha(&mut self, on: bool)
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.
Sourcepub fn group_alpha(&self) -> bool
pub fn group_alpha(&self) -> bool
Whether faded players are drawn as one layer each; see
SSScene::set_group_alpha.
Sourcepub fn stencil_enabled(&self) -> bool
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.
Sourcepub fn mask_backend(&self) -> MaskBackend
pub fn mask_backend(&self) -> MaskBackend
How this target draws masks.
Sourcepub fn config(&self) -> SceneConfig
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.
Sourcepub fn set_viewport(
&mut self,
queue: &Queue,
width: f32,
height: f32,
y_down: bool,
)
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.
Sourcepub fn restore_device(&mut self, device: &Device, queue: &Queue)
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.
Sourcepub fn update(
&mut self,
renderer: &mut SSRenderer,
device: &Device,
queue: &Queue,
delta_secs: f32,
players: &mut [&mut SSPlayer],
)
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.
Sourcepub 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>,
)
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.
Sourcepub fn begin_frame(&mut self)
pub fn begin_frame(&mut self)
Reset per-frame accumulation. Call once before appending any batches.
Sourcepub fn end_frame(
&mut self,
renderer: &mut SSRenderer,
device: &Device,
queue: &Queue,
)
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.
Sourcepub fn draw<'a>(
&'a self,
renderer: &'a SSRenderer,
rpass: &mut RenderPass<'a>,
) -> usize
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.