Primitive

Trait Primitive 

Source
pub trait Primitive:
    Debug
    + MaybeSend
    + MaybeSync
    + 'static {
    type Renderer: MaybeSend + MaybeSync;

    // Required methods
    fn initialize(
        &self,
        device: &Device,
        queue: &Queue,
        format: TextureFormat,
    ) -> Self::Renderer;
    fn prepare(
        &self,
        renderer: &mut Self::Renderer,
        device: &Device,
        queue: &Queue,
        bounds: &Rectangle,
        viewport: &Viewport,
    );

    // Provided methods
    fn draw(
        &self,
        _renderer: &Self::Renderer,
        _render_pass: &mut RenderPass<'_>,
    ) -> bool { ... }
    fn render(
        &self,
        _renderer: &Self::Renderer,
        _encoder: &mut CommandEncoder,
        _target: &TextureView,
        _clip_bounds: &Rectangle<u32>,
    ) { ... }
}
Expand description

A set of methods which allows a Primitive to be rendered.

Required Associated Types§

Source

type Renderer: MaybeSend + MaybeSync

The shared renderer of this Primitive.

Normally, this will contain a bunch of [wgpu] state; like a rendering pipeline, buffers, and textures.

All instances of this Primitive type will share the same Renderer.

Required Methods§

Source

fn initialize( &self, device: &Device, queue: &Queue, format: TextureFormat, ) -> Self::Renderer

Initializes the Renderer of the Primitive.

This will only be called once, when the first Primitive of this kind is encountered.

Source

fn prepare( &self, renderer: &mut Self::Renderer, device: &Device, queue: &Queue, bounds: &Rectangle, viewport: &Viewport, )

Processes the Primitive, allowing for GPU buffer allocation.

Provided Methods§

Source

fn draw( &self, _renderer: &Self::Renderer, _render_pass: &mut RenderPass<'_>, ) -> bool

Draws the Primitive in the given [wgpu::RenderPass].

When possible, this should be implemented over render since reusing the existing render pass should be considerably more efficient than issuing a new one.

The viewport and scissor rect of the render pass provided is set to the bounds and clip bounds of the Primitive, respectively.

If you have complex composition needs, then you can leverage render by returning false here.

By default, it does nothing and returns false.

Source

fn render( &self, _renderer: &Self::Renderer, _encoder: &mut CommandEncoder, _target: &TextureView, _clip_bounds: &Rectangle<u32>, )

Renders the Primitive, using the given [wgpu::CommandEncoder].

This will only be called if draw returns false.

By default, it does nothing.

Implementors§