pub struct WgpuRenderer { /* private fields */ }Implementations§
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn new<W>(
gpu_context: WgpuContextSlot,
window: &W,
config: WgpuSurfaceConfig,
compositor_gpu: Option<CompositorGpuHint>,
gpu_preference: GpuPreference,
) -> Result<Self>
pub fn new<W>( gpu_context: WgpuContextSlot, window: &W, config: WgpuSurfaceConfig, compositor_gpu: Option<CompositorGpuHint>, gpu_preference: GpuPreference, ) -> Result<Self>
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
impl WgpuRenderer
Sourcepub fn update_drawable_size(&mut self, size: Size<DevicePixels>)
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.
pub fn set_subpixel_layout(&mut self, is_bgr: bool)
pub fn update_transparency(&mut self, transparent: bool)
pub fn viewport_size(&self) -> Size<DevicePixels>
pub fn sprite_atlas(&self) -> &Arc<WgpuAtlas> ⓘ
pub fn supports_dual_source_blending(&self) -> bool
Sourcepub fn device(&self) -> &Device
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.
Sourcepub fn gpu_context(&self) -> Option<WgpuContextSlot>
pub fn gpu_context(&self) -> Option<WgpuContextSlot>
The shared context slot this renderer draws through, if it has one.
pub fn gpu_specs(&self) -> Option<GpuSpecs>
pub fn max_texture_size(&self) -> u32
pub fn draw(&mut self, scene: &Scene) -> bool
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn unconfigure_surface(&mut self)
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.
Sourcepub fn replace_surface<W: HasWindowHandle>(
&mut self,
window: &W,
config: WgpuSurfaceConfig,
instance: &Instance,
) -> Result<()>
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.
pub fn destroy(&mut self)
Sourcepub fn device_lost(&self) -> bool
pub fn device_lost(&self) -> bool
Returns true if the GPU device was lost and recovery is needed.
Sourcepub fn needs_redraw(&mut self) -> bool
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.
Sourcepub fn recover<W>(&mut self, window: &W) -> Result<()>
pub fn recover<W>(&mut self, window: &W) -> Result<()>
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
impl GpuRenderer for WgpuRenderer
Source§type Device = (Arc<Device>, Arc<Queue>)
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§impl PlatformRenderer for WgpuRenderer
impl PlatformRenderer for WgpuRenderer
Source§fn update_drawable_size(&mut self, size: Size<DevicePixels>)
fn update_drawable_size(&mut self, size: Size<DevicePixels>)
Source§fn max_texture_size(&self) -> u32
fn max_texture_size(&self) -> u32
Source§fn set_subpixel_layout(&mut self, is_bgr: bool)
fn set_subpixel_layout(&mut self, is_bgr: bool)
Source§fn update_transparency(&mut self, transparent: bool)
fn update_transparency(&mut self, transparent: bool)
Source§fn device_lost(&self) -> bool
fn device_lost(&self) -> bool
Source§fn needs_redraw(&mut self) -> bool
fn needs_redraw(&mut self) -> bool
Source§impl SceneRenderer for WgpuRenderer
impl SceneRenderer for WgpuRenderer
Source§fn draw(&mut self, scene: &Scene) -> bool
fn draw(&mut self, scene: &Scene) -> bool
scene, returning whether it was presented. Read moreSource§fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> ⓘ
fn sprite_atlas(&self) -> Arc<dyn PlatformAtlas> ⓘ
Source§fn set_viewport_size(&mut self, _size: Size<DevicePixels>)
fn set_viewport_size(&mut self, _size: Size<DevicePixels>)
Source§fn render_scene(
&mut self,
_scene: &Scene,
_size: Size<DevicePixels>,
) -> Result<(), Error>
fn render_scene( &mut self, _scene: &Scene, _size: Size<DevicePixels>, ) -> Result<(), Error>
Source§fn read_pixels(&mut self) -> Result<PixelBuffer, Error>
fn read_pixels(&mut self) -> Result<PixelBuffer, Error>
render_scene back. Read moreSource§fn offscreen_surface_handle(&self) -> Option<Arc<dyn Any + Send + Sync>>
fn offscreen_surface_handle(&self) -> Option<Arc<dyn Any + Send + Sync>>
render_scene, as a handle that may
cross a thread boundary. Read moreSource§fn render_scene_to_image(
&mut self,
scene: &Scene,
size: Size<DevicePixels>,
) -> Result<PixelBuffer, Error>
fn render_scene_to_image( &mut self, scene: &Scene, size: Size<DevicePixels>, ) -> Result<PixelBuffer, Error>
scene offscreen and reads the result back.Auto Trait Implementations§
impl !Freeze for WgpuRenderer
impl !RefUnwindSafe for WgpuRenderer
impl !Send for WgpuRenderer
impl !Sync for WgpuRenderer
impl !UnwindSafe for WgpuRenderer
impl Unpin for WgpuRenderer
impl UnsafeUnpin for WgpuRenderer
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
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