VoltAir
|
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 AttributeSetPtr & | getAttributes () 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 Attribute & | getAttribute (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... | |
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.
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.
vertexCount | Number of vertices to allocate |
attributes | Attributes to store for each vertex |
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().
vertexCount | Number 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 |
const Attribute& Mesh::getAttribute | ( | 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.
false
. T
|
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.
false
. T
|
inline |
Returns the list of vertex Attributes as an AttributeSet.
|
inline |
Returns a raw pointer to the current vertex buffer.
|
inline |
Returns the number of vertices that will be drawn when this Mesh is rendered.
|
inline |
Returns the length of the current vertex buffer, in number of vertices.
bool Mesh::hasAttributeArray | ( | const char * | name | ) | const |
|
inline |
Returns whether or not an associated GL buffer object exists and contains uploaded data.
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().
buffer | Pointer to the user managed buffer |
vertexCount | Number 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.
drawVertexCount | Number 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.