Vixen
02b45cc4
csharp
public sealed class MeshInstanceRenderer

Shapes held on the device, drawn once per entity from a transform.

Read the guide page for this →

Remarks

MeshRenderer for a scene rather than for a tool, and the difference is which way the cost runs. That renderer takes triangles that are already in world space, so its caller transforms every vertex of every object every frame and the cost is linear in vertices — the arrangement its own remarks call the deliberate limit of that path. This one takes geometry once, into a GeometryBuffer, and takes a MeshInstance per entity per frame. A hundred cubes are one draw of a hundred instances; a hundred different meshes are a hundred draws that bind nothing between them, because they came out of one pair of buffers.

⚠ This is still not RenderSystem, and the boundary is materials rather than geometry. There is no culling, no sorting, no material and no descriptor set here: one key direction, one ambient term, a colour per instance. What that is enough for is an editor viewport — a block-out reads as a space in flat grey — and what it is not enough for is a per-face material or a textured surface, which is the compositor's work and stays there.

⚠ The geometry is device-local, so registering a shape stages it and Flush records the copy. Two calls because they happen at different times, exactly as GeometryBuffer describes: a shape is registered when the first entity wanting it appears, and the copies belong at one known point in one command list, outside a render pass.

⚠ One buffer per renderer, and a four-pane layout is four copies of eight primitives. That is a few hundred kilobytes and it buys the renderer being the only owner of anything it binds. The day the shapes are a level's worth of edited meshes rather than eight parametric ones, the buffer wants to be shared and handed in — which is a constructor parameter rather than a change of shape.

Fields and properties (11)

  • public int InstanceCapacity

    How many instances fit in one frame's region.

  • public int Regions

    How many regions the instance ring has.

  • public int Region

    Which region the last upload wrote.

  • public int Count

    How many instances the last upload held.

  • public int Draws

    How many draws the last record issued.

  • public int Dropped

    How many of the last upload's instances no draw covers.

  • public int Triangles

    How many triangles the last upload's surface batches draw.

  • public int Segments

    How many segments its wireframe batches draw.

  • public int Shapes

    How many shapes are registered.

  • public Vector3 LightDirection

    Which way the light comes from, in world space.

  • public float Ambient

    How much light a surface facing away still receives, from zero to one.

Methods (9)

  • public MeshInstanceRenderer(IGraphicsDevice device, MeshInstanceShaders shaders, RenderOutput output, int instanceCapacity = 16384, int vertexCapacity = 262144, int indexCapacity = 1048576)

    Builds the pipelines and the buffers a scene's shapes are drawn with.

  • public long StagingCost(MeshData mesh)

    An upper bound on the staging a registration of this mesh would use.

  • public bool Reserve(long bytes)

    Asks for the staging region to be big enough for a frame's worth of registrations.

  • public bool TryRegister(MeshData mesh, out MeshShapeGeometry shape)

    Puts one shape's geometry on the device, to be drawn by any number of instances.

  • public void Release(in MeshShapeGeometry shape)

    Gives one shape's space back.

  • public int Flush(ICommandList commands)

    Records the copies every shape registered since the last flush needs.

  • public void Upload(ReadOnlySpan<MeshInstance> frame, ReadOnlySpan<MeshInstanceBatch> batches)

    Writes a frame's instances into the next region of the ring.

  • public void Record(ICommandList commands, in MeshInstanceView view)

    Draws what the last upload wrote.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Used by (3)

  • FixtureVixen.Rendering.Tests
  • MeshInstanceRendererTestsVixen.Rendering.Tests
  • ScenePresenterVixen.Editor.App