OGRE  2.3
Object-Oriented Graphics Rendering Engine
Ogre::SubMesh Class Reference

Defines a part of a complete mesh. More...

#include <OgreSubMesh2.h>

+ Inheritance diagram for Ogre::SubMesh:

Classes

struct  SourceData
 

Public Types

typedef FastArray< unsigned short > IndexMap
 
typedef FastArray< SourceDataSourceDataArray
 
typedef vector< VertexBoneAssignment >::type VertexBoneAssignmentVec
 

Public Member Functions

 SubMesh ()
 
 ~SubMesh ()
 
void _buildBoneAssignmentsFromVertexData (uint8 const *vertexData)
 Populates mBoneAssignments by reading the vertex data. More...
 
void _buildBoneAssignmentsFromVertexData (void)
 Populates mBoneAssignments by reading the vertex data. More...
 
void _buildBoneIndexMap (void)
 Builds mBlendIndexToBoneIndexMap based on mBoneAssignments. More...
 
void _compileBoneAssignments (void)
 Call this function if you've manually called addBoneAssignment to setup bones for vertices. More...
 
void _prepareForShadowMapping (bool forceSameBuffers)
 
void addBoneAssignment (const VertexBoneAssignment &vertBoneAssign)
 Assigns a vertex to a bone with a given weight, for skeletal animation. More...
 
void arrangeEfficient (bool halfPos, bool halfTexCoords, bool qTangents)
 Converts this SubMesh to an efficient arrangement. More...
 
void clearBoneAssignments (void)
 Removes all bone assignments for this mesh. More...
 
SubMeshclone (Mesh *parentMesh=0, int vertexBufferType=-1, int indexBufferType=-1)
 Makes a copy of this submesh object and gives it a new name. More...
 
void createPoses (const float **positionData, const float **normalData, size_t numPoses, size_t numVertices, const String *names=0, bool halfPrecision=true)
 Fills the pose animation buffer with the given poseData. More...
 
void dearrangeToInefficient (void)
 Reverts the effects from arrangeEfficient by converting all 16-bit half float back to 32-bit float; and QTangents to Normal, Tangent + Reflection representation, which are more compatible for doing certain operations vertex operations in the CPU. More...
 
const VertexBoneAssignmentVecgetBoneAssignments ()
 Gets a const reference to the list of bone assignments. More...
 
String getMaterialName (void) const
 
uint16 getNumPoses ()
 
bool getPoseHalfPrecision ()
 
size_t getPoseIndex (const Ogre::String &name)
 
bool getPoseNormals ()
 
TexBufferPackedgetPoseTexBuffer ()
 
void importFromV1 (v1::SubMesh *subMesh, bool halfPos, bool halfTexCoords, bool qTangents, bool halfPose)
 Imports a v1 SubMesh @See Mesh::importV1. Automatically performs what arrangeEfficient does. More...
 
void operator delete (void *ptr)
 
void operator delete (void *ptr, const char *, int, const char *)
 
void operator delete (void *ptr, void *)
 
void operator delete[] (void *ptr)
 
void operator delete[] (void *ptr, const char *, int, const char *)
 
void * operator new (size_t sz)
 
void * operator new (size_t sz, const char *file, int line, const char *func)
 operator new, with debug line info More...
 
void * operator new (size_t sz, void *ptr)
 placement operator new More...
 
void * operator new[] (size_t sz)
 
void * operator new[] (size_t sz, const char *file, int line, const char *func)
 array operator new, with debug line info More...
 
void setMaterialName (const String &name)
 

Static Public Member Functions

static char * _arrangeEfficient (SourceDataArray srcData, const VertexElement2Vec &vertexElements, uint32 vertexCount)
 Generic form that does the actual job for both v1 and v2 objects. More...
 
static char * _arrangeEfficient (v1::SubMesh *subMesh, bool halfPos, bool halfTexCoords, bool qTangents, VertexElement2Vec *outVertexElements, size_t vaoPassIdx)
 Rearranges the buffers to be efficiently rendered in Ogre 2.1 with Hlms Takes a v1 SubMesh and returns a pointer with the data interleaved, and a VertexElement2Vec with the new vertex format. More...
 
static char * _dearrangeEfficient (char const *RESTRICT_ALIAS srcData, uint32 numElements, const VertexElement2Vec &vertexElements, VertexElement2Vec *outVertexElements)
 Generic form that does the actual job for both v1 and v2 objects. More...
 
