Skip to main content

SsaaCanvas

Struct SsaaCanvas 

Source
pub struct SsaaCanvas { /* private fields */ }
Expand description

A supersampling anti-aliasing (SSAA) canvas wrapper that renders at a higher resolution on an offscreen canvas and downscales to the display canvas for smoother polygon edges in software-rendered 3D scenes.

The offscreen context is scaled by scale_factor so that all drawing code can use logical pixel coordinates without modification. After rendering, call present() to draw the high-resolution buffer onto the visible canvas with high-quality image smoothing.

Implementations§

Source§

impl SsaaCanvas

Implements construction, presentation, and anti-aliasing methods for SsaaCanvas.

Source

pub fn from_selector<S>( canvas_selector: S, width: f64, height: f64, ) -> Option<SsaaCanvas>
where S: AsRef<str>,

Creates an SsaaCanvas from a CSS selector using the default scale factor.

§Arguments
  • S: AsRef<str> - The CSS selector for the display canvas element.
  • f64 - The logical display width in CSS pixels.
  • f64 - The logical display height in CSS pixels.
§Returns
  • Option<SsaaCanvas> - The SSAA canvas, or None if the canvas was not found.
Source

pub fn from_selector_with_scale<S>( canvas_selector: S, width: f64, height: f64, scale_factor: f64, ) -> Option<SsaaCanvas>
where S: AsRef<str>,

Creates an SsaaCanvas from a CSS selector with a custom SSAA scale factor.

The offscreen canvas is created at width * scale_factor by height * scale_factor pixels, and its context is pre-scaled so that drawing code uses logical coordinates.

§Arguments
  • S: AsRef<str> - The CSS selector for the display canvas element.
  • f64 - The logical display width in CSS pixels.
  • f64 - The logical display height in CSS pixels.
  • f64 - The supersampling scale factor (e.g., 2.0 for 4x SSAA).
§Returns
  • Option<SsaaCanvas> - The SSAA canvas, or None if the canvas was not found.
Source

pub fn present(&self)

Presents the offscreen buffer onto the display canvas with high-quality downscaling.

Clears the display canvas, then draws the offscreen canvas scaled down to the logical display size. The active quality preset is applied once at construction via enable_smoothing — there is no need to re-apply it every frame, since the preset never changes mid-render.

#32: the previous version called apply_quality on every present(), costing set_image_smoothing_enabled + 2×Reflect

  • 4×from_str ≈ 7 JS crossings per frame for a value that was invariant across the entire session.
Source

pub fn clear(&self)

Clears the offscreen buffer to transparent.

Source

pub fn clear_color<C>(&self, color: C)
where C: AsRef<str>,

Clears the offscreen buffer and fills it with the given CSS color.

§Arguments
  • C: AsRef<str> - The CSS color string.
Source

pub fn enable_smoothing(&self)

Enables high-quality anti-aliasing on both the display and offscreen contexts.

Applies the active quality preset to both contexts via the shared apply_quality helper.

Source§

impl SsaaCanvas

Source

pub fn get_display_canvas(&self) -> &HtmlCanvasElement

Source

pub fn get_mut_display_canvas(&mut self) -> &mut HtmlCanvasElement

Source

pub fn set_display_canvas(&mut self, val: HtmlCanvasElement) -> &mut Self

Source

pub fn get_display_context(&self) -> &CanvasRenderingContext2d

Source

pub fn get_mut_display_context(&mut self) -> &mut CanvasRenderingContext2d

Source

pub fn set_display_context( &mut self, val: CanvasRenderingContext2d, ) -> &mut Self

Source

pub fn get_offscreen_canvas(&self) -> &HtmlCanvasElement

Source

pub fn get_mut_offscreen_canvas(&mut self) -> &mut HtmlCanvasElement

Source

pub fn set_offscreen_canvas(&mut self, val: HtmlCanvasElement) -> &mut Self

Source

pub fn get_offscreen_context(&self) -> &CanvasRenderingContext2d

Source

pub fn get_mut_offscreen_context(&mut self) -> &mut CanvasRenderingContext2d

Source

pub fn set_offscreen_context( &mut self, val: CanvasRenderingContext2d, ) -> &mut Self

Source

pub fn get_scale_factor(&self) -> f64

Source

pub fn get_mut_scale_factor(&mut self) -> &mut f64

Source

pub fn set_scale_factor(&mut self, val: f64) -> &mut Self

Source

pub fn get_quality(&self) -> RenderQuality

Source

pub fn get_mut_quality(&mut self) -> &mut RenderQuality

Source

pub fn set_quality(&mut self, val: RenderQuality) -> &mut Self

Source

pub fn get_width(&self) -> f64

Source

pub fn get_mut_width(&mut self) -> &mut f64

Source

pub fn set_width(&mut self, val: f64) -> &mut Self

Source

pub fn get_height(&self) -> f64

Source

pub fn get_mut_height(&mut self) -> &mut f64

Source

pub fn set_height(&mut self, val: f64) -> &mut Self

Source§

impl SsaaCanvas

Source

pub fn new( display_canvas: HtmlCanvasElement, display_context: CanvasRenderingContext2d, offscreen_canvas: HtmlCanvasElement, offscreen_context: CanvasRenderingContext2d, scale_factor: f64, width: f64, height: f64, ) -> Self

Trait Implementations§

Source§

impl Clone for SsaaCanvas

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

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 = !

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

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more