Skip to main content

WgpuRenderer

Struct WgpuRenderer 

Source
pub struct WgpuRenderer { /* private fields */ }

Implementations§

Source§

impl WgpuRenderer

Source

pub fn new<W>( gpu_context: WgpuContextSlot, window: &W, config: WgpuSurfaceConfig, compositor_gpu: Option<CompositorGpuHint>, ) -> Result<Self>
where W: HasWindowHandle + HasDisplayHandle + Debug + Send + Sync + Clone + 'static,

Creates a new WgpuRenderer from raw window handles.

The gpu_context is a shared reference that coordinates GPU context across multiple windows. The first window to create a renderer will initialize the context; subsequent windows will share it.

§Safety

The caller must ensure that the window handle remains valid for the lifetime of the returned renderer.

Source§

impl WgpuRenderer

Source

pub fn update_drawable_size(&mut self, size: Size<DevicePixels>)

Records the new drawable size and reconfigures the surface when one is present. The size is kept even without GPU resources so that recovery restores it.

Source

pub fn set_subpixel_layout(&mut self, is_bgr: bool)

Source

pub fn update_transparency(&mut self, transparent: bool)

Source

pub fn viewport_size(&self) -> Size<DevicePixels>

Source

pub fn sprite_atlas(&self) -> &Arc<WgpuAtlas> ⓘ

Source

pub fn supports_dual_source_blending(&self) -> bool

Source

pub fn device(&self) -> &Device

Returns None once GPU resources have been released by destroy or a pending device recovery. A producer on this path renders its texture on this device – that is the whole of the same-device rule – so a renderer that can be built without a window is where an application that owns one reaches a device from. A window’s is reached through GpuRenderer::device, which is the same device by another route.

Source

pub fn queue(&self) -> &Queue

The queue this renderer submits on.

Source

pub fn gpu_context(&self) -> Option<WgpuContextSlot>

The shared context slot this renderer draws through, if it has one.

Source

pub fn gpu_specs(&self) -> Option<GpuSpecs>

Source

pub fn max_texture_size(&self) -> u32

Source

pub fn draw(&mut self, scene: &Scene) -> bool

Source§

impl WgpuRenderer

Source

pub fn unconfigure_surface(&mut self)

Mark the surface as unconfigured so rendering is skipped until a new surface is provided via replace_surface.

This does not drop the renderer — the device, queue, atlas, and pipelines stay alive. Use this when the native window is destroyed (e.g. Android TerminateWindow) but you intend to re-create the surface later without losing cached atlas textures.

Source

pub fn replace_surface<W: HasWindowHandle>( &mut self, window: &W, config: WgpuSurfaceConfig, instance: &Instance, ) -> Result<()>

Replace the wgpu surface with a new one (e.g. after Android destroys and recreates the native window). Keeps the device, queue, atlas, and all pipelines intact so cached AtlasTextureIds remain valid.

The instance must be the same wgpu::Instance that was used to create the adapter and device (i.e. from the WgpuContext). Using a different instance will cause a “Device does not exist” panic because the wgpu device is bound to its originating instance.

Source

pub fn destroy(&mut self)

Source

pub fn device_lost(&self) -> bool

Returns true if the GPU device was lost and recovery is needed.

Source

pub fn needs_redraw(&mut self) -> bool

Returns true if a redraw is needed because GPU state was cleared. Calling this method clears the flag.

Source

pub fn recover<W>(&mut self, window: &W) -> Result<()>
where W: HasWindowHandle + HasDisplayHandle + Debug + Send + Sync + Clone + 'static,

Recovers from a lost GPU device by recreating the renderer with a new context.

Call this after detecting device_lost() returns true.

This method coordinates recovery across multiple windows:

  • The first window to call this will recreate the shared context
  • Subsequent windows will adopt the already-recovered context

Trait Implementations§

Source§

impl GpuRenderer for WgpuRenderer

Source§

type Device = (Arc<Device>, Arc<Queue>)

The shared context slot, which is where a producer on this path reaches the device and the queue: it is the same Rc every window in the process draws through, so reading them out of it is the rendezvous it exists for. None for a renderer built offscreen, which holds no context because it has no window to coordinate with.

Source§

fn device(&self) -> Option<Self::Device>

The device, or None while there is none to lend: a renderer mid-recovery has taken its device apart and has not yet rebuilt it.
Source§

impl PlatformRenderer for WgpuRenderer

Source§

fn update_drawable_size(&mut self, size: Size<DevicePixels>)

The target’s size changed, in device pixels.
Source§

fn max_texture_size(&self) -> u32

The largest texture this renderer can allocate, in pixels.
Source§

fn gpu_specs(&self) -> Option<GpuSpecs>

What GPU this renderer is on, if it can tell.
Source§

fn set_subpixel_layout(&mut self, is_bgr: bool)

Whether glyphs are rasterized with subpixel antialiasing in BGR order.
Source§

fn update_transparency(&mut self, transparent: bool)

The window’s transparency changed.
Source§

fn destroy(&mut self)

Release the renderer’s resources, keeping it reconstructible.
Source§

fn device_lost(&self) -> bool

Whether the GPU device or its surface has been lost.
Source§

fn needs_redraw(&mut self) -> bool

Whether the renderer has work the frame loop should not wait on.
Source§

fn recover(&mut self, target: RendererTarget<'_>) -> Result<()>

Rebuild from the target the renderer was built against, after a lost device or surface.
Source§

impl SceneRenderer for WgpuRenderer

Source§

fn draw(&mut self, scene: &Scene) -> bool

Encodes and submits scene, returning whether it was presented. Read more
Source§

fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> ⓘ

Returns the sprite atlas used by this renderer.
Source§

fn set_viewport_size(&mut self, _size: Size<DevicePixels>)

Sets the size of the target that draw renders into. Read more
Source§

fn render_scene( &mut self, _scene: &Scene, _size: Size<DevicePixels>, ) -> Result<(), Error>

Renders scene into an offscreen target of size, without reading it back. Read more
Source§

fn read_pixels(&mut self) -> Result<PixelBuffer, Error>

Reads the offscreen target of the last render_scene back. Read more
Source§

fn render_scene_to_image( &mut self, scene: &Scene, size: Size<DevicePixels>, ) -> Result<PixelBuffer, Error>

Renders scene offscreen and reads the result back.

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<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> NativeSceneHooks for T
where T: SceneRenderer + ?Sized,

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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V