Skip to main content

Scene

Struct Scene 

Source
pub struct Scene {
    pub draws: Vec<DrawEntry>,
    pub viewport: Option<ViewportRect>,
}
Expand description

A frame’s worth of draws.

The order of DrawEntrys is the order they are recorded in. Recording compares every set_* against the state the previous draw left behind, so consecutive draws that share a pipeline or bind group skip the redundant call: ordering draws by pipeline, and then so that neighbours share their bind groups, minimizes state changes without changing what is drawn. A caller is also free to order the draws for opaque-then-transparent compositing, which is a correctness requirement rather than a performance one; across scenes, DrawOrder and Scene::record_composited take that job over.

Fields§

§draws: Vec<DrawEntry>

The draws to run, in order.

§viewport: Option<ViewportRect>

The region of the target every draw is recorded into, or None to leave the pass’s own viewport alone.

Whole-scene state rather than per-draw: wgpu’s viewport has no reset call, so a scene that letterboxes itself states one here and a scene that draws full-target states none.

Implementations§

Source§

impl Scene

Source

pub fn new() -> Self

An empty scene.

Source

fn resolved_viewport( &self, fallback: Option<ViewportRect>, ) -> Option<ViewportRect>

The region the scene records into when fallback may stand in for the viewport the scene itself states.

Split out from Scene::record so the choice is testable without a render pass: the recording needs a real one, and which region a scene ends up with is the rule that matters.

Source

pub fn record(&self, pass: &mut RenderPass<'_>, fallback: Option<ViewportRect>)

Record the scene into pass, drawing into fallback when the scene states no viewport of its own.

wgpu has no call that resets a viewport, so a caller recording several scenes into one pass has to pass the whole target as fallback: a scene that states none would otherwise inherit the region the previous scene set. None leaves the pass’s region exactly as it is, for a caller that set one itself.

Source

pub fn record_composited( pass: &mut RenderPass<'_>, scenes: &[&Scene], fallback: Option<ViewportRect>, )

Record the draws of several scenes into pass as one composite, drawing into fallback where a scene states no viewport of its own.

The scenes’ draws are grouped by their DrawOrder rather than kept in scene order: the sequenced ones of every scene first, then the depth-sorted ones of every scene pooled together back-to-front, then the trailing ones. The pool spanning scenes is what lets blended geometry from one source composite by depth against another’s, instead of by which scene recorded first. A scene whose draws state no order keeps its place, so a caller that never tags a draw sees the frame Scene::record would have given.

Every draw draws into the region its own scene resolves to — the scene’s Scene::viewport or fallback — so the pool interleaving scenes never moves a draw out of its scene’s letterbox; the deduplicated set_* recording keeps the repeated regions from repeating the calls.

Trait Implementations§

Source§

impl Clone for Scene

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Scene

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Scene

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Scene

§

impl !UnwindSafe for Scene

§

impl Forget for Scene

§

impl Freeze for Scene

§

impl Send for Scene

§

impl Sync for Scene

§

impl Unpin for Scene

§

impl UnsafeUnpin for Scene

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,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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>

§

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,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more