Module OgamlGraphics.VertexArray.VertexSource

Vertex source

This module represents vertex sources, which are collections of vertices.

This module ensures that everything goes well. In particular, it verifies that all the vertices of a source are compatible (i.e. have the same initialized attributes).

An empty source can receive any vertex. The type of the source is then fixed by the first vertex added to it. Any vertex added to the source after the first one must have at least the same initialized attributes as the first vertex.

Note that the type of a source is reinitialized if the source is cleared.

exception Uninitialized_field of string
Raised if a vertex is missing some of the attributes required by the source.
exception Incompatible_sources
Raised when trying to concatenate incompatible sources.
type 'a t
Type of a vertex source
val empty : ?size:int -> unit -> 'a t
Empty vertex source. The source will be redimensionned as needed, but an initial size can be specified with size .
val add : 'a t -> 'a Vertex.t -> unit
Adds a vertex to a source. If the source is not empty, the vertex must have at least the same initialized fields as the first vertex put into the source.
val (<<) : 'a t -> 'a Vertex.t -> 'a t
Convenient operator to add vertices to a source.
val length : 'a t -> int
Returns the length (in vertices) of a source.
val clear : 'a t -> unit
Clears the source. Any source that has been converted into a vertex array can be safely cleared and reused. This avoids reallocation and garbage collection.
val append : 'a t -> 'a t -> unit
append s1 s2 appends the source s2 to s1 . s2 is not modified.
val iter : 'a t -> ('a Vertex.t -> unit) -> unit
Iterates through all the vertices of a source.
val map : 'a t -> ('a Vertex.t -> 'b Vertex.t) -> 'b t
Maps all the vertices of a source to a new source.
val map_to : 'a t -> ('a Vertex.t -> 'b Vertex.t) -> 'b t -> unit
Maps all the vertices of a source to an existing source.