Skip to main content

Module debug_draw

Module debug_draw 

Source
Expand description

Debug draw accumulator for runtime plugins. Debug draw accumulator for runtime plugins.

DebugDraw is a shared resource that plugins use to submit transient and persistent debug visuals each frame. Store one instance in the runtime resource registry and call DebugDraw::begin_frame before each call to super::ViewportRuntime::step to clear one-frame primitives.

§Usage

use viewport_lib::runtime::debug_draw::{DebugDraw, DebugLayer};

// At startup: insert a DebugDraw resource (dev_enabled controls dev-layer draws).
runtime.resources_mut().insert(DebugDraw::new());

// In each frame, before runtime.step():
if let Some(dd) = runtime.resources_mut().get_mut::<DebugDraw>() {
    dd.begin_frame();
}
let output = runtime.step(&mut scene, &mut selection, &frame_ctx);

// After step: convert accumulated primitives to render items.
if let Some(dd) = runtime.resources().get::<DebugDraw>() {
    frame_data.scene.polylines.extend(dd.to_polylines());
    if let Some(pc) = dd.to_point_cloud() {
        frame_data.scene.point_clouds.push(pc);
    }
    frame_data.overlays.labels.extend(dd.to_labels());
}

§Layers

Each primitive carries a DebugLayer tag:

  • DebugLayer::Dev: dev-mode visuals (contacts, AABBs, normals). Suppressed when DebugDraw::dev_enabled is false. Set this to false in ship builds.
  • DebugLayer::Overlay: always shown regardless of dev_enabled. Use for persistent status overlays that should appear in release builds.

§Lifetime

Primitives submitted via the line, point, aabb, sphere, and label methods are transient: cleared by the next begin_frame call. Persistent primitives are added with add_persistent (keyed by a caller-assigned u64) and stay until explicitly removed with remove_persistent.

§Rendering

DebugDraw is a resource accumulator. It does not submit draw calls. After calling runtime.step(...), convert accumulated primitives to render items and push them into FrameData:

// After step():
if let Some(dd) = runtime.resources().get::<DebugDraw>() {
    frame_data.scene.polylines.extend(dd.to_polylines());
    if let Some(pc) = dd.to_point_cloud() {
        frame_data.scene.point_clouds.push(pc);
    }
    frame_data.overlays.labels.extend(dd.to_labels());
}

If this conversion step is omitted, nothing will appear on screen even if plugins submitted primitives during step.

See examples/eframe_showcase/showcase_46_debug_draw.rs for a complete end-to-end example.

Structs§

DebugDraw
Accumulated debug visuals for the current and future frames.

Enums§

DebugLayer
Category of a debug primitive, controlling visibility in ship vs dev builds.
DebugPrim
A single debug draw primitive.