Provides the shared buffer for terrain meshes.
Using a mesh buffer involves the following steps:
Create a MeshBuffer object by calling Create. A container for per-vertex CPU data must be given (see VertexArrays). Optionally, updater objects for vertex data or mesh structure data may be specified; these are usually used to populate GPU buffers, for GPU-based rendering and triangulation.
Create terrain meshes by calling MeshCreate. All terrain meshes will use vertices that are stored in the shared mesh buffer.
The mesh buffer has a background refinement thread which periodically traverses all terrain meshes, updates the tessellation and triggers background computation of vertex data. This happens automatically and is not visible to the application.
The mesh buffer is supposed to be accessed by a single dedicated thread in the application (usually the render thread). A separate snapshot of the terrain mesh tessellation is maintained for consistent access by the application thread.
The MeshUpdate and MeshUpdateData will update the terrain snapshot according to the current state of background refinement. This is a write-only access. Subsequently, the application will read from the terrain snapshot (for example, while traversing the MeshTree).
If an application needs to read from the terrain snapshot from another thread than the dedicated one, then the IBeginEnd.Begin and IBeginEnd.End methods must be used to wrap each read access. This will ensure that all accesses are properly synchronized: write-accesses and read-accesses are mutually exclusive, while read-accesses will be performed in parallel.
The following API will read from the terrain snapshot:
Builds a color-coded image that represents the fragmentation of the shared vertex buffer.
Both width and height of the image are powers of two (but not necessarily the same). Each pixel in the image represent the status of a specific vertex in the shared vertex buffer:
index(x,y) := y * width + x color(x,y) := status
height are the dimensions of the image,
y are pixel coordinates,
index is the mapping from pixel coordinates to zero-based vertex indices and
status if the color-coded vertex status:
The vertex is not used by any terrain mesh.
Dark rainbow color
The vertex is used by a terrain mesh and currently invisible.
Bright rainbow color
The vertex is used by a terrain mesh and currently visible.
The vertex belongs to the skeleton of a terrain mesh.
The hue of the rainbow colors indicates the level of the respective vertex in the mesh structure (i.e, the number of parent vertices, up to the root sector; see XDag).
Creates a new dynamic terrain mesh.
If the given options in are invalid.
The MeshUpdateData method must be called before vertex data is used (e.g. rendering using the GPU vertex buffer). This ensures that the mesh structure is consistent with the vertex data that has been sent to the IVertexUpdater object.
Performs all vertex data and mesh structure updates that have been left out during the last call to MeshUpdate.
This method can be called multiple times, data updates will only be performed once.
Re-initializes the mesh buffer and all meshes.
This method can be called after MeshUpdate has returned a negative value, in order to recover from an error that has occurred earlier.
Allow the refinement thread to sleep for a short period of time when little or no refinement work is necessary?
The default value is
Returns the number of vertices that are not used by any mesh, neither as visible nor invisible vertex.
- See also
Returns the number of visible vertices in all meshes.