MeshBuffer
Description
- Derived from
-
Disposable abstract
ICapacity
IMemoryConsumption
IBeginEnd
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:
Public / Constructors
Create
Creates a new instance of MeshBuffer.
If necessary, the following vertex data arrays will be created:
- TinmanException
-
If vertexUpdater opt is not
null
and vertexData in is missing some required data arrays.
Public / Methods
BuildFragmentationImage
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
where width
and height
are the dimensions of the image, x
and y
are pixel coordinates, index
is the mapping from pixel coordinates to zero-based vertex indices and status
if the color-coded vertex status:
-
Black
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. -
White
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).
MeshCreate
Creates a new dynamic terrain mesh.
- ValidatingException
-
If the given options in are invalid.
- GeorefException
-
If MeshOptions.Geometry is
null
and the given geo-reference is not suitable.
MeshUpdate
Applies all buffered mesh updates, but does not update vertex data via IVertexUpdater or mesh data via IMeshStructureUpdater.
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.
The call to MeshUpdateData may be omitted iff the vertex data is not used. Calling the MeshUpdateData more than once is allowed, but has no effect.
MeshUpdateData
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.
Reinitialize
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.
Public / Attributes
AllowSleep
Allow the refinement thread to sleep for a short period of time when little or no refinement work is necessary?
The default value is true
.
CountUnused
Returns the number of vertices that are not used by any mesh, neither as visible nor invisible vertex.
- See also