NGL  6.5
The NCCA Graphics Library
ngl::VertexArrayObject Class Reference

a class to encapsulate an OpenGL VAO More...

#include <VertexArrayObject.h>

+ Collaboration diagram for ngl::VertexArrayObject:

Public Member Functions

void bind ()
 bind this VOA to make it active More...
 
void unbind ()
 unbind the VOA and set 0 to be the active VOA More...
 
void removeVOA ()
 delete the VOA (using OpenGL calls to clear data etc) More...
 
GLuint getID () const
 accesor for the VOA id More...
 
bool isBound () const
 accesor to see if VOA is bound More...
 
bool isAllocated () const
 accesor to see if VOA has allocated data More...
 
void setData (size_t _size, const GLfloat &_data, GLenum _mode=GL_STATIC_DRAW)
 allocate our data using raw face values (for example tri's) data, attributes must be bound to match at a different level of code (usually in the client as part of the shader loading, see VAO examples for more details More...
 
void setIndexedData (size_t _size, const GLfloat &_data, unsigned int _indexSize, const GLvoid *_indexData, GLenum _indexType, GLenum _mode=GL_STATIC_DRAW)
 allocate our data using raw face values (for example tri's) data, attributes must be bound to match at a different level of code (usually in the client as part of the shader loading, see VAO examples for more details This value uses an index array to point to series of data to store More...
 
void setRawIndexedData (size_t _size, const GLvoid *_data, unsigned int _indexSize, const GLvoid *_indexData, GLenum _indexType, GLenum _mode=GL_STATIC_DRAW)
 allocate our data using raw face values (for example tri's) data, attributes must be bound to match at a different level of code (usually in the client as part of the shader loading, see VAO examples for more details This value uses an index array to point to series of data to store More...
 
void updateIndexedData (size_t _size, const GLfloat &_data, GLenum _mode=GL_STREAM_DRAW)
 allow to update the vertex data of the VBO when declared as dynamic (with GL_STREAM_DRAW) More...
 
void updateIndexedData (GLuint _vboidx, size_t _size, const GLfloat &_data, GLenum _mode=GL_STREAM_DRAW)
 
void updateData (unsigned int _size, const GLfloat &_data, GLenum _mode=GL_STREAM_DRAW)
 allow to update the vertex data of the VBO when declared as dynamic (with GL_STREAM_DRAW) More...
 
void updateData (GLuint _vboidx, unsigned int _size, const GLfloat &_data, GLenum _mode=GL_STREAM_DRAW)
 
void setVertexAttributePointer (GLuint _id, GLint _size, GLenum _type, GLsizei _stride, unsigned int _dataOffset, bool _normalise=GL_FALSE)
 set the generic vertex attribute pointer data More...
 
void setVertexAttributeIPointer (GLuint _id, GLint _size, GLenum _type, GLsizei _stride, unsigned int _dataOffset)
 set the vertex attribute pointer as an Integer this will not be normalised etc More...
 
GLuint getVBOid (unsigned int _index)
 get the VBO id for the data mapped at index _index basically this will be the vbo for the setData called, so if it has been called 3 times 0 would be first call 1, 2nd etc. More...
 
void draw () const
 draw the VOA More...
 
void draw (GLenum _mode) const
 draw the VOA More...
 
void draw (unsigned int _startIndex, unsigned int _numVerts, GLenum _mode=GL_TRIANGLES) const
 draw the VOA More...
 
void drawInstanced (GLenum _n) const
 draw the VOA _n times using instanced methods from GL (use transform feedback) More...
 
void setNumIndices (size_t _n)
 set the number of faces to draw More...
 
unsigned int getNumIndices () const
 get the number of indices in the vao More...
 
RealgetDataPointer (unsigned int _vbo, GLenum _accessMode=GL_READ_WRITE)
 grab a pointer to the first block of the data More...
 
void freeDataPointer ()
 unmap the data pointer More...
 
int getSize () const
 get the size in bytes of the VAO More...
 
 ~VertexArrayObject ()
 dtor doesn't do anything use the removeVAO method instead More...
 

Static Public Member Functions

static VertexArrayObjectcreateVOA (GLenum _mode)
 method to return a newVOA object More...
 

Protected Member Functions

 VertexArrayObject ()
 hide the ctor as we want to create static factory only More...
 
 VertexArrayObject (GLenum _mode)
 hide the ctor as we want to create static factory only More...
 
 VertexArrayObject (const VertexArrayObject &_v)
 hide the copy ctor as we want to create static factory only More...
 

Protected Attributes

GLenum m_drawMode
 the draw mode of the VAO e.g. GL_TRIANGLES More...
 
GLuint m_indicesCount
 the number of faces to draw More...
 
GLuint m_id
 the id of the VAO allocated by OpenGL More...
 
bool m_allocated
 flag to indicate if we have allocated the data to the VAO More...
 
bool m_indexed
 flag to indicate if we have an index or non index vao to draw More...
 
GLenum m_indexType
 Specifies the type of the values in the indices buffer. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT. More...
 
GLuint m_iboID
 the id of the index bufffer object More...
 
bool m_bound
 flag to indicate if we are bound More...
 
std::vector< GLuintm_vboIDs
 an array of VBO associated with this VAO More...
 

Detailed Description

a class to encapsulate an OpenGL VAO

Definition at line 50 of file VertexArrayObject.h.

Constructor & Destructor Documentation

ngl::VertexArrayObject::~VertexArrayObject ( )
inline

dtor doesn't do anything use the removeVAO method instead

Definition at line 223 of file VertexArrayObject.h.

ngl::VertexArrayObject::VertexArrayObject ( )
inlineprotected

hide the ctor as we want to create static factory only

Definition at line 266 of file VertexArrayObject.h.

ngl::VertexArrayObject::VertexArrayObject ( GLenum  _mode)
protected

hide the ctor as we want to create static factory only

Definition at line 27 of file VertexArrayObject.cpp.

References GL_UNSIGNED_BYTE, glGenVertexArrays, m_allocated, m_bound, m_drawMode, m_iboID, m_id, m_indexed, m_indexType, and m_indicesCount.

ngl::VertexArrayObject::VertexArrayObject ( const VertexArrayObject _v)
protected

hide the copy ctor as we want to create static factory only

Member Function Documentation

void ngl::VertexArrayObject::bind ( )

bind this VOA to make it active

Definition at line 41 of file VertexArrayObject.cpp.

References glBindVertexArray, m_bound, and m_id.

+ Here is the caller graph for this function:

static VertexArrayObject* ngl::VertexArrayObject::createVOA ( GLenum  _mode)
inlinestatic

method to return a newVOA object

Returns
a new VOA object

Definition at line 58 of file VertexArrayObject.h.

void ngl::VertexArrayObject::draw ( ) const

draw the VOA

Definition at line 269 of file VertexArrayObject.cpp.

References glDrawArrays(), glDrawElements(), m_allocated, m_bound, m_drawMode, m_indexed, m_indexType, and m_indicesCount.

+ Here is the call graph for this function:

void ngl::VertexArrayObject::draw ( GLenum  _mode) const

draw the VOA

Parameters
[in]_modethe mode to draw with

Definition at line 304 of file VertexArrayObject.cpp.

References glDrawArrays(), glDrawElements(), m_allocated, m_bound, m_indexed, m_indexType, and m_indicesCount.

+ Here is the call graph for this function:

void ngl::VertexArrayObject::draw ( unsigned int  _startIndex,
unsigned int  _numVerts,
GLenum  _mode = GL_TRIANGLES 
) const

draw the VOA

Parameters
[in]_startstart Index
[in]_numVertsthe number to draw
[in]_modethe mode to draw with

Definition at line 291 of file VertexArrayObject.cpp.

References glDrawArrays(), m_allocated, and m_bound.

+ Here is the call graph for this function:

void ngl::VertexArrayObject::drawInstanced ( GLenum  _n) const

draw the VOA _n times using instanced methods from GL (use transform feedback)

Parameters
[in]_nnumber of instances to draw

Definition at line 325 of file VertexArrayObject.cpp.

References glDrawArraysInstanced, glDrawElementsInstanced, m_allocated, m_bound, m_drawMode, m_indexed, m_indexType, and m_indicesCount.

void ngl::VertexArrayObject::freeDataPointer ( )

unmap the data pointer

Definition at line 366 of file VertexArrayObject.cpp.

References GL_ARRAY_BUFFER, and glUnmapBuffer.

Real * ngl::VertexArrayObject::getDataPointer ( unsigned int  _vbo,
GLenum  _accessMode = GL_READ_WRITE 
)

grab a pointer to the first block of the data

Parameters
[in]_vbothe vbo number of the block you wish to grab the data for
[in]_accessModethe mode to access the data, this is default to GL_READ_WRITE but we could change this to GL_READ to make access quicker for just reading the values or GL_WRITE for just writing values etc.
Returns
a pointer to the data

Definition at line 348 of file VertexArrayObject.cpp.

References bind(), GL_ARRAY_BUFFER, glBindBuffer, glMapBuffer, and m_vboIDs.

+ Here is the call graph for this function:

GLuint ngl::VertexArrayObject::getID ( ) const
inline

accesor for the VOA id

returns the VOA id

Definition at line 78 of file VertexArrayObject.h.

unsigned int ngl::VertexArrayObject::getNumIndices ( ) const
inline

get the number of indices in the vao

Returns
the nunmber of indices

Definition at line 198 of file VertexArrayObject.h.

References GL_READ_WRITE.

int ngl::VertexArrayObject::getSize ( ) const

get the size in bytes of the VAO

Definition at line 371 of file VertexArrayObject.cpp.

References GL_ARRAY_BUFFER, GL_BUFFER_SIZE, glGetBufferParameteriv, and m_bound.

GLuint ngl::VertexArrayObject::getVBOid ( unsigned int  _index)

get the VBO id for the data mapped at index _index basically this will be the vbo for the setData called, so if it has been called 3 times 0 would be first call 1, 2nd etc.

Parameters
[in]_indexthe index to get the id for
Returns
0 if not found else the vbo id

_index >=0 && picked up by g++4.3 so removed from below

Definition at line 231 of file VertexArrayObject.cpp.

References m_vboIDs.

+ Here is the caller graph for this function:

bool ngl::VertexArrayObject::isAllocated ( ) const
inline

accesor to see if VOA has allocated data

returns the allocated state (true for allocated)

Definition at line 88 of file VertexArrayObject.h.

References GL_FALSE, GL_STATIC_DRAW, GL_STREAM_DRAW, and GL_TRIANGLES.

bool ngl::VertexArrayObject::isBound ( ) const
inline

accesor to see if VOA is bound

returns the bind state (true for bound)

Definition at line 83 of file VertexArrayObject.h.

void ngl::VertexArrayObject::removeVOA ( )

delete the VOA (using OpenGL calls to clear data etc)

Definition at line 53 of file VertexArrayObject.cpp.

References glDeleteBuffers, glDeleteVertexArrays, m_allocated, m_bound, m_id, m_vboIDs, and unbind().

+ Here is the call graph for this function:

void ngl::VertexArrayObject::setData ( size_t  _size,
const GLfloat _data,
GLenum  _mode = GL_STATIC_DRAW 
)

allocate our data using raw face values (for example tri's) data, attributes must be bound to match at a different level of code (usually in the client as part of the shader loading, see VAO examples for more details

Parameters
_sizethe size of the raw data passed (this will be *sizeof(Real) to convert (this could cause potential bugs!)
_datathe actual data to set for the VOA
_modethe draw mode hint used by GL

Definition at line 70 of file VertexArrayObject.cpp.

References GL_ARRAY_BUFFER, glBindBuffer, glBufferData, glGenBuffers, m_allocated, m_bound, and m_vboIDs.

void ngl::VertexArrayObject::setIndexedData ( size_t  _size,
const GLfloat _data,
unsigned int  _indexSize,
const GLvoid _indexData,
GLenum  _indexType,
GLenum  _mode = GL_STATIC_DRAW 
)

allocate our data using raw face values (for example tri's) data, attributes must be bound to match at a different level of code (usually in the client as part of the shader loading, see VAO examples for more details This value uses an index array to point to series of data to store

Parameters
_sizethe size of the raw data passed
_datathe actual data to set for the VOA
_indexSizethe size of the index array passed
_indexDatathe actual data to set for the VOA indexes (only GLubyte data at present need to write more methods but usually only use this
_indexTypethe type of the values in the indices buffer. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT.
_modethe draw mode hint used by GL

Definition at line 87 of file VertexArrayObject.cpp.

References GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, GL_UNSIGNED_SHORT, glBindBuffer, glBufferData, glGenBuffers, m_allocated, m_bound, m_iboID, m_indexed, m_indexType, and m_vboIDs.

void ngl::VertexArrayObject::setNumIndices ( size_t  _n)
inline

set the number of faces to draw

Parameters
_nthe number of indices to draw in glDrawArray (param 3 count)

Definition at line 193 of file VertexArrayObject.h.

void ngl::VertexArrayObject::setRawIndexedData ( size_t  _size,
const GLvoid _data,
unsigned int  _indexSize,
const GLvoid _indexData,
GLenum  _indexType,
GLenum  _mode = GL_STATIC_DRAW 
)

allocate our data using raw face values (for example tri's) data, attributes must be bound to match at a different level of code (usually in the client as part of the shader loading, see VAO examples for more details This value uses an index array to point to series of data to store

Parameters
_sizethe size of the raw data passed
_datathe actual data to set for the VOA
_indexSizethe size of the index array passed
_indexDatathe actual data to set for the VOA indexes (only GLubyte data at present need to write more methods but usually only use this
_indexTypethe type of the values in the indices buffer. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT.
_modethe draw mode hint used by GL

Definition at line 126 of file VertexArrayObject.cpp.

References GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, GL_UNSIGNED_SHORT, glBindBuffer, glBufferData, glGenBuffers, m_allocated, m_bound, m_iboID, m_indexed, m_indexType, and m_vboIDs.

void ngl::VertexArrayObject::setVertexAttributeIPointer ( GLuint  _id,
GLint  _size,
GLenum  _type,
GLsizei  _stride,
unsigned int  _dataOffset 
)

set the vertex attribute pointer as an Integer this will not be normalised etc

Parameters
_sizethe size of the raw data passed (not counting sizeof(GL_FLOAT))
_typethe data type of the Pointer (eg GL_FLOAT)
_stridethe step between data values (need *sizeof _type) e.g. 10*sizeof(GLfloat)
_dataOffsetSpecifies a pointer to the first component of the first generic vertex attribute in the array. The initial value is 0. and is calculated as ((float *)NULL + (_dataOffset))

Definition at line 255 of file VertexArrayObject.cpp.

References glEnableVertexAttribArray, glVertexAttribIPointer, and m_bound.

void ngl::VertexArrayObject::setVertexAttributePointer ( GLuint  _id,
GLint  _size,
GLenum  _type,
GLsizei  _stride,
unsigned int  _dataOffset,
bool  _normalise = GL_FALSE 
)

set the generic vertex attribute pointer data

Parameters
_sizethe size of the raw data passed (not counting sizeof(GL_FLOAT))
_typethe data type of the Pointer (eg GL_FLOAT)
_stridethe step between data values (need *sizeof _type) e.g. 10*sizeof(GLfloat)
_dataOffsetSpecifies a pointer to the first component of the first generic vertex attribute in the array. The initial value is 0. and is calculated as ((float *)NULL + (_dataOffset))
_normalisespecifies whether fixed-point data values should be normalized (GL_TRUE) or converted directly as fixed-point values (GL_FALSE) when they are accessed.

Definition at line 243 of file VertexArrayObject.cpp.

References glEnableVertexAttribArray, glVertexAttribPointer, and m_bound.

void ngl::VertexArrayObject::unbind ( )

unbind the VOA and set 0 to be the active VOA

Definition at line 47 of file VertexArrayObject.cpp.

References glBindVertexArray, and m_bound.

+ Here is the caller graph for this function:

void ngl::VertexArrayObject::updateData ( unsigned int  _size,
const GLfloat _data,
GLenum  _mode = GL_STREAM_DRAW 
)

allow to update the vertex data of the VBO when declared as dynamic (with GL_STREAM_DRAW)

Parameters
_sizethe size of the raw data passed
_datathe actual data to set for the VOA
_modethe draw mode hint used by GL (choose GL_STREAM_DRAW by default, recommended mode for dynamic VBO's)

Definition at line 199 of file VertexArrayObject.cpp.

References getVBOid(), GL_ARRAY_BUFFER, glBindBuffer, glBufferData, m_allocated, and m_bound.

+ Here is the call graph for this function:

void ngl::VertexArrayObject::updateData ( GLuint  _vboidx,
unsigned int  _size,
const GLfloat _data,
GLenum  _mode = GL_STREAM_DRAW 
)

Definition at line 215 of file VertexArrayObject.cpp.

References getVBOid(), GL_ARRAY_BUFFER, glBindBuffer, glBufferData, m_allocated, and m_bound.

+ Here is the call graph for this function:

void ngl::VertexArrayObject::updateIndexedData ( size_t  _size,
const GLfloat _data,
GLenum  _mode = GL_STREAM_DRAW 
)

allow to update the vertex data of the VBO when declared as dynamic (with GL_STREAM_DRAW)

Parameters
_sizethe size of the raw data passed
_datathe actual data to set for the VOA
_modethe draw mode hint used by GL (choose GL_STREAM_DRAW by default, recommended mode for dynamic VBO's)

Definition at line 167 of file VertexArrayObject.cpp.

References getVBOid(), GL_ARRAY_BUFFER, glBindBuffer, glBufferData, m_allocated, m_bound, and m_indexed.

+ Here is the call graph for this function:

void ngl::VertexArrayObject::updateIndexedData ( GLuint  _vboidx,
size_t  _size,
const GLfloat _data,
GLenum  _mode = GL_STREAM_DRAW 
)

Definition at line 183 of file VertexArrayObject.cpp.

References getVBOid(), GL_ARRAY_BUFFER, glBindBuffer, glBufferData, m_allocated, m_bound, and m_indexed.

+ Here is the call graph for this function:

Member Data Documentation

bool ngl::VertexArrayObject::m_allocated
protected

flag to indicate if we have allocated the data to the VAO

Definition at line 241 of file VertexArrayObject.h.

bool ngl::VertexArrayObject::m_bound
protected

flag to indicate if we are bound

Definition at line 258 of file VertexArrayObject.h.

GLenum ngl::VertexArrayObject::m_drawMode
protected

the draw mode of the VAO e.g. GL_TRIANGLES

Definition at line 229 of file VertexArrayObject.h.

GLuint ngl::VertexArrayObject::m_iboID
protected

the id of the index bufffer object

Definition at line 254 of file VertexArrayObject.h.

GLuint ngl::VertexArrayObject::m_id
protected

the id of the VAO allocated by OpenGL

Definition at line 237 of file VertexArrayObject.h.

bool ngl::VertexArrayObject::m_indexed
protected

flag to indicate if we have an index or non index vao to draw

Definition at line 245 of file VertexArrayObject.h.

GLenum ngl::VertexArrayObject::m_indexType
protected

Specifies the type of the values in the indices buffer. Must be one of GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT.

Definition at line 250 of file VertexArrayObject.h.

GLuint ngl::VertexArrayObject::m_indicesCount
protected

the number of faces to draw

Definition at line 233 of file VertexArrayObject.h.

std::vector<GLuint> ngl::VertexArrayObject::m_vboIDs
protected

an array of VBO associated with this VAO

Definition at line 262 of file VertexArrayObject.h.


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