| GL Studio C++ Runtime API

Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
GlsVertexArray Class Reference

`#include <gls_vertex_array.h>`

Inheritance diagram for GlsVertexArray:

## Public Member Functions
| GlsVertexArray ()
virtual | ~GlsVertexArray ()
void | Setup (const int nVerts, const bool hasT, const bool hasC, const bool hasN)
void | SetVertices (const Vertex verts[])
void | SetTexCoords (const Vector verts[])
void | SetNormals (const Vector verts[])
void | SetColors (const Vertex verts[])
void | SetVertex (const unsigned int index, const Vector &v)
void | SetTexCoord (const unsigned int index, const Vector &v)
void | Bake (IGlsStateManager *stateManager)
void | Draw (const unsigned int glPrimitive, IGlsStateManager *stateManager, const bool texture, const bool color, const bool normal)
void | Draw (const unsigned int glPrimitive, const unsigned int offset, const unsigned int count, GlsIndexArray &indexBuffer, IGlsStateManager *stateManager, const bool texture, const bool color, const bool normal)
void | MultiDraw (const unsigned int glPrimitive, const unsigned int offset, const unsigned int count, const unsigned int primitiveSize, GlsIndexArray &indexBuffer, IGlsStateManager *stateManager, const bool texture, const bool color, const bool normal)

## Static Public Attributes
static const GLuint | VERT_SIZE = sizeof( float ) * 3
| Size of a vertex in bytes.
static const GLuint | TEX_SIZE = sizeof( float ) * 2
| Size of a texture coordinate in bytes.
static const GLuint | NORMAL_SIZE = sizeof( float ) * 3
| Size of a normal in bytes.
static const GLuint | COLOR_SIZE = sizeof( unsigned char ) * 4
| Size of a color in bytes.

## Protected Member Functions
void | AllocateBuffer (const unsigned int size)
void | DeallocateBuffer ()

## Protected Attributes
unsigned char * | _vertexData
unsigned int | _vboHandle
unsigned int | _bufferSize
bool | _setup
bool | _hasT
bool | _hasN
bool | _hasC
unsigned int | _componentSize
unsigned int | _texOffset
unsigned int | _normalOffset
unsigned int | _colorOffset
unsigned int | _nVerts

## Detailed Description

The GlsVertexArray class. This holds a number of Vertex objects in a resizeable buffer.

## Constructor & Destructor Documentation

## ◆ GlsVertexArray()

GlsVertexArray | ( |  | ) |

Default constructor

## ◆ ~GlsVertexArray()

virtual ~GlsVertexArray | ( |  | ) |
| virtual

Destructor

## Member Function Documentation

## ◆ AllocateBuffer()

void AllocateBuffer | ( | const unsigned int | size | ) |
| protected

Allocates the buffer data, copying the existing data

Parameters

  size | The new size in bytes to allocate

## ◆ Bake()

void Bake | ( | IGlsStateManager * | stateManager | ) |

Bake the vertex buffer to a VBO

Precondition
  _setup == true

Parameters

  stateManager | State manager for the OpenGL context to bake the VBO in

## ◆ DeallocateBuffer()

void DeallocateBuffer | ( |  | ) |
| protected

Deallocates the buffer data

## ◆ Draw() [1/2]

void Draw | ( | const unsigned int | glPrimitive,
|  | const unsigned int | offset,
|  | const unsigned int | count,
|  | GlsIndexArray & | indexBuffer,
|  | IGlsStateManager * | stateManager,
|  | const bool | texture,
|  | const bool | color,
|  | const bool | normal
| ) |  |

Draw this vertex array

Precondition
  _setup == true

Postcondition
  The VBO is drawn

Parameters

  glPrimitive | The OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
  offset | Index of the first vertex to draw
  count | Number of primitives to draw
  indexBuffer | Index buffer to use
  stateManager | State manager for the OpenGL context to draw in
  texture | Whether or not to draw with texture
  color | Whether or not to use per vertex colors
  normal | Whether or not to use per vertex normals

## ◆ Draw() [2/2]

void Draw | ( | const unsigned int | glPrimitive,
|  | IGlsStateManager * | stateManager,
|  | const bool | texture,
|  | const bool | color,
|  | const bool | normal
| ) |  |

Draw this vertex array

Precondition
  _setup == true

Postcondition
  The VBO is drawn

Parameters

  glPrimitive | The OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
  stateManager | State manager for the OpenGL context to draw in
  texture | Whether or not to draw with texture
  color | Whether or not to use per vertex colors
  normal | Whether or not to use per vertex normals

