Skip to main content

RenderTarget

Enum RenderTarget 

Source
pub enum RenderTarget<'a> {
    Surface,
    SurfaceWithDepth {
        depth_view: &'a TextureView,
        clear_value: Option<f32>,
    },
    Framebuffer(&'a Framebuffer),
}
Expand description

A render target that can be either a window surface or an offscreen framebuffer.

This enum simplifies render pass setup by providing a unified interface for different rendering destinations.

Variants§

§

Surface

Render to the window surface.

The surface view is obtained from the [Frame] during render pass creation.

§

SurfaceWithDepth

Render to the window surface with an attached depth buffer.

This variant allows rendering to the surface while using a depth texture for z-ordering, which is essential for UI systems and 3D overlays.

§Example

let depth_view = frame.window_depth_view().expect("Window has depth");
let mut pass = frame.render_pass()
    .target(RenderTarget::surface_with_depth_clear(&depth_view, 0.0))
    .clear_color(Color::BLACK)
    .build();
// ... rendering ...

Fields

§depth_view: &'a TextureView

The depth texture view to attach.

§clear_value: Option<f32>

How to handle the depth buffer: None = load, Some(v) = clear to v.

§

Framebuffer(&'a Framebuffer)

Render to an offscreen framebuffer.

The framebuffer manages its own color, depth, and MSAA textures.

Implementations§

Source§

impl<'a> RenderTarget<'a>

Source

pub fn surface() -> Self

Create a surface target (no depth).

Source

pub fn surface_with_depth(depth: &'a TextureView) -> Self

Create a surface target with a depth buffer that loads existing values.

Source

pub fn surface_with_depth_clear(depth: &'a TextureView, clear: f32) -> Self

Create a surface target with a depth buffer that clears to the specified value.

For reverse-Z depth (recommended), use 0.0 as the clear value. For standard depth, use 1.0 as the clear value.

Source

pub fn framebuffer(fb: &'a Framebuffer) -> Self

Create a framebuffer target.

Source

pub fn is_surface(&self) -> bool

Check if this target is a surface (with or without depth).

Source

pub fn is_framebuffer(&self) -> bool

Check if this target is a framebuffer.

Source

pub fn framebuffer_ref(&self) -> Option<&'a Framebuffer>

Get the framebuffer if this is a framebuffer target.

Source

pub fn format(&self) -> Option<TextureFormat>

Get the texture format for this target.

For framebuffers, returns the framebuffer’s format. For surfaces, returns None (format must be obtained from surface config).

Source

pub fn sample_count(&self) -> u32

Get the sample count for this target.

For framebuffers, returns the framebuffer’s sample count. For surfaces, returns 1 (surfaces don’t support MSAA directly).

Source

pub fn has_msaa(&self) -> bool

Check if this target has MSAA enabled.

Source

pub fn has_depth(&self) -> bool

Check if this target has a depth buffer.

Source

pub fn depth_view(&self) -> Option<&'a TextureView>

Get the depth view if available.

Source

pub fn depth_clear_value(&self) -> Option<f32>

Get the depth clear value if this target clears depth.

Trait Implementations§

Source§

impl<'a> Clone for RenderTarget<'a>

Source§

fn clone(&self) -> RenderTarget<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for RenderTarget<'a>

Source§

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

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

impl<'a> Default for RenderTarget<'a>

Source§

fn default() -> RenderTarget<'a>

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

impl<'a> From<&'a Framebuffer> for RenderTarget<'a>

Source§

fn from(fb: &'a Framebuffer) -> Self

Converts to this type from the input type.
Source§

impl<'a> Copy for RenderTarget<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for RenderTarget<'a>

§

impl<'a> !RefUnwindSafe for RenderTarget<'a>

§

impl<'a> Send for RenderTarget<'a>

§

impl<'a> Sync for RenderTarget<'a>

§

impl<'a> Unpin for RenderTarget<'a>

§

impl<'a> UnsafeUnpin for RenderTarget<'a>

§

impl<'a> !UnwindSafe for RenderTarget<'a>

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

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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
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 = 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> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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

Source§

impl<T> WasmNotSendSync for T

Source§

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