/usr/include/OGRE/OgreInstanceBatchVTF.h is in libogre-1.8-dev 1.8.0+dfsg1-7+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | /*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2012 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __BaseInstanceBatchVTF_H__
#define __BaseInstanceBatchVTF_H__
#include "OgreInstanceBatch.h"
#include "OgreTexture.h"
namespace Ogre
{
/** \addtogroup Core
* @{
*/
/** \addtogroup Scene
* @{
*/
/** Instancing implementation using vertex texture through Vertex Texture Fetch (VTF)
This implementation has the following advantages:
* Supports huge amount of instances per batch
* Supports skinning even with huge ammounts of instances per batch
* Doesn't need shader constants registers.
* Best suited for skinned entities
But beware the disadvantages:
* VTF is only fast on modern GPUs (ATI Radeon HD 2000+, GeForce 8+ series onwards)
* On GeForce 6/7 series VTF is too slow
* VTF isn't (controversely) supported on old ATI X1800 hardware
* Only one bone weight per vertex is supported
* GPUs with low memory bandwidth (i.e. laptops and integrated GPUs)
may perform even worse than no instancing
Whether this performs great or bad depends on the hardware. It improved up to 4x performance on
a Intel Core 2 Quad Core X9650 GeForce 8600 GTS, and in an Intel Core 2 Duo P7350 ATI
Mobility Radeon HD 4650, but went 0.75x slower on an AthlonX2 5000+ integrated nForce 6150 SE
Each BaseInstanceBatchVTF has it's own texture, which occupies memory in VRAM.
Approx VRAM usage can be computed by doing 12 bytes * 3 * numInstances * numBones
Use flag IM_VTFBESTFIT to avoid wasting VRAM (but may reduce amount of instances per batch).
@par
The material requires at least a texture unit stage named "InstancingVTF"
@remarks
Design discussion webpage: http://www.ogre3d.org/forums/viewtopic.php?f=4&t=59902
@author
Matias N. Goldberg ("dark_sylinc")
@version
1.0
*/
class _OgreExport BaseInstanceBatchVTF : public InstanceBatch
{
protected:
typedef vector<uint8>::type HWBoneIdxVec;
typedef vector<float>::type HWBoneWgtVec;
typedef vector<Matrix4>::type Matrix4Vec;
size_t mMatricesPerInstance; //number of bone matrices per instance
size_t mNumWorldMatrices; //Num bones * num instances
TexturePtr mMatrixTexture; //The VTF
//Used when all matrices from each instance must be in the same row (i.e. HW Instancing).
//A few pixels are wasted, but resizing the texture puts the danger of not sampling the
//right pixel... (in theory it should work, but in practice doesn't)
size_t mWidthFloatsPadding;
size_t mMaxFloatsPerLine;
size_t mRowLength;
size_t mWeightCount;
//Temporary array used to store 3x4 matrices before they are converted to dual quaternions
float* mTempTransformsArray3x4;
// The state of the usage of bone matrix lookup
bool mUseBoneMatrixLookup;
size_t mMaxLookupTableInstances;
bool mUseBoneDualQuaternions;
bool mForceOneWeight;
bool mUseOneWeight;
/** Clones the base material so it can have it's own vertex texture, and also
clones it's shadow caster materials, if it has any
*/
void cloneMaterial( const MaterialPtr &material );
/** Retrieves bone data from the original sub mesh and puts it into an appropriate buffer,
later to be read when creating the vertex semantics.
Assumes outBoneIdx has enough space (base submesh vertex count)
*/
void retrieveBoneIdx( VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx );
/** @see retrieveBoneIdx()
Assumes outBoneIdx has enough space (twice the base submesh vertex count, one for each weight)
Assumes outBoneWgt has enough space (twice the base submesh vertex count, one for each weight)
*/
void retrieveBoneIdxWithWeights(VertexData *baseVertexData, HWBoneIdxVec &outBoneIdx, HWBoneWgtVec &outBoneWgt);
/** Setups the material to use a vertex texture */
void setupMaterialToUseVTF( TextureType textureType, MaterialPtr &material );
/** Creates the vertex texture */
void createVertexTexture( const SubMesh* baseSubMesh );
/** 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;
size_t convert3x4MatricesToDualQuaternions(float* matrices, size_t numOfMatrices, float* outDualQuaternions);
/** Keeps filling the VTF with world matrix data */
void updateVertexTexture(void);
/** Affects VTF texture's width dimension */
virtual bool matricesToghetherPerRow() const = 0;
/** update the lookup numbers for entities with shared transforms */
virtual void updateSharedLookupIndexes();
/** @see InstanceBatch::generateInstancedEntity() */
virtual InstancedEntity* generateInstancedEntity(size_t num);
public:
BaseInstanceBatchVTF( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
const String &batchName);
virtual ~BaseInstanceBatchVTF();
/** @see InstanceBatch::buildFrom */
void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
//Renderable overloads
void getWorldTransforms( Matrix4* xform ) const;
unsigned short getNumWorldTransforms(void) const;
/** Overloaded to be able to updated the vertex texture */
void _updateRenderQueue(RenderQueue* queue);
/** Sets the state of the usage of bone matrix lookup
Under default condition each instance entity is assigned a specific area in the vertex
texture for bone matrix data. When turned on the amount of area in the vertex texture
assigned for bone matrix data will be relative to the amount of unique animation states.
Instanced entities sharing the same animation state will share the same area in the matrix.
The specific position of each entity is placed in the vertex data and added in a second phase
in the shader.
Note this feature only works in VTF_HW for now.
This value needs to be set before adding any instanced entities
*/
void setBoneMatrixLookup(bool enable, size_t maxLookupTableInstances) { assert(mInstancedEntities.empty());
mUseBoneMatrixLookup = enable; mMaxLookupTableInstances = maxLookupTableInstances; }
/** Tells whether to use bone matrix lookup
@see setBoneMatrixLookup()
*/
bool useBoneMatrixLookup() const { return mUseBoneMatrixLookup; }
void setBoneDualQuaternions(bool enable) { assert(mInstancedEntities.empty());
mUseBoneDualQuaternions = enable; mRowLength = (mUseBoneDualQuaternions ? 2 : 3); }
bool useBoneDualQuaternions() const { return mUseBoneDualQuaternions; }
void setForceOneWeight(bool enable) { assert(mInstancedEntities.empty());
mForceOneWeight = enable; }
bool forceOneWeight() const { return mForceOneWeight; }
void setUseOneWeight(bool enable) { assert(mInstancedEntities.empty());
mUseOneWeight = enable; }
bool useOneWeight() const { return mUseOneWeight; }
/** @see InstanceBatch::useBoneWorldMatrices() */
virtual bool useBoneWorldMatrices() const { return !mUseBoneMatrixLookup; }
/** @return the maximum amount of shared transform entities when using lookup table*/
virtual size_t getMaxLookupTableInstances() const { return mMaxLookupTableInstances; }
};
class _OgreExport InstanceBatchVTF : public BaseInstanceBatchVTF
{
void setupVertices( const SubMesh* baseSubMesh );
void setupIndices( const SubMesh* baseSubMesh );
/** Creates 2 TEXCOORD semantics that will be used to sample the vertex texture */
void createVertexSemantics( VertexData *thisVertexData, VertexData *baseVertexData,
const HWBoneIdxVec &hwBoneIdx, const HWBoneWgtVec &hwBoneWgt );
virtual bool matricesToghetherPerRow() const { return false; }
public:
InstanceBatchVTF( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
const String &batchName);
virtual ~InstanceBatchVTF();
/** @see InstanceBatch::calculateMaxNumInstances */
size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const;
};
}
#endif
|