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
impl SsaaFramebuffer
Sourcepub fn new(
device: &Device,
w: u32,
h: u32,
format: TextureFormat,
with_depth: bool,
) -> Self
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.
Sourcepub fn ensure_size(&mut self, device: &Device, w: u32, h: u32)
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.
pub fn size(&self) -> (u32, u32)
Sourcepub fn render_view(&self) -> &TextureView
pub fn render_view(&self) -> &TextureView
View to use as the colour attachment of the widget’s render pass.
Sourcepub fn resolve_view(&self) -> &TextureView
pub fn resolve_view(&self) -> &TextureView
Same view, exposed under the historic name used by post-render sampling sites (e.g. the screenshot path).
Sourcepub fn resolve_texture(&self) -> &Texture
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_*).
Sourcepub fn depth_view(&self) -> Option<&TextureView>
pub fn depth_view(&self) -> Option<&TextureView>
Depth attachment view, when one was requested at construction.
Sourcepub 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,
)
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.
Sourcepub 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,
)
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.
Sourcepub 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,
)
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.
Sourcepub 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,
)
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:
| factor | pipeline | why |
|---|---|---|
| 0, 1 | Self::blit_to | identity — texel centres align |
| 2 | Self::blit_to | one bilinear tap IS the 2×2 box |
| 3 | Self::blit_downsample_3x_to | 9 taps; bilinear misses 5 of 9 |
| ≥4 | Self::blit_downsample_4x_to | 4 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§
impl !RefUnwindSafe for SsaaFramebuffer
impl !UnwindSafe for SsaaFramebuffer
impl Freeze for SsaaFramebuffer
impl Send for SsaaFramebuffer
impl Sync for SsaaFramebuffer
impl Unpin for SsaaFramebuffer
impl UnsafeUnpin for SsaaFramebuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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