Skip to main content

SsaaFramebuffer

Struct SsaaFramebuffer 

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

Off-screen single-sample framebuffer for widgets that drive their own GPU pipeline and composite the result onto the shared 2-D render target.

SSAA happens via size: the caller allocates this at scale × {w, h} and bilinear-downsamples through Self::blit_to. This type holds no concept of “samples” — it’s just an offscreen colour (+ optional depth) with a composite helper.

Allocated lazily; call Self::ensure_size each frame to keep the attachments sized to the current widget rect × scale.

Implementations§

Source§

impl SsaaFramebuffer

Source

pub fn new( device: &Device, w: u32, h: u32, format: TextureFormat, with_depth: bool, ) -> Self

Build a fresh framebuffer at (w, h) with surface format. with_depth = true allocates a matching depth buffer; widgets that only need colour can pass false.

(w, h) is the physical size of the texture, already multiplied by the desired linear SSAA scale. Use ssaa_linear_scale to map a samples-style UI value to that multiplier.

Source

pub fn ensure_size(&mut self, device: &Device, w: u32, h: u32)

Reallocate the attachments if (w, h) has changed since the last call. Cheap when the size is stable.

Source

pub fn size(&self) -> (u32, u32)

Source

pub fn render_view(&self) -> &TextureView

View to use as the colour attachment of the widget’s render pass.

Source

pub fn resolve_view(&self) -> &TextureView

Same view, exposed under the historic name used by post-render sampling sites (e.g. the screenshot path).

Source

pub fn resolve_texture(&self) -> &Texture

Colour texture handle. Exposed so a platform shell (currently demo-wasm) can use this SsaaFramebuffer as the intermediate “scene” target — pass resolve_texture().clone() to crate::WgpuGfxCtx::set_surface_texture so the GPU-direct screenshot path copies from this scene texture instead of from the real swap-chain surface (which on WebGL2 cannot advertise COPY_SRC and so can’t be the source of a copy_texture_to_*).

Source

pub fn depth_view(&self) -> Option<&TextureView>

Depth attachment view, when one was requested at construction.

Source

pub fn blit_to( &self, device: &Device, encoder: &mut CommandEncoder, target_view: &TextureView, target_size: (u32, u32), dst_rect: Rect, parent_clip: Option<[i32; 4]>, pipelines: &WgpuPipelines, )

Composite the framebuffer’s colour onto target_view’s dst_rect (Y-up screen-space pixels of the target). Uses the shared 2-D textured-quad pipeline with BLEND_STANDARD so transparent pixels (where the widget didn’t render) preserve the 2-D content underneath.

At ≥4× linear minification (e.g. SSAA 16×) a single bilinear tap only reads 4 of the 16 source texels per output pixel; in that case use Self::blit_downsample_4x_to instead. This base blit_to always runs the single-tap pipeline — fine for 1× / 2× / 3× minification (perfect 2×2 box at 2×).

parent_clip is intersected with dst_rect to set the pass scissor — pass the framework scissor that was active when the widget called gl_paint / pushed its draw command.

Source

pub fn blit_downsample_3x_to( &self, device: &Device, encoder: &mut CommandEncoder, target_view: &TextureView, target_size: (u32, u32), dst_rect: Rect, parent_clip: Option<[i32; 4]>, pipelines: &WgpuPipelines, )

3×3-box downsample variant of Self::blit_to. Use when the framebuffer is exactly 3× the linear size of dst_rect (SSAA 9×): runs tex_downsample_3x_pipeline so all 9 source texels under each output pixel contribute equally. A single bilinear tap at 3× minification reads only the corner 2×2 block (4 of 9 texels) and entirely skips one row + one column — visually close to no AA at all — so 3× SSAA needs this dedicated pipeline to be worth its pixel cost.

Source

pub fn blit_downsample_4x_to( &self, device: &Device, encoder: &mut CommandEncoder, target_view: &TextureView, target_size: (u32, u32), dst_rect: Rect, parent_clip: Option<[i32; 4]>, pipelines: &WgpuPipelines, )

4×4-box downsample variant of Self::blit_to. Use when the framebuffer is exactly 4× the linear size of dst_rect (SSAA 16×): runs tex_downsample_4x_pipeline so all 16 source texels under each output pixel contribute equally, instead of the 4-of-16 you’d get from a single bilinear tap.

Source

pub fn blit_downsample_to( &self, device: &Device, encoder: &mut CommandEncoder, target_view: &TextureView, target_size: (u32, u32), dst_rect: Rect, parent_clip: Option<[i32; 4]>, pipelines: &WgpuPipelines, factor: u32, )

Downsample by a factor chosen at runtime, dispatching to the pipeline that is correct for it.

Consumers that pick their supersample factor per device — rather than baking one in at compile time — need this. A renderer running on both a desktop at device-pixel-ratio 1 and a phone at ratio 3 cannot use a fixed factor: the offscreen targets are sized factor × device pixels, so a constant 3× multiplies an already-tripled resolution and blows past both the memory budget and max_texture_dimension_2d. Such a consumer computes its factor from the device scale and limits, then hands it here.

Mapping, per the analysis in the individual methods:

factorpipelinewhy
0, 1Self::blit_toidentity — texel centres align
2Self::blit_toone bilinear tap IS the 2×2 box
3Self::blit_downsample_3x_to9 taps; bilinear misses 5 of 9
≥4Self::blit_downsample_4x_to4 bilinear taps = 16-texel box

Factors above 4 clamp to the 4× pipeline rather than erroring — it degrades gracefully (a partial box) instead of failing a frame, and no caller supersamples that far today.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,