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.