Skip to content

ludus::graphics::renderer::SelectionOutlineRenderer

Ludus Wiki · API overview · Browse API

Class

Draws the silhouette outline of one selected triangle mesh over an image, entirely on the GPU.
The outline is found in screen space instead of from the mesh's edges. The selected mesh is rasterized once into a one-channel coverage mask, with no depth test so that another object in front does not hide the outline. A second pass over the mesh's projected bounds then strokes the boundary of that mask: every pixel within half a stroke width of a boundary between covered and uncovered pixels takes the stroke colour. Only the outer contour of the projected mesh, and the contour of any hole in it, is stroked; edges inside the projected area are not part of the mask boundary.
The cost per frame is one rasterization of the mesh's triangles plus a bounded neighbourhood search per pixel near the mesh, and does not grow with an adjacency build or per-frame CPU work on the mesh. Selecting a mesh uploads its positions and indices once, in SetMesh.
It uses the portable raster profile only, a vertex/index buffer pair, instance rows, one sampled texture and premultiplied blending, so it runs on every RHI backend including the browser backends.
All members run on the RHI owner thread, between frames, except Draw, which records into an open frame. The device must outlive this object.

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

#include <ludus/graphics/renderer/selection_outline.hpp>
class ludus::graphics::renderer::SelectionOutlineRenderer final

Static fields

MAX_STROKE_WIDTH_PIXELS

static constexpr foundation::float32 ludus::graphics::renderer::SelectionOutlineRenderer::MAX_STROKE_WIDTH_PIXELS = 16
Largest stroke width, in physical pixels, bounding the per-pixel search.

Related types: foundation::float32

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

Methods

SelectionOutlineRenderer

ludus::graphics::renderer::SelectionOutlineRenderer::SelectionOutlineRenderer() noexcept
Construct without allocation or device access.

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

~SelectionOutlineRenderer

ludus::graphics::renderer::SelectionOutlineRenderer::~SelectionOutlineRenderer()
Release logical GPU ownership; RHI retires accepted uses.

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

Initialize

rhi::RasterStatus ludus::graphics::renderer::SelectionOutlineRenderer::Initialize(rhi::DeviceHandle device, const rhi::RasterShaderDescription &maskVertex, const rhi::RasterShaderDescription &maskFragment, const rhi::RasterShaderDescription &edgeVertex, const rhi::RasterShaderDescription &edgeFragment) noexcept
Create the fixed shaders, layouts, sampler and pipelines.
ParameterDescription
device
Ready device with the portable raster profile.
maskVertex
Vertex stage of renderer_selection_mask.
maskFragment
Fragment stage of renderer_selection_mask.
edgeVertex
Vertex stage of renderer_selection_outline.
edgeFragment
Fragment stage of renderer_selection_outline.

Returns

Ready or Pending once owned (poll Poll until Ready); InvalidDescription when a stage does not have the expected interface; InvalidState when already initialized. Failure requires Reset before retry.

Related types: rhi::RasterStatus · rhi::DeviceHandle · rhi::RasterShaderDescription

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

Poll

rhi::RasterStatus ludus::graphics::renderer::SelectionOutlineRenderer::Poll() noexcept
Advance asynchronous setup between frames, without waiting.

Related types: rhi::RasterStatus

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

Reset

void ludus::graphics::renderer::SelectionOutlineRenderer::Reset() noexcept
Drop the mesh, prepared versions and fixed resources, between frames.

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

IsReady

bool ludus::graphics::renderer::SelectionOutlineRenderer::IsReady() const noexcept
Whether Initialize and its asynchronous setup have completed.

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

SetMesh

rhi::RasterStatus ludus::graphics::renderer::SelectionOutlineRenderer::SetMesh(foundation::BorrowedView< const foundation::math::Vector3 > positionsMesh, foundation::BorrowedView< const foundation::uint32 > indices) noexcept
Upload the mesh to outline, replacing any earlier one. The arrays are copied before return; the caller may release them at once. Existing prepared versions stay valid and draw the new mesh.
ParameterDescription
positionsMesh
Finite mesh-local positions.
indices
Triangle-list indices into positionsMesh: a positive multiple of three, each below the position count.

Returns

Ready or Pending (poll GetMeshStatus); NotReady before Initialize completes; InvalidDescription for an empty, non-finite or out-of-range mesh; CapacityExceeded or OutOfMemory when the RHI refuses the size. Failure preserves the previous mesh.

Related types: foundation::BorrowedView · foundation::uint32 · rhi::RasterStatus · foundation::math::Vector3

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

ClearMesh

void ludus::graphics::renderer::SelectionOutlineRenderer::ClearMesh() noexcept
Forget the mesh. Prepared versions then draw nothing.

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

GetMeshStatus

rhi::RasterStatus ludus::graphics::renderer::SelectionOutlineRenderer::GetMeshStatus() noexcept
Readiness of the mesh buffers: Ready, Pending, or NotReady when no mesh is set.

Related types: rhi::RasterStatus

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

Prepare

rhi::RasterStatus ludus::graphics::renderer::SelectionOutlineRenderer::Prepare(const SelectionOutlineView &view, PreparedSelectionOutline &outPrepared) noexcept
Create the per-frame data of an outline of the current mesh. Creating a version is cheap (one small buffer), so a caller prepares one per distinct view. At most four versions exist at once.
ParameterDescription
view
Matrix, target extent and strokes.
outPrepared
Null on entry; receives the version on Ready or Pending.

Returns

Ready or Pending (poll GetStatus); NotReady before Initialize completes or without a mesh; InvalidDescription for a non-finite matrix, an empty extent or invalid strokes; CapacityExceeded when four versions are in use; InvalidState when outPrepared is not null. Failure preserves outPrepared.

Related types: rhi::RasterStatus · PreparedSelectionOutline · SelectionOutlineView

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

GetStatus

rhi::RasterStatus ludus::graphics::renderer::SelectionOutlineRenderer::GetStatus(PreparedSelectionOutline prepared) noexcept
Poll the version's buffers and the mesh until all are ready to draw. Draw requires Ready.

Related types: rhi::RasterStatus · PreparedSelectionOutline

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

Draw

rhi::RasterStatus ludus::graphics::renderer::SelectionOutlineRenderer::Draw(PreparedSelectionOutline prepared, const rhi::RasterPassDescription &description) noexcept
Draw the outline over an already initialized target. Records two passes into the open frame: the mask, then the strokes over description's target. The target keeps its contents; only pixels near the silhouette change. A mesh entirely outside the target draws nothing and records no pass.
ParameterDescription
prepared
A version whose GetStatus returned Ready, prepared for exactly this target extent.
description
Target and optional viewport/scissor. Color is the acquired surface when null, otherwise an RGBA8 linear attachment. Load, store and depth members are replaced.

Returns

Ready; InvalidHandle for a stale version; InvalidState when the extent changed or the mesh was replaced by an empty one; Unsupported for another target format; or the RHI failure that stopped recording.

Related types: rhi::RasterStatus · PreparedSelectionOutline · rhi::RasterPassDescription

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp

Release

rhi::RasterStatus ludus::graphics::renderer::SelectionOutlineRenderer::Release(PreparedSelectionOutline &inoutPrepared) noexcept
Clear owned identity; submitted resources retire only after RHI completion.

Related types: rhi::RasterStatus · PreparedSelectionOutline

Declared in modules/graphics/renderer/include/ludus/graphics/renderer/selection_outline.hpp