Skip to content

Management & Rendering

The Vergeo2D.Management namespace provides pooled ownership for many meshes.

using Vergeo2D.Management;
var manager = new MeshManager2D();
var handle = manager.Add(mesh, deformer: new VertexOffsetDeformer2D());

MeshHandle is generation-checked. If a slot is removed and reused, stale handles are detected as invalid instead of silently pointing at a new mesh.

Call PrepareFrame() once per frame before reading render data.

manager.PrepareFrame(parallel: true);
foreach (var batch in manager.GetBatches())
{
foreach (var meshHandle in batch.Handles)
{
if (!manager.TryGetRenderData(meshHandle, out var renderData))
continue;
// Upload renderData.Vertices and renderData.Indices.
}
}

Only dirty meshes are extracted. A mesh is considered dirty when:

  • Mesh2D.Version changes.
  • Its geometry hash changes.
  • A deformer is attached.
  • MarkDirty() is called.
  • SetDeformer() changes the assigned deformer.

GetBatches() groups alive handles by shared Texture2D.

foreach (var batch in manager.GetBatches())
{
var texture = batch.Texture;
foreach (var meshHandle in batch.Handles)
{
// Draw every mesh using this texture.
}
}

This lets a renderer issue one draw path per texture instead of one texture bind per mesh.

The Vergeo2D.Rendering namespace converts meshes into GPU-friendly data.

Type Purpose
MeshRenderExtractor Writes a mesh into MeshRenderData2D, optionally applying a deformer into a scratch buffer.
MeshRenderData2D Growable vertex and index buffers with dirty flags.
MeshRenderData2DExtensions Helpers such as expanding indexed triangles.
MeshViewportLayout2D Viewport fitting and screen/content coordinate conversion.
RenderTransform2D Position, rotation, scale, and Matrix3x2 conversion.

MeshRenderData2D is just interleaved vertex data (x, y, u, v) plus triangle indices. You can upload those spans into your own renderer, including Veldrid, and refresh only the buffers whose dirty flags changed.

IMeshRenderBackend2D is the backend contract. The core library stays engine-agnostic; backend implementations are opt-in.

Backend NuGet package Define constant
OpenGLMeshRenderBackend2D Silk.NET.OpenGL VERGEO_OPENGL
Direct3D11MeshRenderBackend2D Vortice.Direct3D11 VERGEO_DIRECTX
VulkanMeshRenderBackend2D Silk.NET.Vulkan VERGEO_VULKAN

Enable a backend by adding its package and compilation symbol:

<PropertyGroup>
<DefineConstants>$(DefineConstants);VERGEO_OPENGL</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Silk.NET.OpenGL" Version="x.x.x" />
</ItemGroup>