Caffeine

2D vector overlays (RHI path)

Reference Namespace: `Caffeine::Render` Last verified: Source: render/Overlay2D.hpp

Retained-mode debug and gameplay lines, circles and rectangles, drawn through ImGui in the editor and tessellated for a future RHI overlay pass.

Play-mode debug and gameplay primitives are batched in Render::Overlay2D (line, circle, circleFilled, rect, polyline) and cleared by beginFrame().

ImGui path (editor + current runtime)#

When CF_HAS_IMGUI is defined, Overlay2D::draw(ImDrawList*, camera, screenOrigin, panelSize) renders after the world and before UI widgets.

Shipping / no ImGui#

  1. Scripts record primitives via caffeine.draw2d.* (same buffer as ImGui).
  2. Overlay2D::buildRhiMesh(camera, screenOrigin, vertices) tessellates the commands into screen-space RhiVertex values (x, y, r, g, b, a); world-space commands are transformed with the Camera2D first.
  3. Overlay2D::drawRhi(CommandBuffer*, camera, screenOrigin) is the GPU submission entry point.

Shader sources live in src/caffeine/render/shaders/overlay2d.vert and overlay2d.frag. drawRhi is compiled only with CF_HAS_SDL3 and without CF_HEADLESS.

Until the pipeline is registered, tessellation still runs so gameplay logic can be tested; the upload is a no-op (drawRhi tessellates, then discards the vertices).

Coordinate spaces#

  • world — values in scene units; transformed with Camera2D.
  • screen — pixel offsets relative to the viewport origin; converted via screenToWorld for world-space commands.