OgreInstanceBatch.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 __InstanceBatch_H__
29 #define __InstanceBatch_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreRenderOperation.h"
33 #include "OgreRenderable.h"
34 #include "OgreMovableObject.h"
35 #include "OgreMesh.h"
36 #include "OgreHeaderPrefix.h"
37 
38 namespace Ogre
39 {
89  {
90  public:
93  protected:
96 
98 
100 
103 
104  //InstancedEntities are all allocated at build time and kept as "unused"
105  //when they're requested, they're removed from there when requested,
106  //and put back again when they're no longer needed
107  //Note each InstancedEntity has a unique ID ranging from [0; mInstancesPerBatch)
110 
115 
120  bool mBoundsUpdated; //Set to false by derived classes that need it
122 
123  unsigned short mMaterialLodIndex;
124 
125  bool mDirtyAnimation; //Set to false at start of each _updateRenderQueue
126 
129 
133  mutable const Camera *mCachedCamera;
134 
137 
142 
143  virtual void setupVertices( const SubMesh* baseSubMesh ) = 0;
144  virtual void setupIndices( const SubMesh* baseSubMesh ) = 0;
145  virtual void createAllInstancedEntities(void);
146  virtual void deleteAllInstancedEntities(void);
147  virtual void deleteUnusedInstancedEntities(void);
150 
155  void makeMatrixCameraRelative3x4( float *mat3x4, size_t numFloats );
156 
158  virtual bool checkSubMeshCompatibility( const SubMesh* baseSubMesh );
159 
160  void updateVisibility(void);
161 
163  void defragmentBatchNoCull( InstancedEntityVec &usedEntities, CustomParamsVec &usedParams );
164 
170  void defragmentBatchDoCull( InstancedEntityVec &usedEntities, CustomParamsVec &usedParams );
171 
172  public:
173  InstanceBatch( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
174  size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
175  const String &batchName );
176  virtual ~InstanceBatch();
177 
178  MeshPtr& _getMeshRef() { return mMeshReference; }
179 
182  void _setInstancesPerBatch( size_t instancesPerBatch );
183 
184  const Mesh::IndexMap* _getIndexToBoneMap() const { return mIndexToBoneMap; }
185 
192  bool _supportsSkeletalAnimation() const { return mTechnSupportsSkeletal; }
193 
195  void _updateBounds(void);
196 
207  virtual size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const = 0;
208 
222  virtual RenderOperation build( const SubMesh* baseSubMesh );
223 
236  virtual void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
237 
238  const Ogre::MeshPtr& _getMeshReference(void) const { return mMeshReference; }
239 
243  bool isBatchFull(void) const { return mUnusedEntities.empty(); }
244 
247  bool isBatchUnused(void) const { return mUnusedEntities.size() == mInstancedEntities.size(); }
248 
253 
267  void _defragmentBatch( bool optimizeCulling, InstancedEntityVec &usedEntities,
268  CustomParamsVec &usedParams );
269 
276 
280  virtual void _boundsDirty(void);
281 
295  virtual void setStaticAndUpdate( bool bStatic ) {}
296 
299  virtual bool isStatic() const { return false; }
300 
308 
315  void removeInstancedEntity( InstancedEntity *instancedEntity );
316 
320  virtual bool useBoneWorldMatrices() const { return true; }
321 
323  void _markTransformSharingDirty() { mTransformSharingDirty = true; }
324 
326  void _setCustomParam( InstancedEntity *instancedEntity, unsigned char idx, const Vector4 &newParam );
327 
329  const Vector4& _getCustomParam( InstancedEntity *instancedEntity, unsigned char idx );
330 
331  //Renderable overloads
333  const MaterialPtr& getMaterial(void) const { return mMaterial; }
335  void getRenderOperation( RenderOperation& op ) { op = mRenderOperation; }
336 
338  Real getSquaredViewDepth( const Camera* cam ) const;
340  const LightList& getLights( void ) const;
342  Technique* getTechnique(void) const;
343 
345  const String& getMovableType(void) const;
349  const AxisAlignedBox& getBoundingBox(void) const;
351  Real getBoundingRadius(void) const;
352 
353  virtual void _updateRenderQueue(RenderQueue* queue);
354  void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false );
355 
356  // resolve ambiguity of get/setUserAny due to inheriting from Renderable and MovableObject
359  };
360 } // namespace Ogre
361 
362 #include "OgreHeaderSuffix.h"
363 
364 #endif // __InstanceBatch_H__
OgreHeaderSuffix.h
Ogre::HashedVector< Light * >
Ogre::Mesh::IndexMap
vector< unsigned short >::type IndexMap
Definition: OgreMesh.h:108
Ogre::InstanceBatch::mRenderOperation
RenderOperation mRenderOperation
Definition: OgreInstanceBatch.h:94
Ogre::InstanceBatch::useBoneWorldMatrices
virtual bool useBoneWorldMatrices() const
Tells whether world bone matrices need to be calculated.
Definition: OgreInstanceBatch.h:320
Ogre::InstanceBatch::deleteUnusedInstancedEntities
virtual void deleteUnusedInstancedEntities(void)
Ogre::InstanceBatch::isBatchUnused
bool isBatchUnused(void) const
Returns true if it no instanced entity has been requested or all of them have been removed.
Definition: OgreInstanceBatch.h:247
Ogre
Definition: OgreAndroidLogListener.h:35
Ogre::InstanceBatch::generateInstancedEntity
virtual InstancedEntity * generateInstancedEntity(size_t num)
Creates a new InstancedEntity instance.
Ogre::InstanceBatch::mBoundsDirty
bool mBoundsDirty
Definition: OgreInstanceBatch.h:119
OgreMesh.h
Ogre::Camera
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:87
Ogre::InstanceBatch::_boundsDirty
virtual void _boundsDirty(void)
Called by InstancedEntity(s) to tell us we need to update the bounds (we touch the SceneNode so the S...
Ogre::InstanceBatch::_defragmentBatch
void _defragmentBatch(bool optimizeCulling, InstancedEntityVec &usedEntities, CustomParamsVec &usedParams)
Ogre::InstanceBatch::CustomParamsVec
vector< Vector4 >::type CustomParamsVec
Definition: OgreInstanceBatch.h:92
Ogre::InstanceManager
This is the main starting point for the new instancing system.
Definition: OgreInstanceManager.h:64
Ogre::InstanceBatch::removeInstancedEntity
void removeInstancedEntity(InstancedEntity *instancedEntity)
Removes an InstancedEntity from the scene retrieved with getNewInstancedEntity, putting back into a q...
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::MovableObject
Abstract class defining a movable object in a scene.
Definition: OgreMovableObject.h:61
Ogre::InstanceBatch::mIndexToBoneMap
Mesh::IndexMap const * mIndexToBoneMap
Definition: OgreInstanceBatch.h:102
Ogre::InstanceBatch::mCurrentCamera
Camera * mCurrentCamera
Definition: OgreInstanceBatch.h:121
Ogre::InstanceBatch::_supportsSkeletalAnimation
bool _supportsSkeletalAnimation() const
Returns true if this technique supports skeletal animation.
Definition: OgreInstanceBatch.h:192
Ogre::InstanceBatch::~InstanceBatch
virtual ~InstanceBatch()
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::InstanceBatch::setupIndices
virtual void setupIndices(const SubMesh *baseSubMesh)=0
Ogre::Technique
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:54
Ogre::InstanceBatch::getTechnique
Technique * getTechnique(void) const
Ogre::InstanceBatch::mDirtyAnimation
bool mDirtyAnimation
Definition: OgreInstanceBatch.h:125
Ogre::InstanceBatch::calculateMaxNumInstances
virtual size_t calculateMaxNumInstances(const SubMesh *baseSubMesh, uint16 flags) const =0
Some techniques have a limit on how many instances can be done.
Ogre::InstanceBatch::getBoundingBox
const AxisAlignedBox & getBoundingBox(void) const
Ogre::InstanceBatch::buildFrom
virtual void buildFrom(const SubMesh *baseSubMesh, const RenderOperation &renderOperation)
Instancing consumes significantly more GPU memory than regular rendering methods.
Ogre::InstanceBatch::mRemoveOwnVertexData
bool mRemoveOwnVertexData
When true remove the memory of the VertexData we've created because no one else will.
Definition: OgreInstanceBatch.h:139
OgreRenderOperation.h
OgreHeaderPrefix.h
Ogre::InstanceBatch::mCreator
InstanceManager * mCreator
Definition: OgreInstanceBatch.h:97
Ogre::InstanceBatch::makeMatrixCameraRelative3x4
void makeMatrixCameraRelative3x4(float *mat3x4, size_t numFloats)
Takes an array of 3x4 matrices and makes it camera relative.
Ogre::InstanceBatch::updateVisibility
void updateVisibility(void)
OgrePrerequisites.h
Ogre::SubMesh
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:63
Ogre::InstanceBatch::mUnusedEntities
InstancedEntityVec mUnusedEntities
Definition: OgreInstanceBatch.h:109
Ogre::InstanceBatch::mBoundsUpdated
bool mBoundsUpdated
Definition: OgreInstanceBatch.h:120
Ogre::InstanceBatch::_defragmentBatchDiscard
void _defragmentBatchDiscard(void)
Ogre::InstanceBatch::visitRenderables
void visitRenderables(Renderable::Visitor *visitor, bool debugRenderables=false)
Method to allow a caller to abstractly iterate over the Renderable instances that this MovableObject ...
Ogre::InstanceBatch::mInstancedEntities
InstancedEntityVec mInstancedEntities
Definition: OgreInstanceBatch.h:108
Ogre::InstanceBatch::_getMeshReference
const Ogre::MeshPtr & _getMeshReference(void) const
Definition: OgreInstanceBatch.h:238
Ogre::Renderable::getUserAny
virtual OGRE_DEPRECATED const Any & getUserAny(void) const
Definition: OgreRenderable.h:349
Ogre::InstanceBatch::_getMeshRef
MeshPtr & _getMeshRef()
Definition: OgreInstanceBatch.h:178
Ogre::InstanceBatch::_setInstancesPerBatch
void _setInstancesPerBatch(size_t instancesPerBatch)
Raises an exception if trying to change it after being built.
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:55
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::InstanceBatch::InstanceBatch
InstanceBatch(InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material, size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap, const String &batchName)
Ogre::InstanceBatch::isBatchFull
bool isBatchFull(void) const
Definition: OgreInstanceBatch.h:243
Ogre::InstanceBatch::mMeshReference
MeshPtr mMeshReference
Definition: OgreInstanceBatch.h:101
Ogre::InstanceBatch::mMaterialLodIndex
unsigned short mMaterialLodIndex
Definition: OgreInstanceBatch.h:123
Ogre::InstanceBatch::defragmentBatchNoCull
void defragmentBatchNoCull(InstancedEntityVec &usedEntities, CustomParamsVec &usedParams)
Ogre::InstanceBatch::createAllInstancedEntities
virtual void createAllInstancedEntities(void)
Ogre::InstanceBatch::setStaticAndUpdate
virtual void setStaticAndUpdate(bool bStatic)
Tells this batch to stop updating animations, positions, rotations, and display all it's active insta...
Definition: OgreInstanceBatch.h:295
Ogre::InstanceBatch::mMaterial
MaterialPtr mMaterial
Definition: OgreInstanceBatch.h:99
Ogre::InstanceBatch::getBoundingRadius
Real getBoundingRadius(void) const
Ogre::InstanceBatch::mTechnSupportsSkeletal
bool mTechnSupportsSkeletal
False if a technique doesn't support skeletal animation.
Definition: OgreInstanceBatch.h:128
Ogre::InstanceBatch::getRenderOperation
void getRenderOperation(RenderOperation &op)
Definition: OgreInstanceBatch.h:335
Ogre::InstanceBatch::_updateRenderQueue
virtual void _updateRenderQueue(RenderQueue *queue)
Internal method by which the movable object must add Renderable subclass instances to the rendering q...
Ogre::SharedPtr< Material >
Ogre::InstanceBatch::_updateBounds
void _updateBounds(void)
Ogre::InstanceBatch::mBoundingRadius
Real mBoundingRadius
Definition: OgreInstanceBatch.h:118
Ogre::InstanceBatch::InstancedEntityVec
vector< InstancedEntity * >::type InstancedEntityVec
Definition: OgreInstanceBatch.h:91
OgreRenderable.h
OgreMovableObject.h
Ogre::InstanceBatch::deleteAllInstancedEntities
virtual void deleteAllInstancedEntities(void)
Ogre::InstanceBatch::getMaterial
const MaterialPtr & getMaterial(void) const
Definition: OgreInstanceBatch.h:333
Ogre::InstanceBatch::mInstancesPerBatch
size_t mInstancesPerBatch
Definition: OgreInstanceBatch.h:95
Ogre::InstanceBatch::build
virtual RenderOperation build(const SubMesh *baseSubMesh)
Constructs all the data needed to use this batch, as well as the InstanceEntities.
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:46
Ogre::InstanceBatch::getMovableType
const String & getMovableType(void) const
Ogre::InstanceBatch::mRemoveOwnIndexData
bool mRemoveOwnIndexData
When true remove the memory of the IndexData we've created because no one else will.
Definition: OgreInstanceBatch.h:141
Ogre::Renderable::setUserAny
virtual OGRE_DEPRECATED void setUserAny(const Any &anything)
Definition: OgreRenderable.h:344
Ogre::Renderable::Visitor
Visitor object that can be used to iterate over a collection of Renderable instances abstractly.
Definition: OgreRenderable.h:378
Ogre::InstanceBatch::mCachedCamera
const Camera * mCachedCamera
The camera for which the cached distance is valid.
Definition: OgreInstanceBatch.h:133
Ogre::Renderable
Abstract class defining the interface all renderable objects must implement.
Definition: OgreRenderable.h:64
Ogre::InstanceBatch::_setCustomParam
void _setCustomParam(InstancedEntity *instancedEntity, unsigned char idx, const Vector4 &newParam)
Ogre::InstanceBatch::setupVertices
virtual void setupVertices(const SubMesh *baseSubMesh)=0
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::InstanceBatch
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
Definition: OgreInstanceBatch.h:89
Ogre::InstanceBatch::getInstancedEntitiesInUse
void getInstancedEntitiesInUse(InstancedEntityVec &outEntities, CustomParamsVec &outParams)
Fills the input vector with the instances that are currently being used or were requested.
Ogre::InstanceBatch::_getIndexToBoneMap
const Mesh::IndexMap * _getIndexToBoneMap() const
Definition: OgreInstanceBatch.h:184
Ogre::InstanceBatch::mCustomParams
CustomParamsVec mCustomParams
Definition: OgreInstanceBatch.h:114
Ogre::InstanceBatch::mCachedCameraDist
Real mCachedCameraDist
Cached distance to last camera for getSquaredViewDepth.
Definition: OgreInstanceBatch.h:131
Ogre::InstanceBatch::checkSubMeshCompatibility
virtual bool checkSubMeshCompatibility(const SubMesh *baseSubMesh)
Returns false on errors that would prevent building this batch from the given submesh.
Ogre::InstanceBatch::_getCustomParam
const Vector4 & _getCustomParam(InstancedEntity *instancedEntity, unsigned char idx)
Ogre::InstanceBatch::getSquaredViewDepth
Real getSquaredViewDepth(const Camera *cam) const
Ogre::InstanceBatch::defragmentBatchDoCull
void defragmentBatchDoCull(InstancedEntityVec &usedEntities, CustomParamsVec &usedParams)
Ogre::vector
Definition: OgrePrerequisites.h:492
Ogre::InstanceBatch::isStatic
virtual bool isStatic() const
Returns true if this batch was set as static.
Definition: OgreInstanceBatch.h:299
Ogre::InstanceBatch::mTransformSharingDirty
bool mTransformSharingDirty
Tells that the list of entity instances with shared transforms has changed.
Definition: OgreInstanceBatch.h:136
Ogre::InstancedEntity
Definition: OgreInstancedEntity.h:78
Ogre::InstanceBatch::mFullBoundingBox
AxisAlignedBox mFullBoundingBox
This bbox contains all (visible) instanced entities.
Definition: OgreInstanceBatch.h:117
Ogre::InstanceBatch::_markTransformSharingDirty
void _markTransformSharingDirty()
Tells that the list of entity instances with shared transforms has changed.
Definition: OgreInstanceBatch.h:323
Ogre::RenderOperation
'New' rendering operation using vertex buffers.
Definition: OgreRenderOperation.h:45
Ogre::InstanceBatch::_notifyCurrentCamera
void _notifyCurrentCamera(Camera *cam)
Ogre::RenderQueue
Class to manage the scene object rendering queue.
Definition: OgreRenderQueue.h:93
Ogre::InstanceBatch::createInstancedEntity
InstancedEntity * createInstancedEntity()
Returns a pointer to a new InstancedEntity ready to use Note it's actually preallocated,...
Ogre::InstanceBatch::getLights
const LightList & getLights(void) const

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