pub struct CallbackFn { /* private fields */ }
Expand description

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

The callback is composed of two functions: prepare and paint:

  • prepare is called every frame before paint, and can use the passed-in wgpu::Device and wgpu::Buffer to allocate or modify GPU resources such as buffers.
  • paint is called after prepare and 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.

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

source

pub fn new() -> Self

source

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.

source

pub fn paint<F>(self, paint: F) -> Selfwhere
F: for<'a, 'b> Fn(PaintCallbackInfo, &'a mut RenderPass<'b>, &'b TypeMap) + Sync + Send + 'static,

Set the paint callback

Trait Implementations§

source§

impl Default for CallbackFn

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more