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.
impl SsaaCanvas
Implements construction, presentation, and anti-aliasing methods for SsaaCanvas.
Sourcepub fn from_selector<S>(
canvas_selector: S,
width: f64,
height: f64,
) -> Option<SsaaCanvas>
pub fn from_selector<S>( canvas_selector: S, width: f64, height: f64, ) -> Option<SsaaCanvas>
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, orNoneif the canvas was not found.
Sourcepub fn from_selector_with_scale<S>(
canvas_selector: S,
width: f64,
height: f64,
scale_factor: f64,
) -> Option<SsaaCanvas>
pub fn from_selector_with_scale<S>( canvas_selector: S, width: f64, height: f64, scale_factor: f64, ) -> Option<SsaaCanvas>
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, orNoneif the canvas was not found.
Sourcepub fn present(&self)
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.
Sourcepub fn clear_color<C>(&self, color: C)
pub fn clear_color<C>(&self, color: C)
Clears the offscreen buffer and fills it with the given CSS color.
§Arguments
C: AsRef<str>- The CSS color string.
Sourcepub fn enable_smoothing(&self)
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
impl SsaaCanvas
pub fn get_display_canvas(&self) -> &HtmlCanvasElement
pub fn get_mut_display_canvas(&mut self) -> &mut HtmlCanvasElement
pub fn set_display_canvas(&mut self, val: HtmlCanvasElement) -> &mut Self
pub fn get_display_context(&self) -> &CanvasRenderingContext2d
pub fn get_mut_display_context(&mut self) -> &mut CanvasRenderingContext2d
pub fn set_display_context( &mut self, val: CanvasRenderingContext2d, ) -> &mut Self
pub fn get_offscreen_canvas(&self) -> &HtmlCanvasElement
pub fn get_mut_offscreen_canvas(&mut self) -> &mut HtmlCanvasElement
pub fn set_offscreen_canvas(&mut self, val: HtmlCanvasElement) -> &mut Self
pub fn get_offscreen_context(&self) -> &CanvasRenderingContext2d
pub fn get_mut_offscreen_context(&mut self) -> &mut CanvasRenderingContext2d
pub fn set_offscreen_context( &mut self, val: CanvasRenderingContext2d, ) -> &mut Self
pub fn get_scale_factor(&self) -> f64
pub fn get_mut_scale_factor(&mut self) -> &mut f64
pub fn set_scale_factor(&mut self, val: f64) -> &mut Self
pub fn get_quality(&self) -> RenderQuality
pub fn get_mut_quality(&mut self) -> &mut RenderQuality
pub fn set_quality(&mut self, val: RenderQuality) -> &mut Self
pub fn get_width(&self) -> f64
pub fn get_mut_width(&mut self) -> &mut f64
pub fn set_width(&mut self, val: f64) -> &mut Self
pub fn get_height(&self) -> f64
pub fn get_mut_height(&mut self) -> &mut f64
pub fn set_height(&mut self, val: f64) -> &mut Self
Source§impl SsaaCanvas
impl SsaaCanvas
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
impl Clone for SsaaCanvas
Source§fn clone(&self) -> SsaaCanvas
fn clone(&self) -> SsaaCanvas
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more