cushy

Trait 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,
        region: Rect<Px>,
        graphics: &mut Graphics<'_>,
    ) -> Self::Prepared;
    fn render(
        &self,
        prepared: &Self::Prepared,
        region: Rect<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, region: Rect<Px>, graphics: &mut Graphics<'_>, ) -> Self::Prepared

Prepares this operation to be rendered in region in graphics.

This operation’s will automatically be clipped to the available space for the context it is being drawn to. The render operation should project itself into region and only use the clip rect as an optimization. To test that this is handled correctly, try placing whatever is being rendered in a Scroll widget and ensure that as the contents are clipped, the visible area shows the correct contents.

source

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

Render preprared to graphics at region with opacity.

This operation’s will automatically be clipped to the available space for the context it is being drawn to. The render operation should project itself into region and only use the clip rect as an optimization. To test that this is handled correctly, try placing whatever is being rendered in a Scroll widget and ensure that as the contents are clipped, the visible area shows the correct contents.

Object Safety§

This trait is not object safe.

Implementors§