Skip to main content

RenderTarget

Struct RenderTarget 

Source
pub struct RenderTarget {
    pub color_texture: Texture,
    pub color_view: TextureView,
    pub msaa_view: Option<TextureView>,
    pub width: u32,
    pub height: u32,
    pub sample_count: u32,
    /* private fields */
}
Expand description

An off-screen GPU render target.

Wraps a Rgba8Unorm texture (single-sample, RENDER_ATTACHMENT | COPY_SRC | TEXTURE_BINDING) and an optional MSAA resolve texture.

Fields§

§color_texture: Texture

The single-sample backing texture (always COPY_SRC for readback).

§color_view: TextureView

Default view over color_texture.

§msaa_view: Option<TextureView>

Optional MSAA multisample texture view. Present when sample_count > 1.

§width: u32

Target width in physical pixels.

§height: u32

Target height in physical pixels.

§sample_count: u32

Effective MSAA sample count (1 = no MSAA, 4 or 8 = MSAA).

Implementations§

Source§

impl RenderTarget

Source

pub fn new( device: &Device, width: u32, height: u32, sample_count: u32, ) -> Result<Self, UiError>

Create a new off-screen render target of width × height pixels with the given MSAA sample_count (1 = no MSAA).

If sample_count > 1 but MSAA is not supported for TARGET_FORMAT by the adapter, sample_count falls back to 1 silently.

§Errors

Returns UiError::Unsupported if width or height is zero.

Source

pub fn new_simple( device: &Device, width: u32, height: u32, ) -> Result<Self, UiError>

Create a new render target with no MSAA (sample_count=1).

Convenience wrapper around RenderTarget::new.

Source

pub fn color_attachment(&self) -> (&TextureView, Option<&TextureView>)

Returns the colour attachment view and optional resolve target.

Under MSAA: (msaa_view, Some(&color_view)) — render into the MSAA surface, resolve into the backing texture. Under no MSAA: (&color_view, None) — render directly into the backing texture.

Source

pub fn texture_view(&self) -> &TextureView

A view over the resolved (single-sample) backing texture.

Use this view for compositing the render target into a parent pass or for sampling in a shader.

Source

pub fn mark_dirty(&mut self)

Mark the render target as dirty (needing re-render).

Source

pub fn mark_clean(&mut self)

Mark the render target as clean (up-to-date).

Source

pub fn is_dirty(&self) -> bool

Return true if the content is stale and needs re-rendering.

Source

pub fn readback_rgba( &self, device: &Device, queue: &Queue, ) -> Result<Vec<u8>, UiError>

Read the render target’s pixel contents back to CPU memory as a tightly packed width * height * 4 RGBA byte vector.

Row padding (from COPY_BYTES_PER_ROW_ALIGNMENT) is stripped.

§Errors

Returns UiError::Render if the GPU poll or buffer mapping fails.

Source

pub fn resize( &mut self, device: &Device, new_width: u32, new_height: u32, ) -> Result<(), UiError>

Resize the render target to new dimensions.

All existing texture resources are dropped and recreated. Any previously-held views or samplers that refer to the old textures become invalid. The dirty flag is set to true.

§Errors

Returns UiError::Unsupported if new_width or new_height is zero.

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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 = 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,