Class representing an instance of geometry information.
A mesh represents 3D geometry using an array of vertices and indices. To facilitate vertex and index sharing, meshes may contain a matrix describing a specific transformation to be applied to the vertex data prior to rendering.
For instance, an application may make use of a single set of vertices to represent a sphere with diameter 1 and make use of this matrix to apply scaling to render spheres of varying sizes without requiring a different set of vertex data. This allows for rendering with fewer state changes and less overall video ram usage.
Using this matrix instead of the transform matrix of the node containing this mesh is beneficial because children of the node will not inherit the transformation, it will be applied only to the specific instance of the mesh.
#include <renderer/YiMesh.h>
Classes | |
struct | VertexBuffer |
struct | YI_ATTRIBUTE_BINDING |
Public Types | |
enum | GeometryPrimitive : uint8_t { GeometryPrimitive::Triangles, GeometryPrimitive::TriangleStrip, GeometryPrimitive::Points } |
enum | BufferOwnership : uint8_t { BufferOwnership::Owned, BufferOwnership::Shared } |
Static Public Attributes | |
static const uint32_t | YI_POSITION = 0 |
static const uint32_t | YI_TEXCOORD = 1 |
static const uint32_t | YI_NORMAL = 2 |
static const uint32_t | YI_COLOR = 3 |
Protected Attributes | |
CYISmallVector< VertexBuffer, 1 > | m_VBOs |
std::shared_ptr< CYIAssetBufferObjectData > | m_IBO |
CYISmallVector< YI_ATTRIBUTE_BINDING, 2 > | m_Attributes |
glm::mat4 | m_transform |
CYIAABB | m_AABB |
size_t | m_indexCount |
size_t | m_startOffset |
bool | m_hasDepth |
GeometryPrimitive | m_primitive |
BufferOwnership | m_IBOOwnership |
bool | m_isLoaded |
|
strong |
Flag to determine the ownership of the VBOs and IBO. If the flag is se to BufferOwnership::Owned, This CYIMesh Instance will take responsibility for unloading the VBOs and IBOs from the GPU.
Enumerator | |
---|---|
Owned | |
Shared |
|
strong |
CYIMesh::CYIMesh | ( | ) |
|
virtual |
size_t CYIMesh::AddVertexBuffer | ( | std::shared_ptr< CYIAssetBufferObjectData > | pData, |
BufferOwnership | ownership | ||
) |
Function to provide a means of adding vertex data buffers to the mesh, these buffers can later be used to bind to vertex attributes using SetBinding().
This function will return the index at which the buffer resides, for use with GetBuffer() and SetBinding().
const CYIAABB& CYIMesh::GetAxisAlignedBoundingBox | ( | ) | const |
Get the axis-aligned bounding box for this mesh.
const YI_ATTRIBUTE_BINDING& CYIMesh::GetBinding | ( | size_t | bindingIndex | ) | const |
Get the binding at the bindingIndex specified
std::vector<CYIMesh::YI_ATTRIBUTE_BINDING> CYIMesh::GetBindings | ( | ) | const |
Get the currently set bindings
bool CYIMesh::GetDepthTesting | ( | ) | const |
Returns true if this mesh has depth testing enabled, false otherwise. The default value is false.
const std::shared_ptr<CYIAssetBufferObjectData>& CYIMesh::GetIndexBuffer | ( | ) | const |
Get the index buffer
size_t CYIMesh::GetIndexCount | ( | ) | const |
Get the number of indices used in the rendering of this mesh
size_t CYIMesh::GetNumBindings | ( | ) | const |
Returns the number of attached bindings
size_t CYIMesh::GetNumVertexBuffers | ( | ) | const |
Returns the number of attached vertex buffers
GeometryPrimitive CYIMesh::GetPrimitive | ( | ) | const |
Get the primitive used for rendering this mesh.
size_t CYIMesh::GetStartOffset | ( | ) | const |
Get the starting offset of vertices or indices used in the rendering of this mesh. The default value is 0.
const glm::mat4& CYIMesh::GetTransform | ( | ) | const |
Get the transformation matrix for this mesh.
const std::shared_ptr<CYIAssetBufferObjectData>& CYIMesh::GetVertexBuffer | ( | size_t | bufferIndex | ) | const |
Get the vertex buffer at the bufferIndex specified.
bool CYIMesh::IsLoaded | ( | ) | const |
Returns true if this mesh VBOs and IBO that are set are all loaded on the GPU, false otherwise.
void CYIMesh::RemoveIndexBuffer | ( | ) |
Remove the index buffer
void CYIMesh::RemoveVertexBuffer | ( | size_t | bufferIndex | ) |
Remove the vertex buffer at the bufferIndex specified.
void CYIMesh::SetAxisAlignedBoundingBox | ( | const CYIAABB & | aabb | ) |
Set the axis-aligned bounding box for this mesh. It should tightly wrap the post-transform vertices of the mesh.
void CYIMesh::SetBindings | ( | const std::vector< YI_ATTRIBUTE_BINDING > & | bindings | ) |
Set the attribute bindings. This call will replace current bindings set internally.
void CYIMesh::SetBindings | ( | std::initializer_list< YI_ATTRIBUTE_BINDING > | bindings | ) |
Set the attribute bindings. This call will replace current bindings set internally.
void CYIMesh::SetDepthTesting | ( | bool | enabled | ) |
Set whether this mesh should undergo depth testing. The depth test can be set via the IYIRenderer interface, this flag merely indicates that the mesh will undergo depth testing as configured in the renderer.
void CYIMesh::SetIndexBuffer | ( | std::shared_ptr< CYIAssetBufferObjectData > | pData, |
BufferOwnership | ownership | ||
) |
Function to set the index buffer for this mesh. Both an index buffer and one or more vertex buffers must be set and configured via SetBindings before a mesh can be successfully rendered
void CYIMesh::SetIndexCount | ( | size_t | count | ) |
Set the number of vertices for this mesh, note that index in this context is not the same as a buffer index.
void CYIMesh::SetPrimitive | ( | GeometryPrimitive | primitive | ) |
Set the primitive to be used for rendering this mesh. The vertices will be passed to the GPU using the specified geometry.
void CYIMesh::SetStartOffset | ( | size_t | startOffset | ) |
Set the starting offset of vertices or indices for this mesh. Please note that if you you provide an index buffer, this offset will be used on the index buffer. If you do not provide an index buffer, the offset will be used on the vertex buffer(s) instead.
void CYIMesh::SetTransform | ( | const glm::mat4 & | transform | ) |
Set the transform matrix for this mesh. By default this is the identity matrix. This matrix will be applied to the vertices of the mesh prior to rendering, and is guaranteed to be the first matrix applied to the vertex data.
A typical use case is to allow the re-use of normalized vertex data across meshes of different sizes. For example, a 1x1 quad may be scaled up to NxM prior to rendering, allowing the user to make use of the same information across all of their quads instead of providing different vertex data for quads of varying sizes.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
mutableprotected |
|
protected |
|
protected |
|
protected |
|
protected |