Public Member Functions | Protected Member Functions | Friends

VertexArray Class Reference

#include <VertexArray.h>

Inheritance diagram for VertexArray:
Resource

List of all members.

Public Member Functions

void setAttribute (const char *name, u32 offset, u32 length, AttributeType_t type, bool normalize_int=false)
void setIndexArray (void *new_array, u32 type_size, u32 n)
void setArray (void *new_array, u32 n)
u32 getLength ()
u32 getStride ()
u32 getAttributeCount ()
Attribute_tgetAttribute (u32 i)
Attribute_tgetAttribute (char *name)
PrimitiveLayout_t getPrimitiveLayout ()
u32 getIndexTypeSize ()
u32 getIndexLength ()
AttributeUsage_t getUsage ()
AttributeUsage_t getIndexUsage ()
void * getHandle ()
void setHandle (void *nhandle)

Protected Member Functions

AABox getBoundingBox ()

Friends

class SceneGraph
class Geometry

Detailed Description

Vertex array. Inherits from Resource.

This is an array of vertices that is used in conjunction with an index array. The index array points to vertex attributes from this array, and these will be used to construct triangles with accompanying data.

A vertex array should at least contain an attribute that specifies the position of a vertex. Other common properties are normals, color and texture coordinates.

The vertex array is organized in a array of structs-manner, as opposed to a struct of arrays. The difference is illustrated below with a vertex array containing position, normal and color data.

 *                       Vertex attributes
 *
 *   Struct of arrays (not used)       Array of structs
 *   (SOA)                             (AOS)
 *
 *    Vertex[0] Position.x              Vertex[0] Position.x       ^
 *    Vertex[0] Position.y              Vertex[0] Position.y       | S
 *    Vertex[0] Position.z              Vertex[0] Position.z       | t
 *    Vertex[1] Position.x              Vertex[0] Normal.x         | r
 *    Vertex[1] Position.y              Vertex[0] Normal.y         | i
 *    Vertex[1] Position.z              Vertex[0] Normal.z         | d
 *     ...                              Vertex[0] Color.r          | e
 *    Vertex[0] Normal.x                Vertex[0] Color.g          |
 *    Vertex[0] Normal.y                Vertex[0] Color.b          |
 *    Vertex[0] Normal.z                Vertex[0] Color.a          v
 *    Vertex[1] Normal.x                Vertex[1] Position.x
 *    Vertex[1] Normal.y				Vertex[1] Position.y
 *    Vertex[1] Normal.z				Vertex[1] Position.z
 *     ...								Vertex[1] Normal.x
 *     ...								Vertex[1] Normal.y
 *    Vertex[0] Color.r					Vertex[1] Normal.z
 *    Vertex[0] Color.g					Vertex[1] Color.r
 *    Vertex[0] Color.b					Vertex[1] Color.g
 *    Vertex[0] Color.a					Vertex[1] Color.b
 *    Vertex[1] Color.r					Vertex[1] Color.a
 *    Vertex[1] Color.g                  ...
 *    Vertex[1] Color.b
 *    Vertex[1] Color.a
 *     ...
 *
 * 

In this example, for the AOS the stride = 10 * size(f32), since the data type repeats after every 10 entries and (in this example) we assume that each struct member is a 32-bit float.

The offset for the "Normal" attribute in this example is 3, since it's three entries in from the beginning of the array. It's length is 3, since it has three components (x, y, z).


Member Function Documentation

void VertexArray::setAttribute ( const char *  name,
u32  offset,
u32  length,
AttributeType_t  type,
bool  normalize_int = false 
)
Parameters:
nameName of the attribute. This must comply with the vertex attribute names expected further down in the rendering pipeline (as defined by the renderer and shader program.)
offsetOffset, in bytes, to the first entry in the struct/array.
lengthNumber of components in this attribute. This is _NOT_ given in bytes, as the type-argument multiplied with the length reveals the total byte length.
normalize_intThis is only valid for int#-variants. If this is true values will be scaled to the interval [0, 1] in the renderer, otherwise no scaling will occur.
void VertexArray::setIndexArray ( void *  new_array,
u32  type_size,
u32  n 
)
Parameters:
nThe number of indices in the index array. (_NOT_ the number of triangles you expect to be created). The layout argument specified in the constructor will be used by this index array. It's indices point to entries in the attached vertex attribute array. It's safe to delete the incoming index array after calling this function.

The documentation for this class was generated from the following files:
 All Classes Functions