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: TextureThe single-sample backing texture (always COPY_SRC for readback).
color_view: TextureViewDefault view over color_texture.
msaa_view: Option<TextureView>Optional MSAA multisample texture view. Present when sample_count > 1.
width: u32Target width in physical pixels.
height: u32Target height in physical pixels.
sample_count: u32Effective MSAA sample count (1 = no MSAA, 4 or 8 = MSAA).
Implementations§
Source§impl RenderTarget
impl RenderTarget
Sourcepub fn new(
device: &Device,
width: u32,
height: u32,
sample_count: u32,
) -> Result<Self, UiError>
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.
Sourcepub fn new_simple(
device: &Device,
width: u32,
height: u32,
) -> Result<Self, UiError>
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.
Sourcepub fn color_attachment(&self) -> (&TextureView, Option<&TextureView>)
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.
Sourcepub fn texture_view(&self) -> &TextureView
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.
Sourcepub fn mark_dirty(&mut self)
pub fn mark_dirty(&mut self)
Mark the render target as dirty (needing re-render).
Sourcepub fn mark_clean(&mut self)
pub fn mark_clean(&mut self)
Mark the render target as clean (up-to-date).
Sourcepub fn readback_rgba(
&self,
device: &Device,
queue: &Queue,
) -> Result<Vec<u8>, UiError>
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.
Sourcepub fn resize(
&mut self,
device: &Device,
new_width: u32,
new_height: u32,
) -> Result<(), UiError>
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§
impl !RefUnwindSafe for RenderTarget
impl !UnwindSafe for RenderTarget
impl Freeze for RenderTarget
impl Send for RenderTarget
impl Sync for RenderTarget
impl Unpin for RenderTarget
impl UnsafeUnpin for RenderTarget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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