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.MeshPrimitiveMesh
  • System.Numerics.Matrix4x4Matrix (converted at the Core↔backend boundary via Conversions).
  • System.Numerics.Vector3Vector3 (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.RenderCellGridInstanced

Full Usage: this.RenderCellGridInstanced

Parameters:

Emit instanced draw commands for every occupied cell of grid, grouping cells by shaderForKey: cells whose key maps to an effect are shaded by it (when it opts into instancing), keys mapped to ValueNone keep the default PBR instanced path. See docs/graphics3d/instancing.md.

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

this.RenderCellGridInstanced

Full Usage: this.RenderCellGridInstanced

Parameters:

Emit instanced draw commands for every occupied cell of grid, shaded by the default PBR instanced path.

buffer : RenderBuffer3D
grid : CellGrid3D<'T>

this.RenderCellGridVolumeInstanced

Full Usage: this.RenderCellGridVolumeInstanced

Parameters:

Emit instanced draw commands for the occupied cells of grid inside bounds, grouping cells by shaderForKey: cells whose key maps to an effect are shaded by it (when it opts into instancing), keys mapped to ValueNone keep the default PBR instanced path. See docs/graphics3d/instancing.md.

buffer : RenderBuffer3D
bounds : BoundingBox
grid : CellGrid3D<'T>
shaderForKey : 'K -> Effect voption

this.RenderCellGridVolumeInstanced

Full Usage: this.RenderCellGridVolumeInstanced

Parameters:

Emit instanced draw commands for the occupied cells of grid inside bounds, shaded by the default PBR instanced path.

buffer : RenderBuffer3D
bounds : BoundingBox
grid : CellGrid3D<'T>

this.RenderHexGridInstanced

Full Usage: this.RenderHexGridInstanced

Parameters:

Emit instanced draw commands for every occupied cell of the hex grid, grouping cells by shaderForKey: cells whose key maps to an effect are shaded by it (when it opts into instancing), keys mapped to ValueNone keep the default PBR instanced path. See docs/graphics3d/instancing.md.

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

this.RenderHexGridInstanced

Full Usage: this.RenderHexGridInstanced

Parameters:

Emit instanced draw commands for every occupied cell of the hex grid, shaded by the default PBR instanced path.

buffer : RenderBuffer3D
grid : HexGrid3D<'T>

this.RenderHexGridVolumeInstanced

Full Usage: this.RenderHexGridVolumeInstanced

Parameters:

Emit instanced draw commands for the occupied cells of the hex grid inside bounds, grouping cells by shaderForKey: cells whose key maps to an effect are shaded by it (when it opts into instancing), keys mapped to ValueNone keep the default PBR instanced path. See docs/graphics3d/instancing.md.

buffer : RenderBuffer3D
bounds : BoundingBox
grid : HexGrid3D<'T>
shaderForKey : 'K -> Effect voption

this.RenderHexGridVolumeInstanced

Full Usage: this.RenderHexGridVolumeInstanced

Parameters:

Emit instanced draw commands for the occupied cells of the hex grid inside bounds, shaded by the default PBR instanced path.

buffer : RenderBuffer3D
bounds : BoundingBox
grid : HexGrid3D<'T>

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.

Type something to start searching.