Skip to main content

StreamingTexture

Struct StreamingTexture 

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

An app-owned texture updated from CPU pixel data every frame or so — video frames, animated images, camera feeds, software-rendered panels. Owns the texture lifecycle that every media consumer otherwise hand-rolls around app_texture:

  • creates (and on size/format change, recreates) the TEXTURE_BINDING | COPY_DST texture;
  • uploads frames with Self::write_frame, or Self::write_frame_if_changed for sources that repeat frames (paused video, looping animations) where a cheap content hash saves the redundant upload;
  • hands out a stable AppTexture handle via Self::app_texture for the surface() tree builder. The handle’s identity is stable across write_frame calls — which is what keeps the per-texture bind-group cache warm — and changes only when a size/format change forces a new GPU texture (one cold bind-group rebuild, then warm again).

data is tightly-packed rows of width * height pixels in the texture’s format (RGBA8 variants: 4 bytes/pixel; Rgba16Float: 8 bytes/pixel). Formats follow app_texture’s supported set.

Implementations§

Source§

impl StreamingTexture

Source

pub fn new( device: &Device, format: TextureFormat, width: u32, height: u32, ) -> Self

Create with an initial size. The texture contents are undefined until the first Self::write_frame; draw order guarantees nothing samples it before the first queue submission that follows a write.

Source

pub fn write_frame( &mut self, device: &Device, queue: &Queue, width: u32, height: u32, data: &[u8], )

Upload one frame of tightly-packed pixel rows, recreating the texture first if width/height differ from the current size. Panics if data is not exactly width * height * bytes_per_pixel long.

Source

pub fn write_frame_if_changed( &mut self, device: &Device, queue: &Queue, width: u32, height: u32, data: &[u8], ) -> bool

Self::write_frame, skipped when data hashes identically to the previous accepted frame. Worth it for sources that repeat frames (paused video, looping GIFs at rest); for live video where every frame differs, prefer Self::write_frame and skip the hash. Returns true when an upload happened.

Source

pub fn app_texture(&self) -> AppTexture

The handle to embed in the tree via [damascene_core::surface]. Cheap clone; identity stays stable across Self::write_frame calls so backend bind-group caches stay warm.

Source

pub fn size(&self) -> (u32, u32)

Current texture size (width, height) in texels.

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
Source§

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

Source§

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

Source§

impl<T> Downcast<T> for T

Source§

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.

Source§

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Upcast<T> for T

Source§

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

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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