## ◆ MultiDraw()

void MultiDraw | ( | const unsigned int | glPrimitive,
|  | const unsigned int | offset,
|  | const unsigned int | count,
|  | const unsigned int | primitiveSize,
|  | GlsIndexArray & | indexBuffer,
|  | IGlsStateManager * | stateManager,
|  | const bool | texture,
|  | const bool | color,
|  | const bool | normal
| ) |  |

Draw this vertex array

Precondition
  _setup == true

Postcondition
  The VBO is drawn

Parameters

  glPrimitive | The OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
  offset | Index of the first vertex to draw
  count | Number of primitives to draw
  primitiveSize | Number of vertices per primitive
  indexBuffer | Index buffer to use
  stateManager | State manager for the OpenGL context to draw in
  texture | Whether or not to draw with texture
  color | Whether or not to use per vertex colors
  normal | Whether or not to use per vertex normals

## ◆ SetColors()

void SetColors | ( | const Vertex | verts[] | ) |

Sets the Colors of the array. Note: This takes an array of Vertex for compatibility with DisplayObject. It gets the colors from the color component of the vertices.

Precondition
  (_setup && _hasC)

Parameters

  verts | An array of colors to populate this object with. verts[] must have at least _nVerts elements

## ◆ SetNormals()

void SetNormals | ( | const Vector | verts[] | ) |

Sets the Normals of the array

Precondition
  (_setup && _hasN)

Parameters

  verts | An array of normals to populate this object with. verts[] must have at least _nVerts elements

## ◆ SetTexCoord()

void SetTexCoord | ( | const unsigned int | index,
|  | const Vector & | v
| ) |  |

Sets a single texture coordinate

Precondition
  _setup && (index < _nVerts) && _hasT

Parameters

  index | The index of the texture coordinate to set
  v | The texture coordinate to set

## ◆ SetTexCoords()

void SetTexCoords | ( | const Vector | verts[] | ) |

Sets the texture coordinates of the array

Precondition
  (_setup && _hasT)

Parameters

  verts | An array of texture coords to populate this object with. verts[] must have at least _nVerts elements

## ◆ Setup()

void Setup | ( | const int | nVerts,
|  | const bool | hasT,
|  | const bool | hasC,
|  | const bool | hasN
| ) |  |

Prepare the vertex buffer to be populated. Allocates vertex buffer, sets up component offsets.

Parameters

  nVerts | Number of vertices in the array
  hasT | True if array has texture coords
  hasC | True if array has colors
  hasN | True if array has normas

## ◆ SetVertex()

void SetVertex | ( | const unsigned int | index,
|  | const Vector & | v
| ) |  |

Sets a single vertex

Precondition
  _setup && (index < _nVerts)

Parameters

  index | The index of the vertex to set
  v | The vertex to set

## ◆ SetVertices()

void SetVertices | ( | const Vertex | verts[] | ) |

Sets the vertices of the array

Precondition
  _setup == true

Parameters

  verts | An array of vertices to populate this object with. verts[] must have at least _nVerts elements

## Member Data Documentation

## ◆ _bufferSize

unsigned int _bufferSize
| protected

Size of data pointed to by _vertexData

## ◆ _colorOffset

unsigned int _colorOffset
| protected

Offset of the color from the beginning of a component, in bytes

## ◆ _componentSize

unsigned int _componentSize
| protected

Size of one element of this array (total size of all components) in bytes

## ◆ _hasC

bool _hasC
| protected

True if this object has colors

## ◆ _hasN

bool _hasN
| protected

True if this object has normals

## ◆ _hasT

bool _hasT
| protected

True if this object has texture coordinates

## ◆ _normalOffset

unsigned int _normalOffset
| protected

Offset of the normals from the beginning of a component, in bytes

## ◆ _nVerts

unsigned int _nVerts
| protected

Number of vertices in this object

## ◆ _setup

bool _setup
| protected

True if this object has been setup and can be downloaded to a VBO

## ◆ _texOffset

unsigned int _texOffset
| protected

Offset of the texture coords from the beginning of a component, in bytes

## ◆ _vboHandle

unsigned int _vboHandle
| protected

OpenGL VBO handle

## ◆ _vertexData

unsigned char* _vertexData
| protected

Contains the dynamically allocated, interleaved vertex data that gets sent to the VBO

The documentation for this class was generated from the following file:

- gls_vertex_array.h