static void destroyVaos (VertexArrayObjectArray &vaos, VaoManager *vaoManager, bool destroyIndexBuffer=true)
 

Public Attributes

IndexMap mBlendIndexToBoneIndexMap
 Dedicated index map for translate blend index to bone index. More...
 
String mMaterialName
 Name of the material this SubMesh uses. More...
 
MeshmParent
 Reference to parent Mesh (not a smart pointer so child does not keep parent alive). More...
 
VertexArrayObjectArray mVao [NumVertexPass]
 VAO to render the submesh. More...
 

Friends

class Mesh
 
class MeshSerializerImpl
 

Detailed Description

Defines a part of a complete mesh.

Remarks
Meshes which make up the definition of a discrete 3D object are made up of potentially multiple parts. This is because different parts of the mesh may use different materials or use different vertex formats, such that a rendering state change is required between them.
Like the Mesh class, instantiations of 3D objects in the scene share the SubMesh instances, and have the option of overriding their material differences on a per-object basis if required. See the SubEntity class for more information.

Member Typedef Documentation

◆ IndexMap

typedef FastArray<unsigned short> Ogre::SubMesh::IndexMap

◆ SourceDataArray

◆ VertexBoneAssignmentVec

Constructor & Destructor Documentation

◆ SubMesh()

Ogre::SubMesh::SubMesh ( )

◆ ~SubMesh()

Ogre::SubMesh::~SubMesh ( )

Member Function Documentation

◆ _arrangeEfficient() [1/2]

static char* Ogre::SubMesh::_arrangeEfficient ( SourceDataArray  srcData,
const VertexElement2Vec vertexElements,
uint32  vertexCount 
)
static

Generic form that does the actual job for both v1 and v2 objects.

Takes an array of pointers to source each vertex element, and returns a pointer with the valid data.

