pub struct OffscreenRenderer { /* private fields */ }Expand description
Headless scene renderer: renders a Scene into CPU-readable RGBA8.
§Contracts
- Output is
width * height * 4bytes, row-major, premultiplied-alpha sRGB (Rgba8UnormSrgb): opaque content reads back exact sRGB bytes; translucent pixels carryrgb * a(divide byafor straight alpha). clear = Nonefills withscene.clear_color;Some(c)overrides it with linear-space[r, g, b, a]doubles.- All sizes clamp to a minimum of 1 (no zero-sized textures/buffers).
render_rgbablocks until the GPU work completes and the pixels are mapped; it is safe to call every frame (no per-frame allocations beyond the returnedVec).- Without a usable GPU adapter,
new/new_blockingfail with an error (never a panic, never silent fallback).
Implementations§
Source§impl OffscreenRenderer
impl OffscreenRenderer
Sourcepub async fn new(width: u32, height: u32, msaa: u32) -> Result<Self>
pub async fn new(width: u32, height: u32, msaa: u32) -> Result<Self>
Create a renderer for widthxheight frames with msaa samples
(clamped to what the adapter supports via pick_surface_msaa).
Dimensions clamp to ≥ 1. Errors when no GPU adapter is available.
Sourcepub fn new_blocking(width: u32, height: u32, msaa: u32) -> Result<Self>
pub fn new_blocking(width: u32, height: u32, msaa: u32) -> Result<Self>
Blocking new. Must not run on the wasm main thread
without block support (debug-asserted); use render_rgba_async there.
Sourcepub fn from_device(
device: Device,
queue: Queue,
width: u32,
height: u32,
msaa: u32,
) -> Result<Self>
pub fn from_device( device: Device, queue: Queue, width: u32, height: u32, msaa: u32, ) -> Result<Self>
Shared-device: reuse Device/Queue, no Adapter. Dimensions clamp to
≥ 1; msaa clamps to ≥ 1 (no adapter-based picking without one —
prefer from_device_with_adapter
when an adapter is handy).
Sourcepub fn from_device_with_adapter(
device: Device,
queue: Queue,
adapter: &Adapter,
width: u32,
height: u32,
msaa: u32,
) -> Result<Self>
pub fn from_device_with_adapter( device: Device, queue: Queue, adapter: &Adapter, width: u32, height: u32, msaa: u32, ) -> Result<Self>
Shared-device with adapter-based MSAA picking. Dimensions clamp to ≥ 1.
Sourcepub fn from_renderer(
renderer: WgpuSceneRenderer,
width: u32,
height: u32,
) -> Result<Self>
pub fn from_renderer( renderer: WgpuSceneRenderer, width: u32, height: u32, ) -> Result<Self>
Wrap an existing scene renderer with a fresh target + readback buffer. Dimensions clamp to ≥ 1.
Sourcepub fn render_rgba(
&mut self,
scene: &Scene,
clear: Option<[f64; 4]>,
) -> Result<Vec<u8>>
pub fn render_rgba( &mut self, scene: &Scene, clear: Option<[f64; 4]>, ) -> Result<Vec<u8>>
Render scene and read back width * height * 4 premultiplied sRGB
bytes (see the struct contracts). clear = None uses
scene.clear_color; an empty scene therefore reads back the clear
color exactly. Blocks until mapping completes.
pub fn renderer_mut(&mut self) -> &mut WgpuSceneRenderer
pub fn renderer(&self) -> &WgpuSceneRenderer
Sourcepub fn ensure_size(&mut self, width: u32, height: u32) -> Result<()>
pub fn ensure_size(&mut self, width: u32, height: u32) -> Result<()>
Resize the target + readback buffer. A no-op when the size already
matches (no reallocation). Dimensions clamp to ≥ 1. After this,
render_rgba returns width * height * 4 bytes at the new size.
pub async fn render_rgba_unified( &mut self, scene: &Scene, clear: Option<[f64; 4]>, ) -> Result<Vec<u8>>
Auto Trait Implementations§
impl !RefUnwindSafe for OffscreenRenderer
impl !UnwindSafe for OffscreenRenderer
impl Freeze for OffscreenRenderer
impl Send for OffscreenRenderer
impl Sync for OffscreenRenderer
impl Unpin for OffscreenRenderer
impl UnsafeUnpin for OffscreenRenderer
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.