Context

Struct Context 

Source
pub struct Context {
    pub color_clear: Option<Color4>,
    pub depth_clear: Option<f32>,
    pub face_cull: Option<FaceCull>,
    pub depth_sort: Option<DepthSort>,
    pub depth_test: Option<Ordering>,
    pub color_write: bool,
    pub depth_write: bool,
    pub stats: RefCell<Stats>,
}
Expand description

Context and parameters used by the renderer.

Fields§

§color_clear: Option<Color4>

The color with which to fill the color buffer to clear it, if any.

If rendered geometry always fills the entire frame, color_clear can be set to None to avoid redundant work.

§depth_clear: Option<f32>

The value with which to fill the depth buffer to clear it, if any.

§face_cull: Option<FaceCull>

Whether to cull (discard) faces pointing either away from or towards the camera.

If all geometry drawn is “solid” meshes without holes, backfaces can usually be culled because they are always occluded by front faces and drawing them would be redundant.

§depth_sort: Option<DepthSort>

Whether to sort visible faces by their depth.

If z-buffering or other hidden surface determination method is not used, back-to-front depth sorting can be used to ensure correct rendering unless there is intersecting or non-orderable geometry (this is the so-called “painter’s algorithm”).

Overlapping transparent surfaces have to be drawn back-to-front to get correct results. Rendering nontransparent geometry in front-to-back order can improve performance by reducing overdraw.

§depth_test: Option<Ordering>

Whether to do depth testing and which predicate to use.

If set to Some(Ordering::Less), a fragment passes the depth test iff new_z < old_z (the default). If set to None, depth test is not performed. This setting has no effect if the render target does not support z-buffering.

§color_write: bool

Whether to write color values.

If false, other fragment processing is done but there is no color output. This setting has no effect if the render target does not support color writes.

§depth_write: bool

Whether to write depth values.

If false, other fragment processing is done but there is no depth output. This setting has no effect if the render target does not support depth writes.

§stats: RefCell<Stats>

Collecting rendering statistics.

Implementations§

Source§

impl Context

Source

pub fn depth_test(&self, new: f32, curr: f32) -> bool

Compares the reciprocal depth value new to curr and returns whether new passes the depth test specified by self.depth_test. If self.depth_test is None, always returns true.

Source

pub fn face_cull(&self, is_backface: bool) -> bool

Returns whether a primitive should be culled based on the current face culling setting.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

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 Debug for Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Self

Creates a rendering context with default settings.

The default values are:

  • Color clear: Opaque black
  • Depth clear: Positive infinity
  • Face culling: Backfaces
  • Depth sorting: Disabled
  • Color writes: Enabled
  • Depth testing: Pass if closer
  • Depth writes: Enabled

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<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> 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> 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.