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 
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 
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
virtual bool useBoneWorldMatrices() const
#define _OgreExport
Definition: OgrePlatform.h:257
std::vector< T, A > type
Summary class collecting together vertex source information.
Class to manage the scene object rendering queue.
vector< float >::type HWBoneWgtVec
virtual bool matricesTogetherPerRow() const
Affects VTF texture&#39;s width dimension.
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:62
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
TextureType
Enum identifying the texture type.
Definition: OgreTexture.h:67
_StringBase String
This is the main starting point for the new instancing system.
void setBoneDualQuaternions(bool enable)
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
bool useBoneMatrixLookup() const
Tells whether to use bone matrix lookup.
virtual size_t getMaxLookupTableInstances() const
vector< uint8 >::type HWBoneIdxVec
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) This implementation...
&#39;New&#39; rendering operation using vertex buffers.
void setBoneMatrixLookup(bool enable, size_t maxLookupTableInstances)
Sets the state of the usage of bone matrix lookup.
vector< unsigned short >::type IndexMap
Definition: OgreMesh.h:108
vector< Matrix4 >::type Matrix4Vec
unsigned short uint16
Definition: OgrePlatform.h:360

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 Sun Oct 9 2016 22:12:53