OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2014 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:
79 
80  size_t mMatricesPerInstance; //number of bone matrices per instance
81  size_t mNumWorldMatrices; //Num bones * num instances
83 
84  //Used when all matrices from each instance must be in the same row (i.e. HW Instancing).
85  //A few pixels are wasted, but resizing the texture puts the danger of not sampling the
86  //right pixel... (in theory it should work, but in practice doesn't)
89 
90  size_t mRowLength;
91  size_t mWeightCount;
92  //Temporary array used to store 3x4 matrices before they are converted to dual quaternions
94 
95  // The state of the usage of bone matrix lookup
97 
101 
105  void cloneMaterial( const MaterialPtr &material );
106 
111  void retrieveBoneIdx( VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx );
112 
117  void retrieveBoneIdxWithWeights(VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx, HWBoneWgtVec &outBoneWgt);
118 
120  void setupMaterialToUseVTF( TextureType textureType, MaterialPtr &material );
121 
123  void createVertexTexture( const SubMesh* baseSubMesh );
124 
126  virtual void createVertexSemantics( VertexData *thisVertexData, VertexData *baseVertexData,
127  const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt) = 0;
128 
129  size_t convert3x4MatricesToDualQuaternions(float* matrices, size_t numOfMatrices, float* outDualQuaternions);
130 
132  void updateVertexTexture(void);
133 
135  virtual bool matricesTogetherPerRow() const = 0;
136 
138  virtual void updateSharedLookupIndexes();
139 
141  virtual InstancedEntity* generateInstancedEntity(size_t num);
142 
143  public:
144  BaseInstanceBatchVTF( IdType id, ObjectMemoryManager *objectMemoryManager,
145  InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
146  size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap );
147  virtual ~BaseInstanceBatchVTF();
148 
150  void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
151 
152  //Renderable overloads
153  void getWorldTransforms( Matrix4* xform ) const;
154  unsigned short getNumWorldTransforms(void) const;
155 
157  void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera);
158 
171  void setBoneMatrixLookup(bool enable, size_t maxLookupTableInstances)
172  {
173  assert(mInstancedEntities.empty());
174  mTechnSupportsSkeletal = enable ? SKELETONS_LUT : SKELETONS_SUPPORTED;
175  mMaxLookupTableInstances = maxLookupTableInstances;
176  }
177 
181  bool useBoneMatrixLookup() const { return mTechnSupportsSkeletal == SKELETONS_LUT; }
182 
183  void setBoneDualQuaternions(bool enable) { assert(mInstancedEntities.empty());
184  mUseBoneDualQuaternions = enable; mRowLength = (mUseBoneDualQuaternions ? 2 : 3); }
185 
186  bool useBoneDualQuaternions() const { return mUseBoneDualQuaternions; }
187 
188  void setForceOneWeight(bool enable) { assert(mInstancedEntities.empty());
189  mForceOneWeight = enable; }
190 
191  bool forceOneWeight() const { return mForceOneWeight; }
192 
193  void setUseOneWeight(bool enable) { assert(mInstancedEntities.empty());
194  mUseOneWeight = enable; }
195 
196  bool useOneWeight() const { return mUseOneWeight; }
197 
199  virtual size_t getMaxLookupTableInstances() const { return mMaxLookupTableInstances; }
200 
201  };
202 
204  {
205 
206  void setupVertices( const SubMesh* baseSubMesh );
207  void setupIndices( const SubMesh* baseSubMesh );
208 
210  void createVertexSemantics( VertexData *thisVertexData, VertexData *baseVertexData,
211  const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt );
212 
213  virtual bool matricesTogetherPerRow() const { return false; }
214  public:
215  InstanceBatchVTF( IdType id, ObjectMemoryManager *objectMemoryManager, InstanceManager *creator,
216  MeshPtr &meshReference, const MaterialPtr &material,
217  size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap );
218  virtual ~InstanceBatchVTF();
219 
221  size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const;
222  };
223 }
224 
225 #endif
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
#define _OgreExport
Definition: OgrePlatform.h:255
std::vector< T, A > type
virtual size_t getMaxLookupTableInstances() const
vector< uint8 >::type HWBoneIdxVec
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
virtual bool matricesTogetherPerRow() const
Affects VTF texture's width dimension.
Ogre::uint32 IdType
Big projects with lots, lots of units for very long periods of time (MMORPGs?) may want to define thi...
Definition: OgreId.h:36
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:60
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.
Summary class collecting together vertex source information.
'New' rendering operation using vertex buffers.
Instancing implementation using vertex texture through Vertex Texture Fetch (VTF) This implementation...
TextureType
Enum identifying the texture type.
Definition: OgreTexture.h:76
Class to manage the scene object rendering queue.
This is the main starting point for the new instancing system.
unsigned short uint16
Definition: OgrePlatform.h:421
void setBoneDualQuaternions(bool enable)
vector< float >::type HWBoneWgtVec
void setBoneMatrixLookup(bool enable, size_t maxLookupTableInstances)
Sets the state of the usage of bone matrix lookup.