Vixen
02b45cc4
csharp
public sealed class DebugDraw

Immediate-mode debug geometry: say what you want to see, from wherever you are, and it is there until it expires.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

The point is that a call site does not have to own anything. A collision routine that wants to show a contact normal calls Line and forgets about it — no resource to create, nothing to dispose, and nothing to remember to remove when the investigation is over except the call itself.

This is the accumulator, not the renderer. Everything lands in one of three lists — world lines, world labels, and screen-space lines — and DebugDrawRenderer drains them once a frame and turns them into two draw calls. Splitting them that way is what lets a subsystem be written against this with no reference to a graphics API at all: physics, navigation and audio all produce debug geometry without linking a device.

Every shape is lines, including the round ones and the lettered ones. A debug sphere is three rings and reads as a sphere; giving it a mesh would mean a second pipeline, a depth decision and a lighting decision, for geometry whose whole job is to be unmistakably not part of the scene. Text is DebugFont's strokes for the same reason — and because a debug overlay has to work in the frame where the font atlas is the thing that is broken.

⚠ Not thread-safe, on purpose. The lists are plain List`1s and a call is a handful of stores; making them safe would mean a lock on a path taken thousands of times a frame, to serve a case — two threads drawing at once — that is better answered by an accumulator per job. Draw from the loop thread, or from a job that owns one of these.

Fields and properties (7)

  • public bool Enabled

    Whether anything is recorded at all. Off is free: every call returns immediately.

  • public ReadOnlySpan<DebugLine> Lines

    What a renderer drains for the world pass.

  • public ReadOnlySpan<DebugScreenLine> ScreenLines

    What a renderer drains for the screen pass.

  • public ReadOnlySpan<DebugText> Texts

    The labels a renderer has to face at the camera before it can draw them.

  • public int Count

    How many world lines are queued.

  • public int ScreenCount

    How many screen lines are queued.

  • public int TextCount

    How many world labels are queued.

Methods (19)

  • public void Line(Vector3 from, Vector3 to, Color4 colour, float seconds = 0)

    Draws a line.

  • public void Ray(Vector3 origin, Vector3 direction, Color4 colour, float seconds = 0)

    Draws a ray from a point along a direction.

  • public void Arrow(Vector3 from, Vector3 to, Color4 colour, float seconds = 0)

    Draws a line with a head on the far end, so its direction is readable.

  • public void Cross(Vector3 position, float size, Color4 colour, float seconds = 0)

    Draws a small three-armed cross, for marking a point.

  • public void Box(BoundingBox box, Color4 colour, float seconds = 0)

    Draws an axis-aligned box as its twelve edges.

  • public void Box(BoundingBox box, in Matrix4x4 transform, Color4 colour, float seconds = 0)

    Draws a box that has been moved and turned — an oriented bounding box.

  • public void Sphere(BoundingSphere sphere, Color4 colour, float seconds = 0)

    Draws a sphere as three great circles.

  • public void Circle(Vector3 centre, Vector3 normal, float radius, Color4 colour, float seconds = 0)

    Draws a circle in the plane a normal defines.

  • public void Capsule(Vector3 from, Vector3 to, float radius, Color4 colour, float seconds = 0)

    Draws a capsule: a segment with a hemisphere on each end.

  • public void Cone(Vector3 apex, Vector3 direction, float radius, Color4 colour, float seconds = 0)

    Draws a cone as its base circle and four lines to the apex.

  • public void Frustum(in BoundingFrustum frustum, Color4 colour, float seconds = 0)

    Draws a view volume as its twelve edges.

  • public void Axes(Matrix4x4 transform, float length = 1, float seconds = 0)

    Draws a transform's three axes, red for X, green for Y, blue for Z.

  • public void Text(Vector3 position, string text, Color4 colour, float size = 0.25, float seconds = 0)

    Puts a label at a point in the world, facing whatever camera draws it.

  • public void ScreenLine(Vector2 from, Vector2 to, Color4 colour, float seconds = 0)

    Draws a line in screen space, in pixels from the top-left.

  • public void ScreenRect(Vector2 topLeft, Vector2 size, Color4 colour, float seconds = 0)

    Draws the outline of a screen-space rectangle.

  • public void ScreenFill(Vector2 topLeft, Vector2 size, Color4 colour, float spacing = 1, float seconds = 0)

    Fills a screen-space rectangle, as scanlines.

  • public void ScreenText(Vector2 position, ReadOnlySpan<char> text, Color4 colour, float size = 12, float seconds = 0)

    Draws text in screen space, in pixels from the top-left.

  • public void Advance(float seconds)

    Ages everything by a frame: one-frame geometry goes, timed geometry loses .

  • public void Clear()

    Throws everything away.

Used by (25)

  • AnimationSystemsVixen.Animation
  • ConsoleTestsVixen.Engine.Tests
  • ConstraintGizmoSystemVixen.Animation
  • ConstraintGizmosVixen.Animation
  • DebugDrawImageTestsVixen.Graphics.Golden.Tests
  • DebugDrawRendererVixen.Engine.Renderer
  • DebugDrawShapeTestsVixen.Engine.Tests
  • DebugDrawSystemVixen.Engine
  • DebugDrawTestsVixen.Engine.Tests
  • DebugGeometryVixen.Engine.Renderer
  • DebugGeometryTestsVixen.Engine.Renderer.Tests
  • DiagnosticOverlaySystemVixen.Engine
  • DiagnosticOverlayTestsVixen.Engine.Tests
  • DiagnosticOverlaysVixen.Engine
  • GizmoTestsVixen.Animation.Tests
  • NavMeshDebugDrawVixen.Navigation
  • NavMeshDebugDrawTestsVixen.Navigation.Tests
  • OverlayRegionVixen.Engine
  • OverlaySurfaceVixen.Engine
  • PhysicsDebugDrawVixen.Physics
  • PhysicsDebugDrawSystemVixen.Physics
  • PhysicsSceneTestsVixen.Physics.Tests
  • ScreenSinkVixen.Engine
  • ProxyShapeEditorTestsVixen.Editor.AssetEditors.Tests
  • ProxyShapeViewVixen.Editor.AssetEditors