Logo Mibo

InstancedRenderContext<'T, 'K> Type

Contextual object for instanced cell-grid rendering on the MonoGame backend. Bundles the key/material/transform functions and manages internal reusable storage and snapshot pooling to avoid per-frame allocations.

Ported from Mibo.Raylib/Layout3D/Renderer3D.fs with type swaps per §5/§6.2:

  • Raylib_cs.Mesh → PrimitiveMesh
  • System.Numerics.Matrix4x4 → Matrix (converted at the Core↔backend boundary via Conversions).
  • System.Numerics.Vector3 → Vector3 (same).
The layout logic itself lives in Mibo.Core.Layout3D (backend-agnostic) and is reused unchanged; only the renderer glue is ported.

Constructors

Constructor Description

InstancedRenderContext(getKey, getParts, getTransform)

Full Usage: InstancedRenderContext(getKey, getParts, getTransform)

Parameters:
Returns: InstancedRenderContext<'T, 'K>

Constructs a context over zero-copy ModelPart slices (e.g. ModelParts.ofModel results): each group emits one instanced command per part, folding the part's own absolute bone into a pooled per-part snapshot and passing the part's real buffer offsets. The getTransform bone fold of the two-element ctor must NOT be used here — the context applies per-part bones itself.

getKey : 'T -> 'K
getParts : 'T -> ModelPart[]
getTransform : Vector3 -> 'T -> Matrix
Returns: InstancedRenderContext<'T, 'K>

InstancedRenderContext(getKey, getMeshesMaterialAndShader, getTransform)

Full Usage: InstancedRenderContext(getKey, getMeshesMaterialAndShader, getTransform)

Parameters:
Returns: InstancedRenderContext<'T, 'K>

Overload constructor for per-sub-mesh shaders: each triple may carry an Effect voption. A ValueSome effect wraps that sub-mesh's instanced draw in its own BeginEffect/EndEffect scope; ValueNone uses the default PBR instanced path. Existing two-element contexts are unaffected.

getKey : 'T -> 'K
getMeshesMaterialAndShader : 'T -> (PrimitiveMesh * Material3D * Effect voption)[]
getTransform : Vector3 -> 'T -> Matrix
Returns: InstancedRenderContext<'T, 'K>

InstancedRenderContext(getKey, getMeshesAndMaterial, getTransform)

Full Usage: InstancedRenderContext(getKey, getMeshesAndMaterial, getTransform)

Parameters:
Returns: InstancedRenderContext<'T, 'K>
getKey : 'T -> 'K
getMeshesAndMaterial : 'T -> (PrimitiveMesh * Material3D)[]
getTransform : Vector3 -> 'T -> Matrix
Returns: InstancedRenderContext<'T, 'K>

Instance members

Instance member Description

this.GetKey

Full Usage: this.GetKey

Returns: 'T -> 'K
Returns: 'T -> 'K

this.GetMeshesAndMaterial

Full Usage: this.GetMeshesAndMaterial

Returns: 'T -> (PrimitiveMesh * Material3D)[]
Returns: 'T -> (PrimitiveMesh * Material3D)[]

this.GetTransform

Full Usage: this.GetTransform

Returns: Vector3 -> 'T -> Matrix
Returns: Vector3 -> 'T -> Matrix

this.RenderInstanced

Full Usage: this.RenderInstanced

Parameters:

RenderInstanced over the anchors of an occupancy: one instance per anchor, and each anchor's rectangle reaches the transform. A covered cell draws nothing of its own, so a plate stays one instance.

buffer : RenderBuffer3D
grid : CellGrid2D<'T>
occupancy : Occupancy

this.RenderInstanced

Full Usage: this.RenderInstanced

Parameters:

Fills the context from every populated cell of a 2D footprint grid — square or hex — and emits the instanced draws, one per key. Each cell is its own instance, so a cell that covers several cells draws at one cell; use the occupancy member for those.

buffer : RenderBuffer3D
grid : CellGrid2D<'T>

this.RenderInstancedWithEffect

Full Usage: this.RenderInstancedWithEffect

Parameters:

RenderInstanced with an occupancy and per-key effect scoping, like RenderInstancedWithEffect.

buffer : RenderBuffer3D
grid : CellGrid2D<'T>
occupancy : Occupancy
shaderForKey : 'K -> Effect voption

this.RenderInstancedWithEffect

Full Usage: this.RenderInstancedWithEffect

Parameters:

RenderInstanced wrapping each key's draws in a BeginEffect/EndEffect scope when shaderForKey returns ValueSome.

buffer : RenderBuffer3D
grid : CellGrid2D<'T>
shaderForKey : 'K -> Effect voption

this.RenderWindowInstanced

Full Usage: this.RenderWindowInstanced

Parameters:

RenderWindowInstanced over the anchors of an occupancy: the world-space window becomes a cell range, and every anchor whose rectangle intersects it is drawn — so an instance that covers a window cell from an anchor outside the window stays drawn.

buffer : RenderBuffer3D
left : int
top : int
right : int
bottom : int
grid : CellGrid2D<'T>
occupancy : Occupancy

this.RenderWindowInstanced

Full Usage: this.RenderWindowInstanced

Parameters:

Like RenderInstanced but restricted to a world-space window (left/top/right/bottom in int world coordinates). Hex grids cull with an orientation-aware window. A cell-windowed walk drops a large instance once its anchor leaves the window: use the occupancy member for a map with spans.

buffer : RenderBuffer3D
left : int
top : int
right : int
bottom : int
grid : CellGrid2D<'T>

this.RenderWindowInstancedWithEffect

Full Usage: this.RenderWindowInstancedWithEffect

Parameters:

RenderWindowInstanced with an occupancy and per-key effect scoping.

buffer : RenderBuffer3D
left : int
top : int
right : int
bottom : int
grid : CellGrid2D<'T>
occupancy : Occupancy
shaderForKey : 'K -> Effect voption

this.RenderWindowInstancedWithEffect

Full Usage: this.RenderWindowInstancedWithEffect

Parameters:

RenderWindowInstanced with per-key effect scoping, like RenderInstancedWithEffect.

buffer : RenderBuffer3D
left : int
top : int
right : int
bottom : int
grid : CellGrid2D<'T>
shaderForKey : 'K -> Effect voption

this.ResetFrameBuffers

Full Usage: this.ResetFrameBuffers

Returns pooled snapshot arrays to ArrayPool and clears internal tracking state. Call once per frame before invoking renderInstanced or renderVolumeInstanced.

Skippable if GC pressure from instanced rendering is acceptable, but recommended for steady-state zero-alloc rendering.

Static members

Static member Description

InstancedRenderContext.Rect(getKey, getMeshesAndMaterial, getTransform)

Full Usage: InstancedRenderContext.Rect(getKey, getMeshesAndMaterial, getTransform)

Parameters:
Returns: InstancedRenderContext<'T, 'K>

Builds a context whose transform receives the rectangle each instance covers — the anchor's own cell on the cell-walk members, the anchor's rectangle on the occupancy members — so one model scales to the cells it stands for: InstancedRenderContext<Cell, string>.Rect(getKey, getMeshesAndMaterial, getTransform).

getKey : 'T -> 'K
getMeshesAndMaterial : 'T -> (PrimitiveMesh * Material3D)[]
getTransform : CellRect -> Vector3 -> 'T -> Matrix
Returns: InstancedRenderContext<'T, 'K>

Type something to start searching.