Skip to main content

Backend

Trait Backend 

Source
pub trait Backend:
    Sized
    + Sync
    + Send
    + 'static {
    type Frame: FrameOperations;

    // Required methods
    fn init(
        handle: impl GPUSurfaceHandle,
        width: u32,
        height: u32,
        sender: InitSender<Self>,
    );
    fn acquire(&mut self) -> Result<Self::Frame, AcquireError>;
    fn present(&mut self, frame: Self::Frame);

    // Provided method
    fn resize(&mut self, width: u32, height: u32) { ... }
}
Expand description

A unified graphics backend for both native and web targets.

Implement this trait to integrate a concrete graphics API (e.g. wgpu). Initialisation is always done via the InitSender channel so that implementations can choose to do it synchronously or on a background thread.

Required Associated Types§

Source

type Frame: FrameOperations

The per-frame type that exposes rendering operations.

Required Methods§

Source

fn init( handle: impl GPUSurfaceHandle, width: u32, height: u32, sender: InitSender<Self>, )

Begin initialisation. Send the finished backend through sender when ready.

Source

fn acquire(&mut self) -> Result<Self::Frame, AcquireError>

Acquire the next frame for rendering.

Returns AcquireError::Transient for recoverable failures (e.g. swapchain out of date) and AcquireError::Fatal for unrecoverable ones.

Source

fn present(&mut self, frame: Self::Frame)

Present the completed frame to the display.

Provided Methods§

Source

fn resize(&mut self, width: u32, height: u32)

Called when the window is resized. Override to recreate the swapchain.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§