OgreInstanceBatchVTF.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __BaseInstanceBatchVTF_H__
29 #define __BaseInstanceBatchVTF_H__
30 
31 #include "OgreInstanceBatch.h"
32 #include "OgreTexture.h"
33 
34 namespace Ogre
35 {
74  class _OgreExport BaseInstanceBatchVTF : public InstanceBatch
75  {
76  protected:
80 
81  size_t mMatricesPerInstance; //number of bone matrices per instance
82  size_t mNumWorldMatrices; //Num bones * num instances
84 
85  //Used when all matrices from each instance must be in the same row (i.e. HW Instancing).
86  //A few pixels are wasted, but resizing the texture puts the danger of not sampling the
87  //right pixel... (in theory it should work, but in practice doesn't)
90 
91  size_t mRowLength;
92  size_t mWeightCount;
93  //Temporary array used to store 3x4 matrices before they are converted to dual quaternions
95 
96  // The state of the usage of bone matrix lookup
99 
103 
107  void cloneMaterial( const MaterialPtr &material );
108 
113  void retrieveBoneIdx( VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx );
114 
119  void retrieveBoneIdxWithWeights(VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx, HWBoneWgtVec &outBoneWgt);
120 
122  void setupMaterialToUseVTF( TextureType textureType, MaterialPtr &material );
123 
125  void createVertexTexture( const SubMesh* baseSubMesh );
126 
128  virtual void createVertexSemantics( VertexData *thisVertexData, VertexData *baseVertexData,
129  const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt) = 0;
130 
131  size_t convert3x4MatricesToDualQuaternions(float* matrices, size_t numOfMatrices, float* outDualQuaternions);
132 
134  void updateVertexTexture(void);
135 
137  virtual bool matricesTogetherPerRow() const = 0;
138 
140  virtual void updateSharedLookupIndexes();
141 
143  virtual InstancedEntity* generateInstancedEntity(size_t num);
144 
145  public:
146  BaseInstanceBatchVTF( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
147  size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
148  const String &batchName);
149  virtual ~BaseInstanceBatchVTF();
150 
152  void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
153 
154  //Renderable overloads
155  void getWorldTransforms( Matrix4* xform ) const;
156  unsigned short getNumWorldTransforms(void) const;
157 
159  void _updateRenderQueue(RenderQueue* queue);
160 
173  void setBoneMatrixLookup(bool enable, size_t maxLookupTableInstances) { assert(mInstancedEntities.empty());
174  mUseBoneMatrixLookup = enable; mMaxLookupTableInstances = maxLookupTableInstances; }
175 
179  bool useBoneMatrixLookup() const { return mUseBoneMatrixLookup; }
180 
181  void setBoneDualQuaternions(bool enable) { assert(mInstancedEntities.empty());
182  mUseBoneDualQuaternions = enable; mRowLength = (mUseBoneDualQuaternions ? 2 : 3); }
183 
184  bool useBoneDualQuaternions() const { return mUseBoneDualQuaternions; }
185 
186  void setForceOneWeight(bool enable) { assert(mInstancedEntities.empty());
187  mForceOneWeight = enable; }
188 
189  bool forceOneWeight() const { return mForceOneWeight; }
190 
191  void setUseOneWeight(bool enable) { assert(mInstancedEntities.empty());
192  mUseOneWeight = enable; }
193 
194  bool useOneWeight() const { return mUseOneWeight; }
195 
197  virtual bool useBoneWorldMatrices() const { return !mUseBoneMatrixLookup; }
198 
200  virtual size_t getMaxLookupTableInstances() const { return mMaxLookupTableInstances; }
201 
202  };
203 
204  class _OgreExport InstanceBatchVTF : public BaseInstanceBatchVTF
205  {
206 
207  void setupVertices( const SubMesh* baseSubMesh );
208  void setupIndices( const SubMesh* baseSubMesh );
209 
211  void createVertexSemantics( VertexData *thisVertexData, VertexData *baseVertexData,
212  const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt );
213 
214  virtual bool matricesTogetherPerRow() const { return false; }
215  public:
216  InstanceBatchVTF( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
217  size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
218  const String &batchName);
219  virtual ~InstanceBatchVTF();
220 
222  size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const;
223  };
224 }
225 
226 #endif
Ogre::Mesh::IndexMap
vector< unsigned short >::type IndexMap
Definition: OgreMesh.h:108
Ogre::BaseInstanceBatchVTF::forceOneWeight
bool forceOneWeight() const
Definition: OgreInstanceBatchVTF.h:189
Ogre::BaseInstanceBatchVTF::Matrix4Vec
vector< Matrix4 >::type Matrix4Vec
Definition: OgreInstanceBatchVTF.h:79
Ogre::BaseInstanceBatchVTF::HWBoneWgtVec
vector< float >::type HWBoneWgtVec
Definition: OgreInstanceBatchVTF.h:78
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::BaseInstanceBatchVTF::mForceOneWeight
bool mForceOneWeight
Definition: OgreInstanceBatchVTF.h:101
Ogre::BaseInstanceBatchVTF::setBoneDualQuaternions
void setBoneDualQuaternions(bool enable)
Definition: OgreInstanceBatchVTF.h:181
Ogre::BaseInstanceBatchVTF::mRowLength
size_t mRowLength
Definition: OgreInstanceBatchVTF.h:91
Ogre::InstanceManager
This is the main starting point for the new instancing system.
Definition: OgreInstanceManager.h:63
Ogre::BaseInstanceBatchVTF::mMatrixTexture
TexturePtr mMatrixTexture
Definition: OgreInstanceBatchVTF.h:83
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::BaseInstanceBatchVTF::mMatricesPerInstance
size_t mMatricesPerInstance
Definition: OgreInstanceBatchVTF.h:81
Ogre::BaseInstanceBatchVTF::mTempTransformsArray3x4
float * mTempTransformsArray3x4
Definition: OgreInstanceBatchVTF.h:94
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::BaseInstanceBatchVTF::setUseOneWeight
void setUseOneWeight(bool enable)
Definition: OgreInstanceBatchVTF.h:191
Ogre::BaseInstanceBatchVTF::setForceOneWeight
void setForceOneWeight(bool enable)
Definition: OgreInstanceBatchVTF.h:186
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::VertexData
Summary class collecting together vertex source information.
Definition: OgreVertexIndexData.h:49
Ogre::BaseInstanceBatchVTF::mUseBoneDualQuaternions
bool mUseBoneDualQuaternions
Definition: OgreInstanceBatchVTF.h:100
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
Ogre::BaseInstanceBatchVTF::mMaxFloatsPerLine
size_t mMaxFloatsPerLine
Definition: OgreInstanceBatchVTF.h:89
Ogre::Matrix4
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
Ogre::BaseInstanceBatchVTF::mUseBoneMatrixLookup
bool mUseBoneMatrixLookup
Definition: OgreInstanceBatchVTF.h:97
Ogre::BaseInstanceBatchVTF::getMaxLookupTableInstances
virtual size_t getMaxLookupTableInstances() const
Definition: OgreInstanceBatchVTF.h:200
OgreTexture.h
Ogre::SubMesh
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:62
Ogre::BaseInstanceBatchVTF::mWidthFloatsPadding
size_t mWidthFloatsPadding
Definition: OgreInstanceBatchVTF.h:88
Ogre::InstanceBatchVTF
Definition: OgreInstanceBatchVTF.h:204
OgreInstanceBatch.h
Ogre::BaseInstanceBatchVTF::useBoneWorldMatrices
virtual bool useBoneWorldMatrices() const
Definition: OgreInstanceBatchVTF.h:197
Ogre::InstanceBatchVTF::matricesTogetherPerRow
virtual bool matricesTogetherPerRow() const
Affects VTF texture's width dimension.
Definition: OgreInstanceBatchVTF.h:214
Ogre::BaseInstanceBatchVTF::useBoneDualQuaternions
bool useBoneDualQuaternions() const
Definition: OgreInstanceBatchVTF.h:184
Ogre::SharedPtr< Texture >
Ogre::BaseInstanceBatchVTF
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) This implementation...
Definition: OgreInstanceBatchVTF.h:74
Ogre::BaseInstanceBatchVTF::mUseOneWeight
bool mUseOneWeight
Definition: OgreInstanceBatchVTF.h:102
Ogre::BaseInstanceBatchVTF::mMaxLookupTableInstances
size_t mMaxLookupTableInstances
Definition: OgreInstanceBatchVTF.h:98
Ogre::BaseInstanceBatchVTF::useOneWeight
bool useOneWeight() const
Definition: OgreInstanceBatchVTF.h:194
Ogre::BaseInstanceBatchVTF::useBoneMatrixLookup
bool useBoneMatrixLookup() const
Tells whether to use bone matrix lookup.
Definition: OgreInstanceBatchVTF.h:179
Ogre::BaseInstanceBatchVTF::mNumWorldMatrices
size_t mNumWorldMatrices
Definition: OgreInstanceBatchVTF.h:82
Ogre::InstanceBatch
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
Definition: OgreInstanceBatch.h:88
Ogre::TextureType
TextureType
Enum identifying the texture type.
Definition: OgreTexture.h:67
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::BaseInstanceBatchVTF::mWeightCount
size_t mWeightCount
Definition: OgreInstanceBatchVTF.h:92
Ogre::InstancedEntity
Definition: OgreInstancedEntity.h:77
Ogre::RenderOperation
'New' rendering operation using vertex buffers.
Definition: OgreRenderOperation.h:45
Ogre::RenderQueue
Class to manage the scene object rendering queue.
Definition: OgreRenderQueue.h:92
Ogre::BaseInstanceBatchVTF::HWBoneIdxVec
vector< uint8 >::type HWBoneIdxVec
Definition: OgreInstanceBatchVTF.h:77

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Tue Apr 13 2021 08:53:15