#include <mesh.h>
Public Member Functions | |
MeshInstance (RenderService &renderService) | |
virtual | ~MeshInstance () |
bool | init (utility::ErrorState &errorState) |
void | copyMeshProperties (RTTIMeshProperties &meshProperties) |
GPUMesh & | getGPUMesh () const |
template<typename T > | |
VertexAttribute< T > * | findAttribute (const std::string &id) |
template<typename T > | |
const VertexAttribute< T > * | findAttribute (const std::string &id) const |
template<typename T > | |
VertexAttribute< T > & | getAttribute (const std::string &id) |
template<typename T > | |
const VertexAttribute< T > & | getAttribute (const std::string &id) const |
template<typename T > | |
VertexAttribute< T > & | getOrCreateAttribute (const std::string &id) |
void | reserveVertices (size_t numVertices) |
void | setNumVertices (int numVertices) |
int | getNumVertices () const |
int | getNumShapes () const |
void | setDrawMode (EDrawMode mode) |
EDrawMode | getDrawMode () const |
void | setCullMode (ECullMode mode) |
ECullMode | getCullMode () const |
void | setPolygonMode (EPolygonMode mode) |
EPolygonMode | getPolygonMode () const |
MeshShape & | getShape (int index) |
const MeshShape & | getShape (int index) const |
MeshShape & | createShape () |
void | setUsage (EMemoryUsage inUsage) |
EMemoryUsage | getUsage () const |
bool | update (utility::ErrorState &errorState) |
bool | update (nap::BaseVertexAttribute &attribute, utility::ErrorState &errorState) |
template<typename T > | |
nap::VertexAttribute< T > * | findAttribute (const std::string &id) |
template<typename T > | |
nap::VertexAttribute< T > & | getAttribute (const std::string &id) |
template<typename T > | |
nap::VertexAttribute< T > & | getOrCreateAttribute (const std::string &id) |
Protected Member Functions | |
bool | initGPUData (utility::ErrorState &errorState) |
Runtime version of a mesh. MeshInstance holds CPU data and can convert this data into a GPUMesh.
A MeshInstance can be created in two ways: 1) Manually allocate a MeshInstance object, add attributes to it, and call the regular init() on it. This is useful for creation of procedural meshes.
2) Initialize a MeshInstance object through the init() function that takes an RTTIMeshProperties struct. This is intended for situations where the MeshInstance is created from an RTTI based object (either rtti-json or rtti-binary).
After the initial init() call, the GPU attributes are created and the mesh is updated. This means that the contents of the vertex attributes and the index buffer is uploaded to the GPU. If the contents of the vertex attributes are filled in before calling init(), the mesh is fully up to date.
It is also possible to update the mesh dynamically. The vertex attribute contents should be updated, followed by an update() call.
MeshInstance | ( | RenderService & | renderService | ) |
|
virtual |
void copyMeshProperties | ( | RTTIMeshProperties & | meshProperties | ) |
Clones the RTTI based data but does not build a GPU mesh from it. Call init to upload the cloned data to the GPU. The cloned data is owned by MeshInstance
meshProperties | The RTTI mesh properties to clone into the mesh instance. |
MeshShape& createShape | ( | ) |
Create and add a new shape to this mesh. The returned shape is uninitialized; it is up to the client to initialize as needed
VertexAttribute<T>* findAttribute | ( | const std::string & | id | ) |
Finds vertex attribute.
id | The name of the vertex attribute. For predefined vertex attributions like position, color etc, use the various MeshInstance::VertexAttributeIDs. |
nap::VertexAttribute<T>* findAttribute | ( | const std::string & | id | ) |
const VertexAttribute< T > * findAttribute | ( | const std::string & | id | ) | const |
Finds vertex attribute.
id | The name of the vertex attribute. For predefined vertex attributions like position, color etc, use the various MeshInstance::VertexAttributeIDs. |
VertexAttribute<T>& getAttribute | ( | const std::string & | id | ) |
Gets vertex attribute.
id | The name of the vertex attribute. For predefined vertex attributions like position, color etc, use the various MeshInstance::VertexAttributeIDs. |
nap::VertexAttribute<T>& getAttribute | ( | const std::string & | id | ) |
const VertexAttribute< T > & getAttribute | ( | const std::string & | id | ) | const |
Gets vertex attribute.
id | The name of the vertex attribute. For predefined vertex attributions like position, color etc, use the various MeshInstance::VertexAttributeIDs. |
ECullMode getCullMode | ( | ) | const |
EDrawMode getDrawMode | ( | ) | const |
GPUMesh& getGPUMesh | ( | ) | const |
int getNumShapes | ( | ) | const |
int getNumVertices | ( | ) | const |
VertexAttribute<T>& getOrCreateAttribute | ( | const std::string & | id | ) |
Gets a vertex attribute or creates it if it does not exist. In case the attribute did exist, but with a different type, the function asserts.
id | The name of the vertex attribute. For predefined vertex attributions like position, color etc, use the various MeshInstance::VertexAttributeIDs. |
nap::VertexAttribute<T>& getOrCreateAttribute | ( | const std::string & | id | ) |
EPolygonMode getPolygonMode | ( | ) | const |
MeshShape& getShape | ( | int | index | ) |
Get the shape at the specified index
index | The index of the shape to get (between 0 and getNumShapes()) |
const MeshShape& getShape | ( | int | index | ) | const |
Get the shape at the specified index
index | The index of the shape to get (between 0 and getNumShapes()) |
EMemoryUsage getUsage | ( | ) | const |
bool init | ( | utility::ErrorState & | errorState | ) |
Builds a GPU mesh from the CPU mesh. Attribute information should be filled in prior to calling init().
errorState | Contains error information if an error occurred. |
|
protected |
void reserveVertices | ( | size_t | numVertices | ) |
Reserves CPU memory for the given amount of vertices. All associated vertex attributes are affected. GPU memory is reserved after update() is called.
numVertices | amount of vertices to reserve memory for. |
void setCullMode | ( | ECullMode | mode | ) |
mode | the cull mode of this mesh (front, back etc.) |
void setDrawMode | ( | EDrawMode | mode | ) |
void setNumVertices | ( | int | numVertices | ) |
Sets number of vertices. The amount of elements for each vertex buffer should be equal to the amount of vertices in the mesh.
numVertices | amount of vertices in the mesh. |
void setPolygonMode | ( | EPolygonMode | mode | ) |
Sets the polygon mode of this mesh to use (fill, line or point). Logs a warning if the requested mode is not supported. To ensure a specific mode is supported call: RenderService::getPolygonModeSupported().
mode | the polygon mode to use |
void setUsage | ( | EMemoryUsage | inUsage | ) |
Set the usage for this mesh. Note that it only makes sense to change this before init is called, changing it after init will not have any effect.
bool update | ( | nap::BaseVertexAttribute & | attribute, |
utility::ErrorState & | errorState | ||
) |
Push one specific CPU vertex buffer to the GPU. Use this when updating only specific vertex attributes at run-time. Only update the mesh when 'Usage' is set to 'DynamicWrite', an assert is triggered otherwise. If there is a mismatch between the vertex buffer an error will be returned
attribute | the attribute to synchronize. |
errorState | contains the error when synchronization fails. |
bool update | ( | utility::ErrorState & | errorState | ) |
Pushes all CPU vertex buffers to the GPU. Note that update() is called during init(), so this is only required if CPU data is modified after init(). Only update the mesh when 'Usage' is set to 'DynamicWrite', an assert is triggered otherwise. If there is a mismatch between vertex buffer, an error will be returned.
errorState | Contains error information if an error occurred. |