Table of Contents

Class MeshDataPool

Namespace
Vintagestory.API.Client
Assembly
VintagestoryAPI.dll

A model data pool: one large buffer on the GPU that chunk meshes are packed into It holds up to 400k vertices and 300k indices but never more than 900 chunks Open in GitHub

public class MeshDataPool
Inheritance
MeshDataPool
Inherited Members
Extension Methods

Fields

AllocatedTris

How many triangles are allocated

public int AllocatedTris

Field Value

int

CurrentFragmentation

Current buffer fragmentation (share of holes)

public float CurrentFragmentation

Field Value

float

IndicesPoolSize

Size of the pool index buffer

public int IndicesPoolSize

Field Value

int

MaxPartsPerPool

Maximum number of parts (meshes) in this pool

public int MaxPartsPerPool

Field Value

int

RenderedTriangles

How many triangles were drawn

public int RenderedTriangles

Field Value

int

UsedVertices

How many vertices are actually used

public int UsedVertices

Field Value

int

VerticesPoolSize

Size of the pool vertex buffer

public int VerticesPoolSize

Field Value

int

indicesGroupsCount

How many index groups there are (how many draw calls to make)

public int indicesGroupsCount

Field Value

int

indicesPosition

Position in the index buffer

public int indicesPosition

Field Value

int

indicesSizes

Size of each index group

public required int[] indicesSizes

Field Value

int[]

indicesStartsByte

Start byte of each index group

public required int[] indicesStartsByte

Field Value

int[]

verticesPosition

Position in the vertex buffer

public int verticesPosition

Field Value

int

Methods

AllocateNewPool(ICoreClientAPI, int, int, int, CustomMeshDataPartFloat?, CustomMeshDataPartShort?, CustomMeshDataPartByte?, CustomMeshDataPartInt?)

Creates a new pool for mesh data

public static MeshDataPool AllocateNewPool(ICoreClientAPI capi, int verticesPoolSize, int indicesPoolSize, int maxPartsPerPool, CustomMeshDataPartFloat? customFloats = null, CustomMeshDataPartShort? customShorts = null, CustomMeshDataPartByte? customBytes = null, CustomMeshDataPartInt? customInts = null)

Parameters

capi ICoreClientAPI

The core client API

verticesPoolSize int

The vertices pool size.

indicesPoolSize int

The indices pool size.

maxPartsPerPool int

The maximum parts per pool.

customFloats CustomMeshDataPartFloat

The custom floats of the pool.

customShorts CustomMeshDataPartShort

The custom shorts of the pool.

customBytes CustomMeshDataPartByte

The custom bytes of the pool.

customInts CustomMeshDataPartInt

The custom ints of the pool.

Returns

MeshDataPool

The resulting mesh data pool.

CalcFragmentation()

Computes fragmentation: the share of the used vertex buffer taken up by holes between meshes The more holes there are, the more worthwhile it is to insert new meshes into the gaps

public void CalcFragmentation()

Dispose(ICoreClientAPI)

Releases the pool buffers on the GPU

public void Dispose(ICoreClientAPI capi)

Parameters

capi ICoreClientAPI

Draw(ICoreClientAPI, FrustumCulling, EnumFrustumCullMode)

Draws the pool: first picks the visible parts, then sends them in one call

public void Draw(ICoreClientAPI capi, FrustumCulling frustumCuller, EnumFrustumCullMode frustumCullMode)

Parameters

capi ICoreClientAPI

The core client API

frustumCuller FrustumCulling

The area where models can be viewed from the camera.

frustumCullMode EnumFrustumCullMode

The mode of the culling.

FrustumCull(FrustumCulling?, EnumFrustumCullMode)

Finds the visible parts and fills the arrays for MultiDrawElements The rules themselves are implemented in PoolCullData and set by FrustumCulling

public void FrustumCull(FrustumCulling? frustumCuller, EnumFrustumCullMode frustumCullMode)

Parameters

frustumCuller FrustumCulling
frustumCullMode EnumFrustumCullMode

GetFragmentation()

Current pool fragmentation

public float GetFragmentation()

Returns

float

IsEmpty()

Is the pool empty

public bool IsEmpty()

Returns

bool

RemoveLocation(ModelDataPoolLocation)

Removes a mesh from the pool Throws when it cannot be removed (wrong pool or no such mesh in this pool)

public void RemoveLocation(ModelDataPoolLocation location)

Parameters

location ModelDataPoolLocation

RenderMesh(IRenderAPI)

Sends only the parts found by the previous FrustumCull to the GPU

public void RenderMesh(IRenderAPI render)

Parameters

render IRenderAPI

SetFullyVisible()

Draws every part that is not hidden without frustum culling Used for mini dimension pools Everything goes through Cull so Hide, the group layout and the triangle stats share one place

public void SetFullyVisible()

TryAdd(ICoreClientAPI, MeshData, Vec3i, int, Sphere)

Tries to add a new mesh to the pool. Returns null when there is no room or when the mesh is from another dimension.

public ModelDataPoolLocation? TryAdd(ICoreClientAPI capi, MeshData modeldata, Vec3i modelOrigin, int dimension, Sphere frustumCullSphere)

Parameters

capi ICoreClientAPI

The core client API

modeldata MeshData

The model to add

modelOrigin Vec3i

The origin point of the model.

dimension int

The dimension this model appears in.

frustumCullSphere Sphere

The culling sphere.

Returns

ModelDataPoolLocation

The location of the model (and the data) in the pool.