Trait cushy::RenderOperation

source ·
pub trait RenderOperation:
    Send
    + Sync
    + 'static {
    type DrawInfo;
    type Prepared: Debug + Send + Sync + 'static;

    // Required methods
    fn new(graphics: &mut Graphics<'_>) -> Self;
    fn prepare(
        &mut self,
        context: Self::DrawInfo,
        origin: Point<Px>,
        graphics: &mut Graphics<'_>,
    ) -> Self::Prepared;
    fn render(
        &self,
        prepared: &Self::Prepared,
        origin: Point<Px>,
        opacity: f32,
        graphics: &mut RenderingGraphics<'_, '_>,
    );
}
Expand description

A custom wgpu-powered rendering operation.

§How custom rendering ops work

When Graphics::draw/Graphics::draw_with are invoked for the first time for a given RenderOperation implementor, new() is called to create a shared instance of this rendering operation. The new function is a good location to put any initialization that can be shared amongst all drawing calls, as it is invoked only once for each surface.

After an existing or newly-created operation is located, prepare() is invoked passing through the DrawInfo provided to the draw call. The result of this function is stored.

When the graphics is presented, render() is invoked providing the data returned from the prepare() function.

Required Associated Types§

source

type DrawInfo

Data that is provided to the prepare() function. This is passed through from the draw/draw_with invocation.

source

type Prepared: Debug + Send + Sync + 'static

Data that is created in the prepare() function, and provided to the render() function.

Required Methods§

source

fn new(graphics: &mut Graphics<'_>) -> Self

Returns a new instance of this render operation.

source

fn prepare( &mut self, context: Self::DrawInfo, origin: Point<Px>, graphics: &mut Graphics<'_>, ) -> Self::Prepared

Prepares this operation to be rendered at origin in graphics.

source

fn render( &self, prepared: &Self::Prepared, origin: Point<Px>, opacity: f32, graphics: &mut RenderingGraphics<'_, '_>, )

Render preprared to graphics at origin with opacity.

Object Safety§

This trait is not object safe.

Implementors§