pub struct ViewportRect {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub min_depth: f32,
pub max_depth: f32,
}Expand description
The region of the render target a scene draws into, in pixels.
Fragments outside it are discarded and the clip space a pipeline writes is stretched across it, which is what letterboxes a scene whose own aspect differs from its target’s: the projection keeps the scene’s aspect, and the viewport places the result inside the target without distortion.
Unlike ScissorRect, which clips in whole pixels, a viewport is
fractional — a centred letterbox rarely lands on a pixel boundary — so its
fields are floats. It is pass state with no reset call, so see
Scene::viewport.
Fields§
§x: f32Left edge, in pixels.
y: f32Top edge, in pixels.
width: f32Width in pixels.
height: f32Height in pixels.
min_depth: f32The depth the near plane of the viewport’s clip space maps to.
max_depth: f32The depth the far plane of the viewport’s clip space maps to.
Implementations§
Source§impl ViewportRect
impl ViewportRect
Sourcepub fn new(width: f32, height: f32) -> Self
pub fn new(width: f32, height: f32) -> Self
A rectangle covering width x height pixels from the origin, over the
whole 0.0..=1.0 depth range.
Sourcepub fn with_depth(self, min_depth: f32, max_depth: f32) -> Self
pub fn with_depth(self, min_depth: f32, max_depth: f32) -> Self
Same rectangle, mapped over min_depth..=max_depth instead of the whole
depth range.
Sourcepub fn fit_aspect(aspect: f32, target_width: u32, target_height: u32) -> Self
pub fn fit_aspect(aspect: f32, target_width: u32, target_height: u32) -> Self
The largest rectangle of aspect that fits inside a
target_width x target_height target, centred.
This is the letterbox: a target wider than aspect gets a rectangle
spanning the full height with bars at the sides, a narrower one spans
the full width with bars above and below, and the rectangle’s own aspect
is aspect either way — so content drawn through it is scaled
uniformly, showing the same picture on any target shape rather than
being stretched to the target’s.
A degenerate target, or an aspect that is not a positive finite
number, has no rectangle to fit, so the whole target comes back rather
than a zero-sized region.
Trait Implementations§
Source§impl Clone for ViewportRect
impl Clone for ViewportRect
impl Copy for ViewportRect
Source§impl Debug for ViewportRect
impl Debug for ViewportRect
Source§impl PartialEq for ViewportRect
impl PartialEq for ViewportRect
impl StructuralPartialEq for ViewportRect
Auto Trait Implementations§
impl Forget for ViewportRect
impl Freeze for ViewportRect
impl RefUnwindSafe for ViewportRect
impl Send for ViewportRect
impl Sync for ViewportRect
impl Unpin for ViewportRect
impl UnsafeUnpin for ViewportRect
impl UnwindSafe for ViewportRect
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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