OGRE  1.9.0
OgreInstanceBatchVTF.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __BaseInstanceBatchVTF_H__
29#define __BaseInstanceBatchVTF_H__
30
31#include "OgreInstanceBatch.h"
32#include "OgreTexture.h"
33
34namespace 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;
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
114
120
123
126
129 const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt) = 0;
130
132
135
137 virtual bool matricesTogetherPerRow() const = 0;
138
141
144
145 public:
148 const String &batchName);
150
153
154 //Renderable overloads
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
209
213
214 virtual bool matricesTogetherPerRow() const { return false; }
215 public:
218 const String &batchName);
220
222 size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const;
223 };
224}
225
226#endif
#define _OgreExport
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
'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.
virtual InstancedEntity * generateInstancedEntity(size_t num)
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.
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
_StringBase String
std::vector< T, A > type