OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
37 namespace Ogre
38 {
88  {
89  public:
91  protected:
94 
96 
98 
101 
102  //InstancedEntities are all allocated at build time and kept as "unused"
103  //when they're requested, they're removed from there when requested,
104  //and put back again when they're no longer needed
105  //Note each InstancedEntity has a unique ID ranging from [0; mInstancesPerBatch)
108 
116 
117  unsigned short mMaterialLodIndex;
118 
121 
124 
128  mutable const Camera *mCachedCamera;
129 
132 
137 
138  virtual void setupVertices( const SubMesh* baseSubMesh ) = 0;
139  virtual void setupIndices( const SubMesh* baseSubMesh ) = 0;
140  virtual void createAllInstancedEntities(void);
141  virtual void deleteAllInstancedEntities(void);
142  virtual void deleteUnusedInstancedEntities(void);
144  virtual InstancedEntity* generateInstancedEntity(size_t num);
145 
150  void makeMatrixCameraRelative3x4( float *mat3x4, size_t numFloats );
151 
153  virtual bool checkSubMeshCompatibility( const SubMesh* baseSubMesh );
154 
155  void updateVisibility(void);
156 
158  void defragmentBatchNoCull( InstancedEntityVec &usedEntities );
159 
165  void defragmentBatchDoCull( InstancedEntityVec &usedEntities );
166 
167  public:
168  InstanceBatch( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
169  size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
170  const String &batchName );
171  virtual ~InstanceBatch();
172 
173  MeshPtr& _getMeshRef() { return mMeshReference; }
174 
177  void _setInstancesPerBatch( size_t instancesPerBatch );
178 
179  const Mesh::IndexMap* _getIndexToBoneMap() const { return mIndexToBoneMap; }
180 
187  bool _supportsSkeletalAnimation() const { return mTechnSupportsSkeletal; }
188 
190  void _updateBounds(void);
191 
202  virtual size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const = 0;
203 
217  virtual RenderOperation build( const SubMesh* baseSubMesh );
218 
231  virtual void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
232 
233  const Ogre::MeshPtr& _getMeshReference(void) const { return mMeshReference; }
234 
238  bool isBatchFull(void) const { return mUnusedEntities.empty(); }
239 
242  bool isBatchUnused(void) const { return mUnusedEntities.size() == mInstancedEntities.size(); }
243 
247  void getInstancedEntitiesInUse( InstancedEntityVec &outEntities );
248 
260  void _defragmentBatch( bool optimizeCulling, InstancedEntityVec &usedEntities );
261 
267  void _defragmentBatchDiscard(void);
268 
272  virtual void _boundsDirty(void);
273 
287  virtual void setStaticAndUpdate( bool bStatic ) {}
288 
291  virtual bool isStatic() const { return false; }
292 
299  InstancedEntity* createInstancedEntity();
300 
307  void removeInstancedEntity( InstancedEntity *instancedEntity );
308 
312  virtual bool useBoneWorldMatrices() const { return true; }
313 
315  void _markTransformSharingDirty() { mTransformSharingDirty = true; }
316 
317  //Renderable overloads
319  const MaterialPtr& getMaterial(void) const { return mMaterial; }
321  void getRenderOperation( RenderOperation& op ) { op = mRenderOperation; }
322 
324  Real getSquaredViewDepth( const Camera* cam ) const;
326  const LightList& getLights( void ) const;
328  Technique* getTechnique(void) const;
329 
331  const String& getMovableType(void) const;
333  void _notifyCurrentCamera( Camera* cam );
335  const AxisAlignedBox& getBoundingBox(void) const;
337  Real getBoundingRadius(void) const;
338 
339  virtual void _updateRenderQueue(RenderQueue* queue);
340  void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false );
341 
342  // resolve ambiguity of get/setUserAny due to inheriting from Renderable and MovableObject
345  };
346 }
347 
348 #endif
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
const MaterialPtr & getMaterial(void) const
Mesh::IndexMap const * mIndexToBoneMap
virtual bool useBoneWorldMatrices() const
Tells whether world bone matrices need to be calculated.
float Real
Software floating point type.
vector< unsigned short >::type IndexMap
Definition: OgreMesh.h:107
bool isBatchFull(void) const
#define _OgreExport
Definition: OgrePlatform.h:233
unsigned short mMaterialLodIndex
virtual void setStaticAndUpdate(bool bStatic)
Tells this batch to stop updating animations, positions, rotations, and display all it's active insta...
A 3D box aligned with the x/y/z axes.
AxisAlignedBox mFullBoundingBox
This bbox contains all (visible) instanced entities.
bool mTechnSupportsSkeletal
False if a technique doesn't support skeletal animation.
Real mCachedCameraDist
Cached distance to last camera for getSquaredViewDepth.
bool mRemoveOwnVertexData
When true remove the memory of the VertexData we've created because no one else will.
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:53
const Ogre::MeshPtr & _getMeshReference(void) const
bool mRemoveOwnIndexData
When true remove the memory of the IndexData we've created because no one else will.
Abstract class defining a movable object in a scene.
InstancedEntityVec mInstancedEntities
bool mBoundsUpdated
Set to false by derived classes that need it.
Abstract class defining the interface all renderable objects must implement.
void getRenderOperation(RenderOperation &op)
bool _supportsSkeletalAnimation() const
Returns true if this technique supports skeletal animation.
InstanceManager * mCreator
bool mDirtyAnimation
Set to false at start of each _updateRenderQueue.
bool mTransformSharingDirty
Tells that the list of entity instances with shared transforms has changed.
virtual bool isStatic() const
Returns true if this batch was set as static.
const Mesh::IndexMap * _getIndexToBoneMap() const
const Camera * mCachedCamera
The camera for which the cached distance is valid.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:62
virtual const Any & getUserAny(void) const
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
bool isBatchUnused(void) const
Returns true if it no instanced entity has been requested or all of them have been removed...
'New' rendering operation using vertex buffers.
Class to manage the scene object rendering queue.
This is the main starting point for the new instancing system.
RenderOperation mRenderOperation
_StringBase String
void _markTransformSharingDirty()
Tells that the list of entity instances with shared transforms has changed.
virtual void setUserAny(const Any &anything)
unsigned short uint16
Definition: OgrePlatform.h:271
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:688
vector< InstancedEntity * >::type InstancedEntityVec
Specialisation of SharedPtr to allow SharedPtr to be assigned to MeshPtr.
Definition: OgreMesh.h:875
InstancedEntityVec mUnusedEntities