OgreInstanceBatchVTF.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __BaseInstanceBatchVTF_H__
#define __BaseInstanceBatchVTF_H__
#include "OgreInstanceBatch.h"
#include "OgreTexture.h"
namespace Ogre
{
class _OgreExport BaseInstanceBatchVTF : public InstanceBatch
{
protected:
typedef vector<uint8>::type HWBoneIdxVec;
typedef vector<float>::type HWBoneWgtVec;
typedef vector<Matrix4>::type Matrix4Vec;
size_t mMatricesPerInstance; //number of bone matrices per instance
size_t mNumWorldMatrices; //Num bones * num instances
TexturePtr mMatrixTexture; //The VTF
//Used when all matrices from each instance must be in the same row (i.e. HW Instancing).
//A few pixels are wasted, but resizing the texture puts the danger of not sampling the
//right pixel... (in theory it should work, but in practice doesn't)
size_t mWidthFloatsPadding;
size_t mMaxFloatsPerLine;
size_t mRowLength;
size_t mWeightCount;
//Temporary array used to store 3x4 matrices before they are converted to dual quaternions
float* mTempTransformsArray3x4;
// The state of the usage of bone matrix lookup
bool mUseBoneMatrixLookup;
size_t mMaxLookupTableInstances;
bool mUseBoneDualQuaternions;
bool mForceOneWeight;
bool mUseOneWeight;
void cloneMaterial( const MaterialPtr &material );
void retrieveBoneIdx( VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx );
void retrieveBoneIdxWithWeights(VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx, HWBoneWgtVec &outBoneWgt);
void setupMaterialToUseVTF( TextureType textureType, MaterialPtr &material );
void createVertexTexture( const SubMesh* baseSubMesh );
virtual void createVertexSemantics( VertexData *thisVertexData, VertexData *baseVertexData,
const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt) = 0;
size_t convert3x4MatricesToDualQuaternions(float* matrices, size_t numOfMatrices, float* outDualQuaternions);
void updateVertexTexture(void);
virtual bool matricesTogetherPerRow() const = 0;
virtual void updateSharedLookupIndexes();
virtual InstancedEntity* generateInstancedEntity(size_t num);
public:
BaseInstanceBatchVTF( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
const String &batchName);
virtual ~BaseInstanceBatchVTF();
void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
//Renderable overloads
void getWorldTransforms( Matrix4* xform ) const;
unsigned short getNumWorldTransforms(void) const;
void _updateRenderQueue(RenderQueue* queue);
void setBoneMatrixLookup(bool enable, size_t maxLookupTableInstances) { assert(mInstancedEntities.empty());
mUseBoneMatrixLookup = enable; mMaxLookupTableInstances = maxLookupTableInstances; }
bool useBoneMatrixLookup() const { return mUseBoneMatrixLookup; }
void setBoneDualQuaternions(bool enable) { assert(mInstancedEntities.empty());
mUseBoneDualQuaternions = enable; mRowLength = (mUseBoneDualQuaternions ? 2 : 3); }
bool useBoneDualQuaternions() const { return mUseBoneDualQuaternions; }
void setForceOneWeight(bool enable) { assert(mInstancedEntities.empty());
mForceOneWeight = enable; }
bool forceOneWeight() const { return mForceOneWeight; }
void setUseOneWeight(bool enable) { assert(mInstancedEntities.empty());
mUseOneWeight = enable; }
bool useOneWeight() const { return mUseOneWeight; }
virtual bool useBoneWorldMatrices() const { return !mUseBoneMatrixLookup; }
virtual size_t getMaxLookupTableInstances() const { return mMaxLookupTableInstances; }
};
class _OgreExport InstanceBatchVTF : public BaseInstanceBatchVTF
{
void setupVertices( const SubMesh* baseSubMesh );
void setupIndices( const SubMesh* baseSubMesh );
void createVertexSemantics( VertexData *thisVertexData, VertexData *baseVertexData,
const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt );
virtual bool matricesTogetherPerRow() const { return false; }
public:
InstanceBatchVTF( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
const String &batchName);
virtual ~InstanceBatchVTF();
size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const;
};
}
#endif
Ogre::BaseInstanceBatchVTF::mForceOneWeight
bool mForceOneWeight
Definition: OgreInstanceBatchVTF.h:101
Ogre::BaseInstanceBatchVTF::mNumWorldMatrices
size_t mNumWorldMatrices
Definition: OgreInstanceBatchVTF.h:82
Ogre::BaseInstanceBatchVTF::forceOneWeight
bool forceOneWeight() const
Definition: OgreInstanceBatchVTF.h:189
Ogre::BaseInstanceBatchVTF::useOneWeight
bool useOneWeight() const
Definition: OgreInstanceBatchVTF.h:194
Ogre::BaseInstanceBatchVTF::useBoneWorldMatrices
virtual bool useBoneWorldMatrices() const
Definition: OgreInstanceBatchVTF.h:197
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::BaseInstanceBatchVTF::mTempTransformsArray3x4
float * mTempTransformsArray3x4
Definition: OgreInstanceBatchVTF.h:94
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
Ogre::VertexData
Summary class collecting together vertex source information.
Definition: OgreVertexIndexData.h:49
Ogre::BaseInstanceBatchVTF::mMatricesPerInstance
size_t mMatricesPerInstance
Definition: OgreInstanceBatchVTF.h:81
Ogre::BaseInstanceBatchVTF::mMaxFloatsPerLine
size_t mMaxFloatsPerLine
Definition: OgreInstanceBatchVTF.h:89
Ogre::RenderQueue
Class to manage the scene object rendering queue.
Definition: OgreRenderQueue.h:92
Ogre::BaseInstanceBatchVTF::HWBoneWgtVec
vector< float >::type HWBoneWgtVec
Definition: OgreInstanceBatchVTF.h:78
Ogre::BaseInstanceBatchVTF::setUseOneWeight
void setUseOneWeight(bool enable)
Definition: OgreInstanceBatchVTF.h:191
Ogre::BaseInstanceBatchVTF::setForceOneWeight
void setForceOneWeight(bool enable)
Definition: OgreInstanceBatchVTF.h:186
Ogre::InstanceBatchVTF::matricesTogetherPerRow
virtual bool matricesTogetherPerRow() const
Affects VTF texture&#39;s width dimension.
Definition: OgreInstanceBatchVTF.h:214
Ogre::SubMesh
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:62
Ogre::BaseInstanceBatchVTF::mMaxLookupTableInstances
size_t mMaxLookupTableInstances
Definition: OgreInstanceBatchVTF.h:98
Ogre::Matrix4
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
Ogre::BaseInstanceBatchVTF::mUseBoneMatrixLookup
bool mUseBoneMatrixLookup
Definition: OgreInstanceBatchVTF.h:97
Ogre::BaseInstanceBatchVTF::mWeightCount
size_t mWeightCount
Definition: OgreInstanceBatchVTF.h:92
OgreTexture.h
Ogre::BaseInstanceBatchVTF::mMatrixTexture
TexturePtr mMatrixTexture
Definition: OgreInstanceBatchVTF.h:83
Ogre::InstanceBatchVTF
Definition: OgreInstanceBatchVTF.h:204
Ogre::BaseInstanceBatchVTF::mWidthFloatsPadding
size_t mWidthFloatsPadding
Definition: OgreInstanceBatchVTF.h:88
Ogre::BaseInstanceBatchVTF::mRowLength
size_t mRowLength
Definition: OgreInstanceBatchVTF.h:91
Ogre::TextureType
TextureType
Enum identifying the texture type.
Definition: OgreTexture.h:67
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::BaseInstanceBatchVTF::useBoneDualQuaternions
bool useBoneDualQuaternions() const
Definition: OgreInstanceBatchVTF.h:184
Ogre::InstanceManager
This is the main starting point for the new instancing system.
Definition: OgreInstanceManager.h:63
Ogre::BaseInstanceBatchVTF::setBoneDualQuaternions
void setBoneDualQuaternions(bool enable)
Definition: OgreInstanceBatchVTF.h:181
Ogre::BaseInstanceBatchVTF::mUseOneWeight
bool mUseOneWeight
Definition: OgreInstanceBatchVTF.h:102
OgreInstanceBatch.h
Ogre::InstanceBatch
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
Definition: OgreInstanceBatch.h:88
Ogre::BaseInstanceBatchVTF::useBoneMatrixLookup
bool useBoneMatrixLookup() const
Tells whether to use bone matrix lookup.
Definition: OgreInstanceBatchVTF.h:179
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::SharedPtr< Texture >
Ogre::BaseInstanceBatchVTF::mUseBoneDualQuaternions
bool mUseBoneDualQuaternions
Definition: OgreInstanceBatchVTF.h:100
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::BaseInstanceBatchVTF::getMaxLookupTableInstances
virtual size_t getMaxLookupTableInstances() const
Definition: OgreInstanceBatchVTF.h:200
Ogre::BaseInstanceBatchVTF::HWBoneIdxVec
vector< uint8 >::type HWBoneIdxVec
Definition: OgreInstanceBatchVTF.h:77
Ogre::BaseInstanceBatchVTF
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) This implementation...
Definition: OgreInstanceBatchVTF.h:74
Ogre::RenderOperation
&#39;New&#39; rendering operation using vertex buffers.
Definition: OgreRenderOperation.h:45
Ogre::BaseInstanceBatchVTF::setBoneMatrixLookup
void setBoneMatrixLookup(bool enable, size_t maxLookupTableInstances)
Sets the state of the usage of bone matrix lookup.
Definition: OgreInstanceBatchVTF.h:173
Ogre::Mesh::IndexMap
vector< unsigned short >::type IndexMap
Definition: OgreMesh.h:108
Ogre::InstancedEntity
Definition: OgreInstancedEntity.h:77
Ogre::BaseInstanceBatchVTF::Matrix4Vec
vector< Matrix4 >::type Matrix4Vec
Definition: OgreInstanceBatchVTF.h:79
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.