Module OgamlGraphics.VertexArray

High-level wrapper around OpenGL vertex arrays

Submodules

VertexSource Vertex source
SimpleVertex Simple pre-initialized structure
Vertex Creation and manipulation of vertices

This modules provides a high-level and safe access to openGL vertex arrays. Vertex arrays are used to store vertices on the GPU and can be used to render 3D models.

The idea behind this module is to provide a safe way to create vertex arrays in 3 steps:

- First, you will need to create a vertex structure. This is done using the function Vertex.make. You can add attributes to your structure V by calling V.attribute and giving them a name and type.
The attributes will be passed to GLSL programs under the provided name. Once you have added some attributes to your structure, you need to seal it using V.seal.
Be careful as once a structure is sealed, you cannot add attributes to it anymore. You can then create vertices that will contain the attributes of your structure using V.create.
Alternatively, you can use the module SimpleVertex which is a predefined vertex structure containing a position, texture coordinates, a color, and a normal.

- Secondly, you will need to create a source which contains vertices. This is done using VertexSource.empty. The module VertexSource provides several useful functions to manipulate sources of vertices.

- Finally, you can create a vertex array using one of the two functions static or dynamic .

exception Missing_attribute of string
Raised when trying to draw with a program that requires an attribute not provided by the vertex array.
exception Invalid_attribute of string
Raised when trying to draw with a program that requires an attribute of a different type than the one provided by the vertex array.
exception Out_of_bounds of string
Raised when trying to draw an invalid slice of a vertex array.
type static
Phantom type for static arrays
type dynamic
Phantom type for dynamic arrays
type ('a,'b) t
Type of a vertex array (static or dynamic)
val static : (module RenderTarget.T with type t = 'a) -> 'a -> 'b VertexSource.t -> (static, 'b) t
Creates a static array from a source. A static array is faster but cannot be modified later.
See : OgamlGraphics.VertexArray.Source
val dynamic : (module RenderTarget.T with type t = 'a) -> 'a -> 'b VertexSource.t -> (dynamic, 'b) t
Creates a dynamic vertex array that can be modified later.
See : OgamlGraphics.VertexArray.Source
val rebuild : (dynamic, 'b) t -> 'b VertexSource.t -> int -> unit
rebuild array src offset rebuilds array starting from the vertex at position offset using src .
The vertex array is modified in-place and is resized as needed.
See : OgamlGraphics.VertexArray.Source
val length : ('a, 'b) t -> int
Returns the length of a vertex array
val draw : (module RenderTarget.T with type t = 'a) -> vertices:('b, 'c) t -> target:'a -> ?indices:'d IndexArray.t -> program:Program.t -> ?uniform:Uniform.t -> ?parameters:DrawParameter.t -> ?start:int -> ?length:int -> ?mode:DrawMode.t -> unit -> unit
Draws the slice starting at start of length length of a vertex array on a window using the given parameters.
start defaults to 0
if length is not provided, then the whole vertex array (starting from start ) is drawn
uniform should provide the uniforms required by program (defaults to empty)
parameters defaults to DrawParameter.make ()
mode defaults to DrawMode.Triangles

See : OgamlGraphics.IndexArray
See : OgamlGraphics.Window
See : OgamlGraphics.Program
See : OgamlGraphics.Uniform
See : OgamlGraphics.DrawParameter
See : OgamlGraphics.DrawMode