Class ShapeBatchExtensions
Wires ShapeBatch rendering into a game's graphics compositor.
public static class ShapeBatchExtensions
- Inheritance
-
ShapeBatchExtensions
Methods
AddShapeBatch(Game, bool, IComputeColor?, bool)
Registers the shape renderer and returns the batch to submit shapes to.
public static ShapeBatch AddShapeBatch(this Game game, bool depthTest = false, IComputeColor? fill = null, bool afterPostEffects = false)
Parameters
gameGameThe 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 the post-processing chain, in the compositor's UI stage, where the text renderers draw: a colour comes out as given. In the scene, a shape goes through the tone mapper with everything else, and under auto exposure a white shape lands at whatever grey the frame's brightness leaves it - about half, next to text that is truly white. That is right for a decal on the ground and wrong for a HUD. Nothing is depth-tested there; the compositor must have the toolkit's UI stage (
AddUIStageorAddCleanUIStage, whichSetupBase3DandAddGraphicsCompositorboth do), else the batch falls back to the scene's 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; 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(Game, 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 Game game, ShapeBatch batch)
Parameters
gameGameThe game the batch was added to.
batchShapeBatchThe batch AddShapeBatch(Game, bool, IComputeColor?, bool) returned.