Class ShapeBatchExtensions
Wires ShapeBatch rendering into a game's graphics compositor.
public static class ShapeBatchExtensions
- Inheritance
-
ShapeBatchExtensions
Methods
AddShapeBatch(IGame, bool, IComputeColor?, bool)
Registers the shape renderer and returns the batch to submit shapes to.
public static ShapeBatch AddShapeBatch(this IGame game, bool depthTest = false, IComputeColor? fill = null, bool afterPostEffects = false)
Parameters
gameIGameThe game whose compositor to modify.
depthTestboolWhether scene geometry can occlude these shapes. Leave
falsefor gizmos, 2D scenes and anything that should stay visible through walls; passtruefor decals and ground markers that belong in the scene.fillIComputeColorA fill source for a textured batch - see FillSource - or
nullfor plain fills. FillWith(Texture, Vector2?, Vector2?, TextureAddressMode) installs one later for the common case.afterPostEffectsboolDraw the batch after post-processing, in the compositor's UI stage, so colours are not tone-mapped; in the scene, auto exposure can draw a white shape about half grey. Right for a HUD, wrong for a decal. Nothing is depth-tested there. Needs the toolkit's UI stage (
AddUIStageorAddCleanUIStage, added bySetupBase3DandAddGraphicsCompositor); without it the batch draws in the transparent stage.
Returns
- ShapeBatch
The batch: submit shapes to it every frame from your update logic.
Remarks
Shapes render in the compositor's "Transparent" stage, alpha-blended in submission order,
before UI and debug text - or, with afterPostEffects, in the UI stage
after the post effects. Call after the graphics compositor exists (from the Start callback).
Calling this more than once adds another independent batch, which is how you get depth-tested
and overlay shapes in the same scene. Batches in the same stage draw in the order they were
added, the later one on top. The first batch registers as the service that
ShapeComponent draws through. A scene that never calls this still draws its
components: the processor registers a depth-tested batch of its own the first time it needs one.
Exceptions
- InvalidOperationException
The compositor has no "Transparent" render stage.
RemoveShapeBatch(IGame, ShapeBatch)
Takes a batch out of rendering. Its shapes stop drawing from the next frame; the batch itself can be added again later.
public static void RemoveShapeBatch(this IGame game, ShapeBatch batch)
Parameters
gameIGameThe game the batch was added to.
batchShapeBatchThe batch AddShapeBatch(IGame, bool, IComputeColor?, bool) returned.