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(
canvas_selector: &str,
width: f64,
height: f64,
) -> Option<SsaaCanvas>
pub fn from_selector( canvas_selector: &str, width: f64, height: f64, ) -> Option<SsaaCanvas>
Creates an SsaaCanvas from a CSS selector using the default scale factor.
§Arguments
&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(
canvas_selector: &str,
width: f64,
height: f64,
scale_factor: f64,
) -> Option<SsaaCanvas>
pub fn from_selector_with_scale( canvas_selector: &str, 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
&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.
Enables imageSmoothingEnabled and imageSmoothingQuality = "high" on the
display context, clears the display canvas, then draws the offscreen canvas
scaled down to the logical display size. This is the core SSAA step that
produces smooth polygon edges.
Sourcepub fn clear_with_color(&self, color: &str)
pub fn clear_with_color(&self, color: &str)
Clears the offscreen buffer and fills it with the given CSS color.
§Arguments
&str- The CSS color string.
Sourcepub fn enable_anti_aliasing(&self)
pub fn enable_anti_aliasing(&self)
Enables high-quality anti-aliasing on both the display and offscreen contexts.
Sets imageSmoothingEnabled = true and imageSmoothingQuality = "high"
on both contexts to ensure optimal image scaling quality.
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_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