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>

Inheritance diagram for CYIMesh:

Classes

struct  YI_ATTRIBUTE_BINDING
 

Public Types

enum  YI_GEOMETRY_PRIMITIVE {
  YI_TRIANGLES,
  YI_TRIANGLE_STRIP,
  YI_POINTS
}
 
enum  YI_BUFFER_OWNERSHIP {
  YI_BUFFER_OWNED,
  YI_BUFFER_SHARED
}
 

Public Member Functions

 CYIMesh ()
 
virtual ~CYIMesh ()
 
void SetTransform (const glm::mat4 &transform)
 
const glm::mat4 & GetTransform () const
 
uint32_t AddVertexBuffer (const std::shared_ptr< CYIAssetBufferObjectData > &pData, YI_BUFFER_OWNERSHIP ownership)
 
void SetIndexBuffer (const std::shared_ptr< CYIAssetBufferObjectData > &pData, YI_BUFFER_OWNERSHIP ownership)
 
void SetBindings (const std::vector< YI_ATTRIBUTE_BINDING > &bindings)
 
const std::vector< YI_ATTRIBUTE_BINDING > & GetBindings () const
 
void SetAxisAlignedBoundingBox (const CYIAABB &aabb)
 
const CYIAABBGetAxisAlignedBoundingBox () const
 
const std::shared_ptr< CYIAssetBufferObjectData > & GetVertexBuffer (uint32_t uBufferIndex) const
 
const std::shared_ptr< CYIAssetBufferObjectData > & GetIndexBuffer () const
 
void RemoveVertexBuffer (uint32_t uBufferIndex)
 
void RemoveIndexBuffer ()
 
const YI_ATTRIBUTE_BINDINGGetBinding (uint32_t uBindingIndex)
 
uint32_t GetNumVertexBuffers () const
 
uint32_t GetNumBindings () const
 
void SetPrimitive (YI_GEOMETRY_PRIMITIVE primitive)
 
YI_GEOMETRY_PRIMITIVE GetPrimitive () const
 
uint32_t GetIndexCount () const
 
void SetIndexCount (uint32_t count)
 
uint32_t GetStartOffset () const
 
void SetStartOffset (uint32_t uStartOffset)
 
void SetDepthTesting (bool bEnabled)
 
bool GetDepthTesting () const
 
bool IsLoaded () const
 
- Public Member Functions inherited from CYIScriptableObject
 CYIScriptableObject ()
 
 CYIScriptableObject (const CYIScriptableObject &other)
 
CYIScriptableObjectoperator= (const CYIScriptableObject &other)
 
virtual ~CYIScriptableObject ()
 
CYIBindingImplementationGetBindingImplementation () const
 
void SetBindingImplementation (CYIBindingImplementation *pBindingImplementation)
 
virtual const CYIRuntimeTypeInfoGetRuntimeTypeInfoForScriptObject () 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

std::vector< std::shared_ptr< CYIAssetBufferObjectData > > m_VBOs
 
std::shared_ptr< CYIAssetBufferObjectDatam_IBO
 
std::vector< YI_ATTRIBUTE_BINDINGm_Attributes
 
YI_GEOMETRY_PRIMITIVE m_primitive
 
uint32_t m_indexCount
 
uint32_t m_uStartOffset
 
glm::mat4 m_transform
 
CYIAABB m_AABB
 
bool m_bHasDepth
 
std::vector< YI_BUFFER_OWNERSHIPm_VBOOwnership
 
YI_BUFFER_OWNERSHIP m_IBOOwnership
 
bool m_bIsLoaded
 

Member Enumeration Documentation

Flag to determine the ownership of the VBOs and IBO. If the flag is se to YI_BUFFER_OWNED, This CYIMesh Instance will take responsibility for unloading the VBOs and IBOs from the GPU.

Enumerator
YI_BUFFER_OWNED 
YI_BUFFER_SHARED 

The primitive to be used for rendering this mesh

Enumerator
YI_TRIANGLES 
YI_TRIANGLE_STRIP 
YI_POINTS 

Constructor & Destructor Documentation

CYIMesh::CYIMesh ( )
virtual CYIMesh::~CYIMesh ( )
virtual

Member Function Documentation

uint32_t CYIMesh::AddVertexBuffer ( const std::shared_ptr< CYIAssetBufferObjectData > &  pData,
YI_BUFFER_OWNERSHIP  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 ( uint32_t  uBindingIndex)

Get the binding at the uBindingIndex specified

const std::vector<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

uint32_t CYIMesh::GetIndexCount ( ) const

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

uint32_t CYIMesh::GetNumBindings ( ) const

Returns the number of attached bindings

uint32_t CYIMesh::GetNumVertexBuffers ( ) const

Returns the number of attached vertex buffers

YI_GEOMETRY_PRIMITIVE CYIMesh::GetPrimitive ( ) const

Get the primitive used for rendering this mesh.

uint32_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
SetStartOffset
const glm::mat4& CYIMesh::GetTransform ( ) const

Get the transformation matrix for this mesh.

const std::shared_ptr<CYIAssetBufferObjectData>& CYIMesh::GetVertexBuffer ( uint32_t  uBufferIndex) const

Get the vertex buffer at the uBufferIndex 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 ( uint32_t  uBufferIndex)

Remove the vertex buffer at the uBufferIndex 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.

Warning
The user is responsible for including the mesh transform in the bounding box calculation if it is non-identity
void CYIMesh::SetBindings ( const std::vector< YI_ATTRIBUTE_BINDING > &  bindings)

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

void CYIMesh::SetDepthTesting ( bool  bEnabled)

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 ( const std::shared_ptr< CYIAssetBufferObjectData > &  pData,
YI_BUFFER_OWNERSHIP  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 ( uint32_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 ( YI_GEOMETRY_PRIMITIVE  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 ( uint32_t  uStartOffset)

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
GetStartOffset
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.

Warning
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

CYIAABB CYIMesh::m_AABB
protected
std::vector<YI_ATTRIBUTE_BINDING> CYIMesh::m_Attributes
protected
bool CYIMesh::m_bHasDepth
protected
bool CYIMesh::m_bIsLoaded
mutableprotected
std::shared_ptr<CYIAssetBufferObjectData> CYIMesh::m_IBO
protected
YI_BUFFER_OWNERSHIP CYIMesh::m_IBOOwnership
protected
uint32_t CYIMesh::m_indexCount
protected
YI_GEOMETRY_PRIMITIVE CYIMesh::m_primitive
protected
glm::mat4 CYIMesh::m_transform
protected
uint32_t CYIMesh::m_uStartOffset
protected
std::vector<YI_BUFFER_OWNERSHIP> CYIMesh::m_VBOOwnership
protected
std::vector<std::shared_ptr<CYIAssetBufferObjectData> > CYIMesh::m_VBOs
protected

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