Skip to main content

Module custom_render

Module custom_render 

Source
Expand description

Public hook for user widgets to inject their own wgpu render pass(es) into the agg-gui frame.

§Why

agg-gui paints 2-D widgets via deferred DrawCommands that flush into a single wgpu::CommandEncoder in WgpuGfxCtx::end_frame. A 3-D viewport widget (e.g. AtomArtist’s Viewport3dWidget) needs to run its own render pass(es) interleaved with that 2-D stream so its output ends up on the same surface or layer texture, with depth-correct ordering relative to surrounding 2-D content.

The demo’s own WgpuCubeWidget used to push a hard-coded DrawCommand::DrawBarGrid variant directly into the command list — which worked but was not extensible, and it kept demo content inside the renderer. This module generalises that pattern so any widget can plug in; the cube now rides this path like everyone else.

§How to use

  1. Define a struct that implements WgpuCustomRender.
  2. Hold it in Rc<RefCell<dyn WgpuCustomRender>> so the widget can keep a clone (lazy-init / persistent buffers across frames).
  3. From your widget’s paint(ctx), downcast ctx to WgpuGfxCtx via DrawCtx::as_any_mut and call WgpuGfxCtx::push_custom_render.

§Pass semantics

When the executor reaches a DrawCommand::Custom entry, it:

  1. Ends the active 2-D render pass.
  2. Calls WgpuCustomRender::render with a WgpuCustomRenderCtx pointing at the same encoder + active target view.
  3. Reopens a 2-D pass with LoadOp::Load so subsequent 2-D content composites cleanly on top.

The custom renderer may record any number of its own passes against the encoder, including offscreen passes followed by a blit to target_view. Conventionally the implementor should leave its target state untouched after returning (no in-progress pass, no orphaned buffer mappings).

Structs§

WgpuCustomRenderCtx
Inputs handed to a WgpuCustomRender implementor at execution time.

Traits§

WgpuCustomRender
Trait implemented by widgets that want to inject custom wgpu render commands into the frame.

Type Aliases§

SharedCustomRenderer
Convenience type alias for the boxed-trait pattern most callers use.