VertexArray

A wrapper around GL Vertex Attribute Object that also manages its vertex storage.

Acts as a dynamic array of vertex type V.

V must be a plain-old-data struct where each member is either a gl3n Vector (such as vec3) or a scalar number (such as float).

Example vertex type:

1 struct Vertex
2 {
3     vec3 position;
4     vec3 normal;
5     Vector!(ubyte, 4) rgbaColor;
6 }

Vertex attributes must be either one of the following types: float, double, byte, short, int, ubyte, ushort, uint or a 4 or less dimensional gl3n.linalg.Vector with type parameter set to one of listed types. Note that by default, attributes with integral values will have those values normalized into the [0-1] range (for example, a color channel with value of 255 will be normalized into 1.0). In future, an UDA (TODO) will be added to allow the user to disable normalization of integers.

The VertexArray requires a shader program when being bound and looks for vertex attributes with names corresponding to fields of V. Any shader program used to draw a VertexArray must contain vertex attributes for all members of V (otherwise VertexArray binding will fail).

For example, the following vertex shader source has all members specified by the Vertex struct in the above example:

1 #version 130
2 
3 in vec3 position;
4 in vec3 normal;
5 in vec4 rgbaColor;
6 
7 void main()
8 {
9     // ... do stuff here ...
10 }

Constructors

this
this(OpenGL gl, V[] storage)

Construct a VertexArray.

Destructor

~this
~this()

Destroy the VertexArray.

Members

Enums

State
enum State

Possible states a VertexArray can be in.

Functions

bind
bool bind(GLProgram program)

Bind the VertexArray for drawing. Must be called before drawing. VertexArray must be locked.

capacity
size_t capacity()

Get the maximum number of vertices the VertexArray can hold.

clear
void clear()

Clear the VertexArray, deleting all vertices.

data
V[] data()

Get direct access to vertices in the VertexArray.

draw
void draw(PrimitiveType type, size_t first, size_t count)

Draw vertices from the VertexArray directly, without using indices.

empty
bool empty()

Is the VertexArray empty (no vertices) ?

length
size_t length()

Get the current number of vertices in the VertexArray.

length
void length(size_t rhs)

Manually set the length of the VertexArray.

lock
void lock()

Lock the buffer.

put
void put(const V vertex)

Add a vertex to the VertexArray.

release
void release()

Release the buffer after drawing.

unlock
void unlock()

Unlock the buffer.

Meta