pub trait GfxBackend {
    type Configuration: Default;

    // Required methods
    fn new(
        window_backend: &mut impl WindowBackend,
        config: Self::Configuration
    ) -> Self;
    fn resize_framebuffer(&mut self, window_backend: &mut impl WindowBackend);
    fn prepare_frame(&mut self, window_backend: &mut impl WindowBackend);
    fn render_egui(
        &mut self,
        meshes: Vec<ClippedPrimitive>,
        textures_delta: TexturesDelta,
        logical_screen_size: [f32; 2]
    );
    fn present(&mut self, window_backend: &mut impl WindowBackend);

    // Provided methods
    fn suspend(&mut self, _window_backend: &mut impl WindowBackend) { ... }
    fn resume(&mut self, _window_backend: &mut impl WindowBackend) { ... }
}
Expand description

Trait for Gfx backends. these could be Gfx APIs like opengl or vulkan or wgpu etc.. or higher level renderers like three-d or rend3 or custom renderers etc..

Required Associated Types§

source

type Configuration: Default

similar to WindowBackendConfig. A custom config struct for the creation of GfxBackend

Required Methods§

source

fn new( window_backend: &mut impl WindowBackend, config: Self::Configuration ) -> Self

create a new GfxBackend using info from window backend and custom config struct WindowBackend trait provides the backend config, which can be used by the renderer to check for compatibility.

for example, a glow renderer might want an opengl context. but if the window was created without one, the glow renderer should panic.

source

fn resize_framebuffer(&mut self, window_backend: &mut impl WindowBackend)

called if framebuffer has been resized. use this to reconfigure your swapchain/surface/viewport..

source

fn prepare_frame(&mut self, window_backend: &mut impl WindowBackend)

prepare the surface / swapchain etc.. by acquiring an image for the current frame. use WindowBackend::get_live_physical_size_framebuffer fn to resize your swapchain if it is out of date.

source

fn render_egui( &mut self, meshes: Vec<ClippedPrimitive>, textures_delta: TexturesDelta, logical_screen_size: [f32; 2] )

This is where the renderers will start creating renderpasses, issue draw calls etc.. using the data previously prepared.

source

fn present(&mut self, window_backend: &mut impl WindowBackend)

This is called at the end of the frame. after everything is drawn, you can now present on opengl, renderer might call WindowBackend::swap_buffers. on wgpu / vulkan, renderer might submit commands to queues, present swapchain image etc..

Provided Methods§

source

fn suspend(&mut self, _window_backend: &mut impl WindowBackend)

Android only. callend on app suspension, which destroys the window. so, will need to destroy the Surface and recreate during resume event.

Panic

Panic on other platforms

source

fn resume(&mut self, _window_backend: &mut impl WindowBackend)

Android Only. called when app is resumed after suspension. On Android, window can only be created on resume event. so, you cannot create a Surface before entering the event loop. when this fn is called, we can create a new surface (swapchain) for the window. doesn’t apply on other platforms.

Implementors§