OGRE  2.0
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-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 __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"
38 
39 namespace Ogre
40 {
90  {
91  public:
95 
97  {
100  SKELETONS_LUT
101  };
102 
103  protected:
106 
109 
111 
114 
115  //InstancedEntities are all allocated at build time and kept as "unused"
116  //when they're requested, they're removed from there when requested,
117  //and put back again when they're no longer needed
118  //Note each InstancedEntity has a unique ID ranging from [0; mInstancesPerBatch)
121 
122 #ifdef OGRE_LEGACY_ANIMATIONS
123 
127  InstancedEntityArray mAnimatedEntities;
128 #endif
129 
134 
136 
140  mutable const Camera *mCachedCamera;
141 
144 
146 
148  MovableObjectArray mCulledInstances;
149 
154 
155  virtual void setupVertices( const SubMesh* baseSubMesh ) = 0;
156  virtual void setupIndices( const SubMesh* baseSubMesh ) = 0;
157  virtual void createAllInstancedEntities(void);
158  virtual void deleteAllInstancedEntities(void);
159  virtual void deleteUnusedInstancedEntities(void);
161  virtual InstancedEntity* generateInstancedEntity(size_t num);
162 
164  virtual bool checkSubMeshCompatibility( const SubMesh* baseSubMesh );
165 
167  void defragmentBatchNoCull( InstancedEntityVec &usedEntities, CustomParamsVec &usedParams );
168 
174  void defragmentBatchDoCull( InstancedEntityVec &usedEntities, CustomParamsVec &usedParams );
175 
179  void instanceBatchCullFrustumThreadedImpl(const Frustum *frustum, const Camera *lodCamera,
180  uint32 combinedVisibilityFlags );
181 
182  public:
183  InstanceBatch( IdType id, ObjectMemoryManager *objectMemoryManager,
184  InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
185  size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap );
186  virtual ~InstanceBatch();
187 
188  MeshPtr& _getMeshRef() { return mMeshReference; }
189 
192  void _setInstancesPerBatch( size_t instancesPerBatch );
193 
194  const Mesh::IndexMap* _getIndexToBoneMap() const { return mIndexToBoneMap; }
195 
202  SkeletalAnimationMode _supportsSkeletalAnimation() const { return mTechnSupportsSkeletal; }
203 
204 #ifdef OGRE_LEGACY_ANIMATIONS
205  void _updateAnimations(void);
207 #endif
208 
214  void _updateEntitiesBoundsThread( size_t threadIdx );
215 
217  void _updateBounds(void);
218 
229  virtual size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const = 0;
230 
244  virtual RenderOperation build( const SubMesh* baseSubMesh );
245 
258  virtual void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
259 
260  const Ogre::MeshPtr& _getMeshReference(void) const { return mMeshReference; }
261 
265  bool isBatchFull(void) const { return mUnusedEntities.empty(); }
266 
269  bool isBatchUnused(void) const { return mUnusedEntities.size() == mInstancedEntities.size(); }
270 
274  void getInstancedEntitiesInUse( InstancedEntityVec &outEntities, CustomParamsVec &outParams );
275 
276 #ifdef OGRE_LEGACY_ANIMATIONS
277  void _addAnimatedInstance( InstancedEntity *instancedEntity );
279 
284  void _removeAnimatedInstance( const InstancedEntity *instancedEntity );
285 #endif
286 
300  void _defragmentBatch( bool optimizeCulling, InstancedEntityVec &usedEntities,
301  CustomParamsVec &usedParams );
302 
308  void _defragmentBatchDiscard(void);
309 
324  bool setStatic( bool bStatic );
325 
329  virtual void _notifyStaticDirty(void);
330 
337  InstancedEntity* createInstancedEntity();
338 
345  void removeInstancedEntity( InstancedEntity *instancedEntity );
346 
347 #ifdef OGRE_LEGACY_ANIMATIONS
348 
351  bool useBoneWorldMatrices() const { return mTechnSupportsSkeletal != SKELETONS_LUT; }
352 #endif
353 
355  void _markTransformSharingDirty() { mTransformSharingDirty = true; }
356 
358  void _setCustomParam( InstancedEntity *instancedEntity, unsigned char idx, const Vector4 &newParam );
359 
361  const Vector4& _getCustomParam( InstancedEntity *instancedEntity, unsigned char idx );
362 
363  //Renderable overloads
365  const MaterialPtr& getMaterial(void) const { return mMaterial; }
367  void getRenderOperation( RenderOperation& op ) { op = mRenderOperation; }
368 
370  Real getSquaredViewDepth( const Camera* cam ) const;
372  const LightList& getLights( void ) const;
374  Technique* getTechnique(void) const;
375 
377  const String& getMovableType(void) const;
378 
379  virtual void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera);
380  void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false );
381 
382  // resolve ambiguity of get/setUserAny due to inheriting from Renderable and MovableObject
385  };
386 } // namespace Ogre
387 
388 #include "OgreHeaderSuffix.h"
389 
390 #endif // __InstanceBatch_H__
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
const MaterialPtr & getMaterial(void) const
Mesh::IndexMap const * mIndexToBoneMap
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:420
bool isBatchFull(void) const
#define _OgreExport
Definition: OgrePlatform.h:255
std::vector< T, A > type
MaterialPtr mMaterial
Only one render queue is used.
A frustum represents a pyramid, capped at the near and far end which is used to represent either a vi...
Definition: OgreFrustum.h:84
Lightweight implementation of std::vector.
Definition: OgreFastArray.h:65
Real mCachedCameraDist
Cached distance to last camera for getSquaredViewDepth.
bool mRemoveOwnVertexData
Only for HW Basic & HW VTF.
CustomParamsVec mCustomParams
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:50
FastArray< InstancedEntity * > InstancedEntityArray
const Ogre::MeshPtr & _getMeshReference(void) const
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
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
Abstract class defining the interface all renderable objects must implement.
void getRenderOperation(RenderOperation &op)
InstanceManager * mCreator
bool mTransformSharingDirty
Tells that the list of entity instances with shared transforms has changed.
SkeletalAnimationMode mTechnSupportsSkeletal
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
MovableObjectArray mCulledInstances
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...
vector< Aabb >::type mThreadAabbs
ObjectMemoryManager mLocalObjectMemoryManager
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 isBatchUnused(void) const
Returns true if it no instanced entity has been requested or all of them have been removed...
SkeletalAnimationMode _supportsSkeletalAnimation() const
Returns true if this technique supports skeletal animation.
'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
Definition: OgreCommon.h:53
void _markTransformSharingDirty()
Tells that the list of entity instances with shared transforms has changed.
vector< Vector4 >::type CustomParamsVec
unsigned short uint16
Definition: OgrePlatform.h:421
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
vector< InstancedEntity * >::type InstancedEntityVec
virtual OGRE_DEPRECATED void setUserAny(const Any &anything)
virtual OGRE_DEPRECATED const Any & getUserAny(void) const
InstancedEntityVec mUnusedEntities