You.i Engine
CYIMesh Class Reference

Detailed Description

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>


struct  VertexBuffer

Public Types

enum  GeometryPrimitive : uint8_t {
enum  BufferOwnership : uint8_t {

Public Member Functions

 CYIMesh ()
virtual ~CYIMesh ()
void SetTransform (const glm::mat4 &transform)
const glm::mat4 & GetTransform () const
size_t AddVertexBuffer (std::shared_ptr< CYIAssetBufferObjectData > pData, BufferOwnership ownership)
void SetIndexBuffer (std::shared_ptr< CYIAssetBufferObjectData > pData, BufferOwnership ownership)
void SetBindings (const std::vector< YI_ATTRIBUTE_BINDING > &bindings)
void SetBindings (std::initializer_list< YI_ATTRIBUTE_BINDING > bindings)
std::vector< CYIMesh::YI_ATTRIBUTE_BINDINGGetBindings () const
void SetAxisAlignedBoundingBox (const CYIAABB &aabb)
const CYIAABBGetAxisAlignedBoundingBox () const
const std::shared_ptr< CYIAssetBufferObjectData > & GetVertexBuffer (size_t bufferIndex) const
const std::shared_ptr< CYIAssetBufferObjectData > & GetIndexBuffer () const
void RemoveVertexBuffer (size_t bufferIndex)
void RemoveIndexBuffer ()
const YI_ATTRIBUTE_BINDINGGetBinding (size_t bindingIndex) const
size_t GetNumVertexBuffers () const
size_t GetNumBindings () const
void SetPrimitive (GeometryPrimitive primitive)
GeometryPrimitive GetPrimitive () const
size_t GetIndexCount () const
void SetIndexCount (size_t count)
size_t GetStartOffset () const
void SetStartOffset (size_t startOffset)
void SetDepthTesting (bool enabled)
bool GetDepthTesting () const
bool IsLoaded () const

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< CYIAssetBufferObjectDatam_IBO
CYISmallVector< YI_ATTRIBUTE_BINDING, 2 > m_Attributes
glm::mat4 m_transform
size_t m_indexCount
size_t m_startOffset
bool m_hasDepth
GeometryPrimitive m_primitive
BufferOwnership m_IBOOwnership
bool m_isLoaded

Member Enumeration Documentation

◆ BufferOwnership

enum CYIMesh::BufferOwnership : uint8_t

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.


◆ GeometryPrimitive

enum CYIMesh::GeometryPrimitive : uint8_t

The primitive to be used for rendering this mesh


Constructor & Destructor Documentation

◆ CYIMesh()

CYIMesh::CYIMesh ( )

◆ ~CYIMesh()

virtual CYIMesh::~CYIMesh ( )

Member Function Documentation

◆ AddVertexBuffer()

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().

◆ GetAxisAlignedBoundingBox()

const CYIAABB& CYIMesh::GetAxisAlignedBoundingBox ( ) const

Get the axis-aligned bounding box for this mesh.

◆ GetBinding()

const YI_ATTRIBUTE_BINDING& CYIMesh::GetBinding ( size_t  bindingIndex) const

Get the binding at the bindingIndex specified

◆ GetBindings()

std::vector<CYIMesh::YI_ATTRIBUTE_BINDING> CYIMesh::GetBindings ( ) const

Get the currently set bindings

◆ GetDepthTesting()

bool CYIMesh::GetDepthTesting ( ) const

Returns true if this mesh has depth testing enabled, false otherwise. The default value is false.

◆ GetIndexBuffer()

const std::shared_ptr<CYIAssetBufferObjectData>& CYIMesh::GetIndexBuffer ( ) const

Get the index buffer

◆ GetIndexCount()

size_t CYIMesh::GetIndexCount ( ) const

Get the number of indices used in the rendering of this mesh

◆ GetNumBindings()

size_t CYIMesh::GetNumBindings ( ) const

Returns the number of attached bindings

◆ GetNumVertexBuffers()

size_t CYIMesh::GetNumVertexBuffers ( ) const

Returns the number of attached vertex buffers

◆ GetPrimitive()

GeometryPrimitive CYIMesh::GetPrimitive ( ) const

Get the primitive used for rendering this mesh.

◆ GetStartOffset()

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.

See also

◆ GetTransform()

const glm::mat4& CYIMesh::GetTransform ( ) const

Get the transformation matrix for this mesh.

◆ GetVertexBuffer()

const std::shared_ptr<CYIAssetBufferObjectData>& CYIMesh::GetVertexBuffer ( size_t  bufferIndex) const

Get the vertex buffer at the bufferIndex specified.

◆ IsLoaded()

bool CYIMesh::IsLoaded ( ) const

Returns true if this mesh VBOs and IBO that are set are all loaded on the GPU, false otherwise.

◆ RemoveIndexBuffer()

void CYIMesh::RemoveIndexBuffer ( )

Remove the index buffer

◆ RemoveVertexBuffer()

void CYIMesh::RemoveVertexBuffer ( size_t  bufferIndex)

Remove the vertex buffer at the bufferIndex specified.

◆ SetAxisAlignedBoundingBox()

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.

The user is responsible for including the mesh transform in the bounding box calculation if it is non-identity

◆ SetBindings() [1/2]

void CYIMesh::SetBindings ( const std::vector< YI_ATTRIBUTE_BINDING > &  bindings)

Set the attribute bindings. This call will replace current bindings set internally.

◆ SetBindings() [2/2]

void CYIMesh::SetBindings ( std::initializer_list< YI_ATTRIBUTE_BINDING bindings)

Set the attribute bindings. This call will replace current bindings set internally.

◆ SetDepthTesting()

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.

◆ SetIndexBuffer()

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

◆ SetIndexCount()

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.

◆ SetPrimitive()

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.

◆ SetStartOffset()

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.

See also

◆ SetTransform()

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.

This transformation is not intended to be used in place of the scene node transformation functions, changes to this transformation will not propagate to the children of the node containing this mesh, the transform will only be applied to the internal vertices of this mesh, as specified by the buffers.

Member Data Documentation

◆ m_AABB


◆ m_Attributes

CYISmallVector<YI_ATTRIBUTE_BINDING, 2> CYIMesh::m_Attributes

◆ m_hasDepth

bool CYIMesh::m_hasDepth

◆ m_IBO

std::shared_ptr<CYIAssetBufferObjectData> CYIMesh::m_IBO

◆ m_IBOOwnership

BufferOwnership CYIMesh::m_IBOOwnership

◆ m_indexCount

size_t CYIMesh::m_indexCount

◆ m_isLoaded

bool CYIMesh::m_isLoaded

◆ m_primitive

GeometryPrimitive CYIMesh::m_primitive

◆ m_startOffset

size_t CYIMesh::m_startOffset

◆ m_transform

glm::mat4 CYIMesh::m_transform

◆ m_VBOs

CYISmallVector<VertexBuffer, 1> CYIMesh::m_VBOs

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