Skip to main content

Viewport

Struct Viewport 

Source
pub struct Viewport<'a> { /* private fields */ }
Expand description

Passive view description for rendering.

Declares camera, target, viewport, scissor, layer mask, and clear values. setup_image_2d/setup_image_aspect_fit manufacture and retain an orthographic camera internally; an externally borrowed camera supplied later through Self::set_camera takes precedence again.

Donor: oa::Viewport.

Implementations§

Source§

impl<'a> Viewport<'a>

Source

pub fn with_mode(mode: ViewportMode) -> Self

Create a viewport for mode.

Source

pub fn set_mode(&mut self, mode: ViewportMode)

Set the content mode.

Source

pub const fn mode(&self) -> ViewportMode

Return the content mode.

Source

pub fn set_camera(&mut self, camera: Option<&'a Camera>)

Borrow an external camera, or None to clear one.

Source

pub fn camera(&self) -> Option<&Camera>

Return the active camera — the borrowed external camera when present, otherwise the internally manufactured one.

Source

pub fn set_target(&mut self, target: Option<&'a Texture>)

Borrow the render target, or None to clear it.

Source

pub const fn target(&self) -> Option<&'a Texture>

Return the borrowed render target.

Source

pub fn set_viewport(&mut self, viewport: ViewportDesc) -> Result<()>

Set the viewport rectangle and depth range.

§Errors

Returns an error for non-positive dimensions or a depth range outside [0, 1].

Source

pub const fn viewport(&self) -> ViewportDesc

Return the configured viewport rectangle.

Source

pub fn set_scissor(&mut self, scissor: ScissorDesc) -> Result<()>

Enable scissor clipping with scissor.

§Errors

Returns an error for non-positive dimensions.

Source

pub fn disable_scissor(&mut self)

Disable scissor clipping.

Source

pub const fn is_scissor_enabled(&self) -> bool

Return whether scissor clipping is enabled.

Source

pub const fn scissor(&self) -> ScissorDesc

Return the configured scissor rectangle.

Source

pub fn set_layer_mask(&mut self, mask: RenderLayer)

Set the layer visibility mask.

Source

pub const fn layer_mask(&self) -> RenderLayer

Return the layer visibility mask.

Source

pub const fn is_layer_visible(&self, layer: RenderLayer) -> bool

Return whether layer passes the visibility mask.

Source

pub fn set_clear_color(&mut self, color: [f32; 4]) -> Result<()>

Set the RGBA clear color.

§Errors

Returns an error for non-finite components.

Source

pub const fn clear_color(&self) -> [f32; 4]

Return the RGBA clear color.

Source

pub fn set_clear_depth(&mut self, depth: f32) -> Result<()>

Set the clear depth.

§Errors

Returns an error for a non-finite value or one outside [0, 1].

Source

pub const fn clear_depth(&self) -> f32

Return the clear depth.

Source

pub fn is_valid(&self) -> bool

Return whether the viewport is complete and consistent: an active camera, a borrowed target, a valid viewport rectangle, a valid enabled scissor, and finite clear values.

Source

pub fn setup_image_2d( &mut self, image_width: f32, image_height: f32, target: &'a Texture, viewport: ViewportDesc, ) -> Result<()>

Set up orthographic 2D image viewing over target.

Manufactures an internal orthographic camera matching the image extent; a later Self::set_camera overrides it again.

§Errors

Returns an error for non-positive image dimensions or an invalid viewport.

Source

pub fn setup_image_aspect_fit( &mut self, image_width: f32, image_height: f32, window_width: f32, window_height: f32, target: &'a Texture, ) -> Result<()>

Set up aspect-fitted image display: a centered letterboxed viewport preserving the image aspect inside the window.

§Errors

Returns an error for non-positive dimensions, a window exceeding signed pixel coordinates, or a result that cannot be represented as a positive pixel rectangle.

Trait Implementations§

Source§

impl<'a> Default for Viewport<'a>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

impl<'a> !Send for Viewport<'a>

§

impl<'a> !Sync for Viewport<'a>

§

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

§

impl<'a> Forget for Viewport<'a>

§

impl<'a> Freeze for Viewport<'a>
where &'a Camera: Freeze, &'a Texture: Freeze,

§

impl<'a> Move for Viewport<'a>

§

impl<'a> Unpin for Viewport<'a>
where &'a Camera: Unpin, &'a Texture: Unpin,

§

impl<'a> UnsafeUnpin for Viewport<'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<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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

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<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.