GL Studio C++ Runtime API
GlsVertexArray Class Reference

#include <gls_vertex_array.h>

Inheritance diagram for GlsVertexArray:
NonCopyable

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( GL_FLOAT ) * 3
 Size of a vertex in bytes.
 
static const GLuint TEX_SIZE = sizeof( GL_FLOAT ) * 2
 Size of a texture coordinate in bytes.
 
static const GLuint NORMAL_SIZE = sizeof( GL_FLOAT ) * 3
 Size of a normal in bytes.
 
static const GLuint COLOR_SIZE = sizeof( GL_UNSIGNED_BYTE ) * 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()

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
sizeThe new size in bytes to allocate

◆ Bake()

void Bake ( IGlsStateManager stateManager)

Bake the vertex buffer to a VBO

Precondition
_setup == true
Parameters
stateManagerState 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
glPrimitiveThe OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
offsetIndex of the first vertex to draw
countNumber of primitives to draw
indexBufferIndex buffer to use
stateManagerState manager for the OpenGL context to draw in
textureWhether or not to draw with texture
colorWhether or not to use per vertex colors
normalWhether 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
glPrimitiveThe OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
stateManagerState manager for the OpenGL context to draw in
textureWhether or not to draw with texture
colorWhether or not to use per vertex colors
normalWhether 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
glPrimitiveThe OpenGL primitive type to draw (e.g. GL_LINE_LOOP)
offsetIndex of the first vertex to draw
countNumber of primitives to draw
primitiveSizeNumber of vertices per primitive
indexBufferIndex buffer to use
stateManagerState manager for the OpenGL context to draw in
textureWhether or not to draw with texture
colorWhether or not to use per vertex colors
normalWhether 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
vertsAn 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
vertsAn 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
indexThe index of the texture coordinate to set
vThe texture coordinate to set

◆ SetTexCoords()

void SetTexCoords ( const Vector  verts[])

Sets the texture coordinates of the array

Precondition
(_setup && _hasT)
Parameters
vertsAn 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
nVertsNumber of vertices in the array
hasTTrue if array has texture coords
hasCTrue if array has colors
hasNTrue if array has normas

◆ SetVertex()

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

Sets a single vertex

Precondition
_setup && (index < _nVerts)
Parameters
indexThe index of the vertex to set
vThe vertex to set

◆ SetVertices()

void SetVertices ( const Vertex  verts[])

Sets the vertices of the array

Precondition
_setup == true
Parameters
vertsAn 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: