Struct egui_wgpu::renderer::CallbackFn
source · pub struct CallbackFn { /* private fields */ }Expand description
A callback function that can be used to compose an [egui::PaintCallback] for custom WGPU
rendering.
The callback is composed of two functions: prepare and paint:
prepareis called every frame beforepaint, and can use the passed-inwgpu::Deviceandwgpu::Bufferto allocate or modify GPU resources such as buffers.paintis called afterprepareand is given access to thewgpu::RenderPassso that it can issue draw commands into the samewgpu::RenderPassthat is used for all other egui elements.
The final argument of both the prepare and paint callbacks is a the
paint_callback_resources.
paint_callback_resources has the same lifetime as the Egui render pass, so it can be used to
store buffers, pipelines, and other information that needs to be accessed during the render
pass.
Example
See the custom3d_wgpu demo source for a detailed usage example.
Implementations§
source§impl CallbackFn
impl CallbackFn
pub fn new() -> Self
sourcepub fn prepare<F>(self, prepare: F) -> Selfwhere
F: Fn(&Device, &Queue, &mut CommandEncoder, &mut TypeMap) -> Vec<CommandBuffer> + Sync + Send + 'static,
pub fn prepare<F>(self, prepare: F) -> Selfwhere
F: Fn(&Device, &Queue, &mut CommandEncoder, &mut TypeMap) -> Vec<CommandBuffer> + Sync + Send + 'static,
Set the prepare callback.
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.
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.