Package limn.render3d

Class DebugDraw

java.lang.Object
limn.render3d.DebugDraw

public final class DebugDraw extends Object
Immediate-mode debug geometry: world-space lines (AABBs, oriented boxes, axes, grids, rays) batched on the CPU and flushed into a RenderPass once per frame. Purely a vertex buffer builder: no GL, so it works headless and in tests; the backend draws the batch after the scene's meshes.

Two buckets: depth-tested lines are occluded by scene geometry like any mesh; overlay ("X-ray") lines draw on top regardless of depth. Select with depthTest(boolean); primitives go to the current bucket.

GC discipline: vertices accumulate into reused, doubling float[]s; steady-state emission allocates nothing. The core primitives take floats; Vec3/Vec4 conveniences exist for call sites where clarity beats the last allocation. Typical per-frame use inside a Viewport3D.Renderer:


 debug.grid(10, 20, gray);
 debug.axes(nodeWorld, 0.5f);
 debug.depthTest(false).aabb(worldBounds, red);
 debug.flush(pass); // submits both buckets and resets for the next frame
 

Lines are 1 px (core profile clamps glLineWidth; the viewport's MSAA target antialiases them). Colors are STRAIGHT (non-premultiplied) and are alpha-blended over whatever the pass has already drawn, so a faded guide really does read as faded.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Floats per vertex: x, y, z, r, g, b, a.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    aabb(Aabb box, Vec4 color)
    The 12 edges of an axis-aligned box.
    axes(Mat4 transform, float size)
    The basis of an affine transform drawn from its origin: X red, Y green, Z blue, each size long (in the transform's own scale).
    void
    Drops all emitted vertices (buckets stay allocated for reuse).
    depthTest(boolean on)
    Selects the bucket for subsequent primitives (default: depth-tested).
    void
    Submits both buckets to the pass and resets for the next frame.
    grid(float halfExtent, int divisions, Vec4 color)
    A square grid on the XZ plane at y=0, centered at the origin: divisions×divisions cells spanning ±halfExtent.
    line(float x0, float y0, float z0, float x1, float y1, float z1, float r, float g, float b, float a)
    A world-space line segment, the primitive everything else builds on.
    line(Vec3 from, Vec3 to, Vec4 color)
    Queues a world-space line for this frame; cleared after it is drawn.
    obb(Aabb box, Mat4 transform, Vec4 color)
    The 12 edges of box transformed by an affine transform, an oriented box (a mesh's local bounds under its world matrix), unlike aabb(box.transformedBy(m), …) which draws the axis-aligned hull the culler uses.
    ray(Ray ray, float length, Vec4 color)
    A ray drawn length long from its origin.
    int
    vertexCount(boolean depthTestedBucket)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FLOATS_PER_VERTEX

      public static final int FLOATS_PER_VERTEX
      Floats per vertex: x, y, z, r, g, b, a.
      See Also:
  • Constructor Details

    • DebugDraw

      public DebugDraw()
  • Method Details

    • depthTest

      public DebugDraw depthTest(boolean on)
      Selects the bucket for subsequent primitives (default: depth-tested).
    • line

      public DebugDraw line(float x0, float y0, float z0, float x1, float y1, float z1, float r, float g, float b, float a)
      A world-space line segment, the primitive everything else builds on.
    • line

      public DebugDraw line(Vec3 from, Vec3 to, Vec4 color)
      Queues a world-space line for this frame; cleared after it is drawn.
    • aabb

      public DebugDraw aabb(Aabb box, Vec4 color)
      The 12 edges of an axis-aligned box. Empty boxes draw nothing.
    • obb

      public DebugDraw obb(Aabb box, Mat4 transform, Vec4 color)
      The 12 edges of box transformed by an affine transform, an oriented box (a mesh's local bounds under its world matrix), unlike aabb(box.transformedBy(m), …) which draws the axis-aligned hull the culler uses. Empty boxes draw nothing.
    • axes

      public DebugDraw axes(Mat4 transform, float size)
      The basis of an affine transform drawn from its origin: X red, Y green, Z blue, each size long (in the transform's own scale).
    • grid

      public DebugDraw grid(float halfExtent, int divisions, Vec4 color)
      A square grid on the XZ plane at y=0, centered at the origin: divisions×divisions cells spanning ±halfExtent.
    • ray

      public DebugDraw ray(Ray ray, float length, Vec4 color)
      A ray drawn length long from its origin.
    • flush

      public void flush(RenderPass pass)
      Submits both buckets to the pass and resets for the next frame. The arrays are handed to the backend by reference and consumed before this pass's render call returns; call once, at the end of frame emission.
    • clear

      public void clear()
      Drops all emitted vertices (buckets stay allocated for reuse).
    • vertexCount

      public int vertexCount(boolean depthTestedBucket)
      Returns:
      vertices currently held in the given bucket (for tests/HUDs)