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 {
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 
135 
137  virtual bool matricesTogetherPerRow() const = 0;
138 
141 
144 
145  public:
146  BaseInstanceBatchVTF( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
147  size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
148  const String &batchName);
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 
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 
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
#define _OgreExport
Definition: OgrePlatform.h:257
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) This implementation...
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
This is the main starting point for the new instancing system.
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
vector< unsigned short >::type IndexMap
Definition: OgreMesh.h:108
'New' rendering operation using vertex buffers.
Class to manage the scene object rendering queue.
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:63
Summary class collecting together vertex source information.
TextureType
Enum identifying the texture type.
Definition: OgreTexture.h:68
size_t calculateMaxNumInstances(const SubMesh *baseSubMesh, uint16 flags) const
void retrieveBoneIdxWithWeights(VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx, HWBoneWgtVec &outBoneWgt)
void retrieveBoneIdx(VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx)
Retrieves bone data from the original sub mesh and puts it into an appropriate buffer,...
void cloneMaterial(const MaterialPtr &material)
Clones the base material so it can have it's own vertex texture, and also clones it's shadow caster m...
unsigned short getNumWorldTransforms(void) const
Returns the number of world transform matrices this renderable requires.
void createVertexSemantics(VertexData *thisVertexData, VertexData *baseVertexData, const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt)
Creates 2 TEXCOORD semantics that will be used to sample the vertex texture.
virtual void createVertexSemantics(VertexData *thisVertexData, VertexData *baseVertexData, const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt)=0
Creates 2 TEXCOORD semantics that will be used to sample the vertex texture.
virtual bool useBoneWorldMatrices() const
virtual size_t getMaxLookupTableInstances() const
vector< Matrix4 >::type Matrix4Vec
bool useBoneMatrixLookup() const
Tells whether to use bone matrix lookup.
void setBoneMatrixLookup(bool enable, size_t maxLookupTableInstances)
Sets the state of the usage of bone matrix lookup.
void setBoneDualQuaternions(bool enable)
void setupMaterialToUseVTF(TextureType textureType, MaterialPtr &material)
Setups the material to use a vertex texture.
virtual void updateSharedLookupIndexes()
update the lookup numbers for entities with shared transforms
vector< float >::type HWBoneWgtVec
virtual bool matricesTogetherPerRow() const
Affects VTF texture's width dimension.
BaseInstanceBatchVTF(InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material, size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap, const String &batchName)
vector< uint8 >::type HWBoneIdxVec
InstanceBatchVTF(InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material, size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap, const String &batchName)
void setupVertices(const SubMesh *baseSubMesh)
void getWorldTransforms(Matrix4 *xform) const
Gets the world transform matrix / matrices for this renderable object.
virtual InstancedEntity * generateInstancedEntity(size_t num)
void setupIndices(const SubMesh *baseSubMesh)
void buildFrom(const SubMesh *baseSubMesh, const RenderOperation &renderOperation)
void updateVertexTexture(void)
Keeps filling the VTF with world matrix data.
virtual bool matricesTogetherPerRow() const =0
Affects VTF texture's width dimension.
void _updateRenderQueue(RenderQueue *queue)
Overloaded to be able to updated the vertex texture.
void createVertexTexture(const SubMesh *baseSubMesh)
Creates the vertex texture.
size_t convert3x4MatricesToDualQuaternions(float *matrices, size_t numOfMatrices, float *outDualQuaternions)
unsigned short uint16
Definition: OgrePlatform.h:360
_StringBase String
std::vector< T, A > type

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