VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Member Functions | List of all members

Mesh composed of vertices, and attributes for each vertex. More...

Public Member Functions

 Mesh (int vertexCount, const AttributeSetPtr &attributes)
 Construct a mesh with the given vertex attributes and vertex count. More...
 
int getVertexCount () const
 Returns the length of the current vertex buffer, in number of vertices. More...
 
void bind ()
 Bind this vertex buffer, uploading it if necessary. More...
 
void unbind ()
 Unbinds this vertex buffer. More...
 
void upload ()
 Uploads the current vertex buffer's data into a GL buffer object. More...
 
void dispose ()
 Frees this Mesh's managed buffer, and GL buffer object, if allocated. More...
 
bool isUploaded () const
 Returns whether or not an associated GL buffer object exists and contains uploaded data. More...
 
const AttributeSetPtrgetAttributes () const
 Returns the list of vertex Attributes as an AttributeSet. More...
 
bool hasAttributeArray (const char *name) const
 Returns whether or not vertices in this Mesh have an Attribute of the given name. More...
 
const AttributegetAttribute (const char *name) const
 Returns the Attribute definition with the given name, or an empty Attribute if it does not exist. More...
 
int findAttributeIndex (const char *name) const
 Returns the index of the Attribute with the given name. More...
 
void * getBuffer () const
 Returns a raw pointer to the current vertex buffer. More...
 
void setBuffer (void *buffer, int vertexCount)
 Sets the current vertex buffer to be a user managed buffer. More...
 
void allocateBuffer (int vertexCount)
 Sets the current buffer to be a Mesh managed buffer. More...
 
int getDrawVertexCount () const
 Returns the number of vertices that will be drawn when this Mesh is rendered. More...
 
void setDrawVertexCount (int drawVertexCount)
 Sets the number of vertices to draw when this Mesh is rendered. More...
 
template<typename T >
const AttributeArray< T > getAttributeArray (const char *name) const
 Returns the values of the vertex Attribute with the given name as an AttributeArray. More...
 
template<typename T >
AttributeArray< T > getAttributeArray (const char *name)
 Returns the values of the vertex Attribute with the given name as a mutable AttributeArray. More...
 

Detailed Description

Mesh composed of vertices, and attributes for each vertex.

This class manages a GL buffer object, which is used to store vertex data. This data can be bound and read as inputs to Shader vertex attributes. MeshInstance is used to store the mapping between a particular Mesh and Shader pair. Data is uploaded as a GL_STATIC_DRAW GL_ARRAY_BUFFER object. Indexed primitives are currently not supported.

Note
This class does not currently restore GL resources on context change.

Constructor & Destructor Documentation

Mesh::Mesh ( int  vertexCount,
const AttributeSetPtr attributes 
)

Construct a mesh with the given vertex attributes and vertex count.

The vertex buffer is allocated and managed by this object using a call to allocateBuffer(). This buffer, and any GL resources are freed when this Mesh is destroyed. A custom buffer can be provided using setBuffer(). This frees the managed buffer and treats the provided buffer as this Mesh's vertex data.

Parameters
vertexCountNumber of vertices to allocate
attributesAttributes to store for each vertex

Member Function Documentation

void Mesh::allocateBuffer ( int  vertexCount)

Sets the current buffer to be a Mesh managed buffer.

The old Mesh managed buffer is freed if allocated, and a new one created. This method also resets the number of vertices to draw to the total vertex count using setDrawVertexCount().

Parameters
vertexCountNumber of vertices to allocate
void Mesh::bind ( )

Bind this vertex buffer, uploading it if necessary.

void Mesh::dispose ( )

Frees this Mesh's managed buffer, and GL buffer object, if allocated.

int Mesh::findAttributeIndex ( const char *  name) const

Returns the index of the Attribute with the given name.

Parameters
nameName of the Attribute to get
Returns
Index of the given Attribute, or -1 if it was not found
const Attribute& Mesh::getAttribute ( const char *  name) const

Returns the Attribute definition with the given name, or an empty Attribute if it does not exist.

Parameters
nameName of the Attribute to get
template<typename T >
const AttributeArray<T> Mesh::getAttributeArray ( const char *  name) const
inline

Returns the values of the vertex Attribute with the given name as an AttributeArray.

The data is returned as an iterable AttributeArray of the given type T. This allows the attribute values for all vertices to be treated as an array, without worrying about vertex stride.

Note
If the Attribute was not found, the returned AttributeArray will be invalid, and its AttributeArray::isValid() method will return false.
Returns
AttributeArray which interprets the vertex Attribute as the given type T
template<typename T >
AttributeArray<T> Mesh::getAttributeArray ( const char *  name)
inline

Returns the values of the vertex Attribute with the given name as a mutable AttributeArray.

The data is returned as an iterable AttributeArray of the given type T. This allows the attribute values for all vertices to be treated as an array, without worrying about vertex stride. This allows for convenient filling of vertex attributes.

Note
If the Attribute was not found, the returned AttributeArray will be invalid, and its AttributeArray::isValid() method will return false.
Returns
AttributeArray which interprets the vertex Attribute as the given type T
const AttributeSetPtr& Mesh::getAttributes ( ) const
inline

Returns the list of vertex Attributes as an AttributeSet.

void* Mesh::getBuffer ( ) const
inline

Returns a raw pointer to the current vertex buffer.

int Mesh::getDrawVertexCount ( ) const
inline

Returns the number of vertices that will be drawn when this Mesh is rendered.

See also
setDrawVertexCount()
int Mesh::getVertexCount ( ) const
inline

Returns the length of the current vertex buffer, in number of vertices.

bool Mesh::hasAttributeArray ( const char *  name) const

Returns whether or not vertices in this Mesh have an Attribute of the given name.

Parameters
nameName of the Attribute to check
bool Mesh::isUploaded ( ) const
inline

Returns whether or not an associated GL buffer object exists and contains uploaded data.

Note
This method does not indicate if the data that was uploaded is up to date.
void Mesh::setBuffer ( void *  buffer,
int  vertexCount 
)

Sets the current vertex buffer to be a user managed buffer.

This frees the Mesh managed buffer if allocated. This method also resets the number of vertices to draw to the total vertex count using setDrawVertexCount().

Parameters
bufferPointer to the user managed buffer
vertexCountNumber of vertices in the buffer
void Mesh::setDrawVertexCount ( int  drawVertexCount)

Sets the number of vertices to draw when this Mesh is rendered.

This number must be less than or equal to the total number of vertices in the buffer. This method allows the user to preallocate a buffer of some length, and then using it as a variable length buffer up to that maximum length.

Parameters
drawVertexCountNumber of vertices to draw
void Mesh::unbind ( )

Unbinds this vertex buffer.

void Mesh::upload ( )

Uploads the current vertex buffer's data into a GL buffer object.

If no GL buffer object has been allocated, a new one is created.