pub trait CallbackTrait: Send + Sync {
    // Required method
    fn paint<'a>(
        &'a self,
        info: PaintCallbackInfo,
        render_pass: &mut RenderPass<'a>,
        callback_resources: &'a CallbackResources
    );

    // Provided methods
    fn prepare(
        &self,
        _device: &Device,
        _queue: &Queue,
        _screen_descriptor: &ScreenDescriptor,
        _egui_encoder: &mut CommandEncoder,
        _callback_resources: &mut CallbackResources
    ) -> Vec<CommandBuffer> { ... }
    fn finish_prepare(
        &self,
        _device: &Device,
        _queue: &Queue,
        _egui_encoder: &mut CommandEncoder,
        _callback_resources: &mut CallbackResources
    ) -> Vec<CommandBuffer> { ... }
}
Expand description

A callback trait that can be used to compose an epaint::PaintCallback via Callback for custom WGPU rendering.

Callbacks in Renderer are done in three steps:

Each callback has access to an instance of CallbackResources that is stored in the Renderer. This can be used to store wgpu resources that need to be accessed during the CallbackTrait::paint step.

The callbacks implementing CallbackTrait itself must always be Send + Sync, but resources stored in Renderer::callback_resources are not required to implement Send + Sync when building for wasm. (this is because wgpu stores references to the JS heap in most of its resources which can not be shared with other threads).

§Command submission

§Command Encoder

The passed-in CommandEncoder is egui’s and can be used directly to register wgpu commands for simple use cases. This allows reusing the same wgpu::CommandEncoder for all callbacks and egui rendering itself.

§Command Buffers

For more complicated use cases, one can also return a list of arbitrary CommandBuffers and have complete control over how they get created and fed. In particular, this gives an opportunity to parallelize command registration and prevents a faulty callback from poisoning the main wgpu pipeline.

When using eframe, the main egui command buffer, as well as all user-defined command buffers returned by this function, are guaranteed to all be submitted at once in a single call.

Command Buffers returned by CallbackTrait::finish_prepare will always be issued after those returned by CallbackTrait::prepare. Order within command buffers returned by CallbackTrait::prepare is dependent on the order the respective epaint::Shape::Callbacks were submitted in.

§Example

See the custom3d_wgpu demo source for a detailed usage example.

Required Methods§

source

fn paint<'a>( &'a self, info: PaintCallbackInfo, render_pass: &mut RenderPass<'a>, callback_resources: &'a CallbackResources )

Called after all CallbackTrait::finish_prepare calls are done.

It is given access to the wgpu::RenderPass so that it can issue draw commands into the same wgpu::RenderPass that is used for all other egui elements.

Provided Methods§

source

fn prepare( &self, _device: &Device, _queue: &Queue, _screen_descriptor: &ScreenDescriptor, _egui_encoder: &mut CommandEncoder, _callback_resources: &mut CallbackResources ) -> Vec<CommandBuffer>

source

fn finish_prepare( &self, _device: &Device, _queue: &Queue, _egui_encoder: &mut CommandEncoder, _callback_resources: &mut CallbackResources ) -> Vec<CommandBuffer>

Called after all CallbackTrait::prepare calls are done.

Implementors§