Header menu logo Mibo

PrimitiveBatch Type

Batch renderer for 2D primitive shapes using vertex arrays and GraphicsDevice.DrawUserPrimitives.

Mirrors raylib's primitive rendering (circles, rings, triangles, lines, polygons, etc.) on top of MonoGame. The batch accumulates vertices in managed arrays and flushes them as PrimitiveType groups. This avoids per-geometry GPU resource allocation; DrawUserPrimitives copies the current vertex span to the device on flush.

The renderer owns one PrimitiveBatch alongside its SpriteBatch. State transitions (camera changes, DrawImmediate) flush both batches before re-entering with updated transform settings.

Constructors

Constructor Description

PrimitiveBatch(graphicsDevice)

Full Usage: PrimitiveBatch(graphicsDevice)

Parameters:
Returns: PrimitiveBatch
graphicsDevice : GraphicsDevice
Returns: PrimitiveBatch

Instance members

Instance member Description

this.AddLine

Full Usage: this.AddLine

Parameters:

Adds a single line segment with the given color.

start : Vector2
end : Vector2
color : Color

this.AddLineStrip

Full Usage: this.AddLineStrip

Parameters:

Adds a line strip with the given color.

points : Vector2[]
color : Color

this.AddLineThick

Full Usage: this.AddLineThick

Parameters:

Adds a thick line as a quad (two triangles) with the given thickness and color.

start : Vector2
end : Vector2
thickness : float32
color : Color

this.AddTriangleFan

Full Usage: this.AddTriangleFan

Parameters:
    points : Vector2[] - points[0] is the fan center; points[1..] are the rim vertices in order. points.Length must be at least 3.
    color : Color - Vertex color applied to every generated vertex.
    ?closeLoop : bool - When true (default), the last rim vertex is connected back to points[1], closing the fan into a loop. Use false for open arcs (e.g. a partial circle sector) where connecting the ends would draw an unwanted chord across the mouth.

Adds a triangle fan by decomposing into a triangle list.

points : Vector2[]

points[0] is the fan center; points[1..] are the rim vertices in order. points.Length must be at least 3.

color : Color

Vertex color applied to every generated vertex.

?closeLoop : bool

When true (default), the last rim vertex is connected back to points[1], closing the fan into a loop. Use false for open arcs (e.g. a partial circle sector) where connecting the ends would draw an unwanted chord across the mouth.

this.AddTriangleStrip

Full Usage: this.AddTriangleStrip

Parameters:

Adds a triangle strip with the given color.

points : Vector2[]
color : Color

this.AddTriangles

Full Usage: this.AddTriangles

Parameters:

Adds a triangle list with the given vertices.

verts : VertexPositionColor[]

this.Begin

Full Usage: this.Begin

Parameters:

Begins a batch with the given world/camera transform.

matrix : Matrix

this.End

Full Usage: this.End

Ends the batch, flushing any remaining vertices.

this.Flush

Full Usage: this.Flush

Flushes all buffered primitive groups to the GPU.

this.LineWidth

Full Usage: this.LineWidth

Gets or sets the default thick-line width used by SetLineWidth.

this.SetBlendState

Full Usage: this.SetBlendState

Parameters:

Changes the blend state applied during flush.

blend : BlendState

this.SetEffect

Full Usage: this.SetEffect

Parameters:

Replaces the effect used during flush.

ValueNone restores the internal BasicEffect.

effect : Effect voption

this.SetRasterizerState

Full Usage: this.SetRasterizerState

Parameters:

Changes the rasterizer state applied during flush.

rasterizer : RasterizerState

this.SetTransform

Full Usage: this.SetTransform

Parameters:

Changes the active world/camera transform mid-batch.

Flushes pending vertices, updates the transform, then resumes.

matrix : Matrix

Type something to start searching.