Parameters
srcDataArray that points to the source data for every vertex element. VES_TANGENT and VES_BINORMAL must be at the end if converting to QTangents. The pointer in SourceData::data must already be offsetted.
vertexElementsThe vertex format we're converting to.
vertexCountNumber of vertices
Returns
Buffer pointer with reorganized data. static char* _arrangeEfficient( SourceDataArray srcData, Caller MUST free the pointer with OGRE_FREE_SIMD( MEMCATEGORY_GEOMETRY ).

◆ _arrangeEfficient() [2/2]

static char* Ogre::SubMesh::_arrangeEfficient ( v1::SubMesh subMesh,
bool  halfPos,
bool  halfTexCoords,
bool  qTangents,
VertexElement2Vec outVertexElements,
size_t  vaoPassIdx 
)
static

Rearranges the buffers to be efficiently rendered in Ogre 2.1 with Hlms Takes a v1 SubMesh and returns a pointer with the data interleaved, and a VertexElement2Vec with the new vertex format.

Remarks
Final work is delegated to the generic overload.
Parameters
halfPos@See Mesh::importV1
halfTexCoords@See Mesh::importV1
qTangents@See Mesh::importV1
outVertexElements[out] Description of the buffer in the new v2 system.
Returns
Buffer pointer with reorganized data. Caller MUST free the pointer with OGRE_FREE_SIMD( MEMCATEGORY_GEOMETRY ).

◆ _buildBoneAssignmentsFromVertexData() [1/2]

void Ogre::SubMesh::_buildBoneAssignmentsFromVertexData ( uint8 const *  vertexData)

Populates mBoneAssignments by reading the vertex data.

This version accepts an external buffer in case you already have the vertex data on CPU (instead of having to bring it back from GPU)

Remarks
mBlendIndexToBoneIndexMap MUST be up to date. OTHERWISE IT MAY CRASH. Despite accepting external vertexData, mVao must be correctly populated with information about vertexData
Parameters
vertexDataVertex data with blend indices and weights.

◆ _buildBoneAssignmentsFromVertexData() [2/2]

void Ogre::SubMesh::_buildBoneAssignmentsFromVertexData ( void  )

Populates mBoneAssignments by reading the vertex data.

See the other overload.

◆ _buildBoneIndexMap()

void Ogre::SubMesh::_buildBoneIndexMap ( void  )

Builds mBlendIndexToBoneIndexMap based on mBoneAssignments.

mBlendIndexToBoneIndexMap is necessary for enabling skeletal animation.

◆ _compileBoneAssignments()

void Ogre::SubMesh::_compileBoneAssignments ( void  )

Call this function if you've manually called addBoneAssignment to setup bones for vertices.

WARNING: Will destroy LODs.

◆ _dearrangeEfficient()

static char* Ogre::SubMesh::_dearrangeEfficient ( char const *RESTRICT_ALIAS  srcData,
uint32  numElements,
const VertexElement2Vec vertexElements,
VertexElement2Vec outVertexElements 
)
static

Generic form that does the actual job for both v1 and v2 objects.

See also
dearrangeEfficientToInefficient.
Parameters
srcDataSingle pointer with interleaved data.
numElementsNumber of vertices.
vertexElementsVertex format of the original vertex buffer.
outVertexElements[out] Vertex format of the new converted vertex buffer.
Returns
Pointer to the decompressed/dearranged data, interleaved in a single buffer.

◆ _prepareForShadowMapping()

void Ogre::SubMesh::_prepareForShadowMapping ( bool  forceSameBuffers)

◆ addBoneAssignment()

void Ogre::SubMesh::addBoneAssignment ( const VertexBoneAssignment vertBoneAssign)

Assigns a vertex to a bone with a given weight, for skeletal animation.

Remarks

This method is only valid after calling setSkeletonName. Since this is a one-off process there exists only 'addBoneAssignment' and 'clearBoneAssignments' methods, no 'editBoneAssignment'. You should not need to modify bone assignments during rendering (only the positions of bones) and OGRE reserves the right to do some internal data reformatting of this information, depending on render system requirements.
This method is for assigning weights to the dedicated geometry of the SubMesh. To assign weights to the shared Mesh geometry, see the equivalent methods on Mesh.

◆ arrangeEfficient()

void Ogre::SubMesh::arrangeEfficient ( bool  halfPos,
bool  halfTexCoords,
bool  qTangents 
)

Converts this SubMesh to an efficient arrangement.

@See Mesh::importV1 for an explanation on the parameters.

See also
dearrangeEfficientToInefficient to perform the opposite operation.

◆ clearBoneAssignments()

void Ogre::SubMesh::clearBoneAssignments ( void  )

Removes all bone assignments for this mesh.

This method is for assigning weights to the dedicated geometry of the SubMesh. To assign weights to the shared Mesh geometry, see the equivalent methods on Mesh.

◆ clone()

SubMesh* Ogre::SubMesh::clone ( Mesh parentMesh = 0,
int  vertexBufferType = -1,
int  indexBufferType = -1 
)

Makes a copy of this submesh object and gives it a new name.

Parameters
newNameThe name to give the clone.
parentMeshOptional mesh to make the parent of the newly created clone. If you leave this blank, the clone will be parented to the same Mesh as the original.
vertexBufferTypeSee BufferType. Must be set to a valid BufferType. Pass a negative value to keep the same type of the original buffer being cloned.
indexBufferTypeSee BufferType. Must be set to a valid BufferType. Pass a negative value to keep the same type of the original buffer being cloned.

◆ createPoses()

void Ogre::SubMesh::createPoses ( const float **  positionData,
const float **  normalData,
size_t  numPoses,
size_t  numVertices,
const String names = 0,
bool  halfPrecision = true 
)

Fills the pose animation buffer with the given poseData.

Parameters
positionDataArray with a pointer to a block of data for each pose, and each pose should contain (x,y,z) offsets for each vertex in sequence. The size of each block of data must be equals to numVertices * 3 * sizeof(float) or else a buffer overrun shall occur.
normalDataSimilar to positionData however should contain normal offsets and can be nullptr if morphing normals is not desired and it will also save memory.
numPosesNumber of poses.
numVerticesNumber of vertices
namesArray containing the name of each pose or null. If not null must contain numPoses elements.
halfPrecisionTrue if you want the pose buffer to have pixel format PF_FLOAT16_RGBA which uses significantly less memory. Otherwise it is created with pixel format PF_FLOAT32_RGBA. Rarely the extra precision is needed.

◆ dearrangeToInefficient()

void Ogre::SubMesh::dearrangeToInefficient ( void  )

Reverts the effects from arrangeEfficient by converting all 16-bit half float back to 32-bit float; and QTangents to Normal, Tangent + Reflection representation, which are more compatible for doing certain operations vertex operations in the CPU.

◆ destroyVaos()

static void Ogre::SubMesh::destroyVaos ( VertexArrayObjectArray vaos,
VaoManager vaoManager,
bool  destroyIndexBuffer = true 
)
static

◆ getBoneAssignments()

const VertexBoneAssignmentVec& Ogre::SubMesh::getBoneAssignments ( )
inline

Gets a const reference to the list of bone assignments.

◆ getMaterialName()

String Ogre::SubMesh::getMaterialName ( void  ) const
inline

◆ getNumPoses()

uint16 Ogre::SubMesh::getNumPoses ( )
inline

◆ getPoseHalfPrecision()

bool Ogre::SubMesh::getPoseHalfPrecision ( )
inline

◆ getPoseIndex()

size_t Ogre::SubMesh::getPoseIndex ( const Ogre::String name)
inline

◆ getPoseNormals()

bool Ogre::SubMesh::getPoseNormals ( )
inline

◆ getPoseTexBuffer()

TexBufferPacked* Ogre::SubMesh::getPoseTexBuffer ( )
inline

◆ importFromV1()

void Ogre::SubMesh::importFromV1 ( v1::SubMesh subMesh,
bool  halfPos,
bool  halfTexCoords,
bool  qTangents,
bool  halfPose 
)

Imports a v1 SubMesh @See Mesh::importV1. Automatically performs what arrangeEfficient does.

◆ operator delete() [1/3]

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr)
inlineinherited

◆ operator delete() [2/3]

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr,
const char *  ,
int  ,
const char *   
)
inlineinherited

◆ operator delete() [3/3]

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr,
void *   
)
inlineinherited

◆ operator delete[]() [1/2]

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete[] ( void *  ptr)
inlineinherited

◆ operator delete[]() [2/2]

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete[] ( void *  ptr,
const char *  ,
int  ,
const char *   
)
inlineinherited

◆ operator new() [1/3]

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz)
inlineinherited

◆ operator new() [2/3]

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz,
const char *  file,
int  line,
const char *  func 
)
inlineinherited

operator new, with debug line info

◆ operator new() [3/3]

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz,
void *  ptr 
)
inlineinherited

placement operator new

◆ operator new[]() [1/2]

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new[] ( size_t  sz)
inlineinherited

◆ operator new[]() [2/2]

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new[] ( size_t  sz,
const char *  file,
int  line,
const char *  func 
)
inlineinherited

array operator new, with debug line info

◆ setMaterialName()

void Ogre::SubMesh::setMaterialName ( const String name)
inline

Friends And Related Function Documentation

◆ Mesh

friend class Mesh
friend

◆ MeshSerializerImpl

friend class MeshSerializerImpl
friend

Member Data Documentation

◆ mBlendIndexToBoneIndexMap

IndexMap Ogre::SubMesh::mBlendIndexToBoneIndexMap

Dedicated index map for translate blend index to bone index.

We collect actually used bones of all bone assignments, and build the blend index in 'packed' form, then the range of the blend index in vertex data VES_BLEND_INDICES element is continuous, with no gaps. Thus, by minimising the world matrix array constants passing to GPU, we can support more bones for a mesh when hardware skinning is used. The hardware skinning support limit is applied to each set of vertex data in the mesh, in other words, the hardware skinning support limit is applied only to the actually used bones of each SubMeshes, not all bones across the entire Mesh.
Because the blend index is different to the bone index, therefore, we use the index map to translate the blend index to bone index.
The use of shared or non-shared index map is determined when model data is converted to the OGRE .mesh format.

◆ mMaterialName

String Ogre::SubMesh::mMaterialName

Name of the material this SubMesh uses.

◆ mParent

Mesh* Ogre::SubMesh::mParent

Reference to parent Mesh (not a smart pointer so child does not keep parent alive).

◆ mVao

VertexArrayObjectArray Ogre::SubMesh::mVao[NumVertexPass]

VAO to render the submesh.

One per LOD level. Each LOD may or may not share the vertex and index buffers the other levels [0] = Used for regular rendering [1] = Used for shadow map caster passes Note that mVao[1] = mVao[0] is valid. But if they're not exactly the same VertexArrayObject pointers, then they won't share any pointer.


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