OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Ogre::InstanceManager Class Reference

This is the main starting point for the new instancing system. More...

#include <OgreInstanceManager.h>

+ Inheritance diagram for Ogre::InstanceManager:
+ Collaboration diagram for Ogre::InstanceManager:

Classes

struct  BatchSettings
 

Public Types

enum  BatchSettingId { CAST_SHADOWS = 0, SHOW_BOUNDINGBOX, NUM_SETTINGS }
 Values to be used in setSetting() & BatchSettings::setting. More...
 
typedef ConstVectorIterator
< InstanceBatchVec
InstanceBatchIterator
 
typedef ConstMapIterator
< InstanceBatchMap
InstanceBatchMapIterator
 
enum  InstancingTechnique {
  ShaderBased, TextureVTF, HWInstancingBasic, HWInstancingVTF,
  InstancingTechniquesCount
}
 

Public Member Functions

 InstanceManager (IdString customName, SceneManager *sceneManager, const String &meshName, const String &groupName, InstancingTechnique instancingTechnique, uint16 instancingFlags, size_t instancesPerBatch, unsigned short subMeshIdx, bool useBoneMatrixLookup=false)
 
virtual ~InstanceManager ()
 
void _addDirtyStaticBatch (InstanceBatch *dirtyBatch)
 Called by an InstanceBatch when it requests their bounds to be updated for proper culling. More...
 
void _addToDynamicBatchList (InstanceBatch *dynamicBatch)
 Kees the batch in the dynamic batch list so that it gets updated every frame. More...
 
void _removeFromDynamicBatchList (InstanceBatch *batch)
 Called when a previously dynamic InstanceBatch went static (. More...
 
void _updateDirtyBatches (void)
 Called by SceneManager every frame. More...
 
void _updateDirtyBatchesThread (size_t threadIdx)
 Called by SceneManager every frame from multiple threads. More...
 
void cleanupEmptyBatches (void)
 This function can be useful to improve CPU speed after having too many instances created, which where now removed, thus freeing many batches with zero used Instanced Entities However the batches aren't automatically removed from memory until the InstanceManager is destroyed, or this function is called. More...
 
InstancedEntitycreateInstancedEntity (const String &materialName, SceneMemoryMgrTypes sceneType=SCENE_DYNAMIC)
 Creates an InstancedEntity based on an existing InstanceManager (. More...
 
void defragmentBatches (bool optimizeCulling)
 After creating many entities (which turns in many batches) and then removing entities that are in the middle of these batches, there might be many batches with many free entities. More...
 
InstanceBatchIterator getInstanceBatchIterator (const String &materialName, SceneMemoryMgrTypes sceneType) const
 Get non-updateable iterator over instance batches for given material. More...
 
InstanceBatchMapIterator getInstanceBatchMapIterator (void) const
 Get non-updateable iterator over instance batches per material. More...
 
InstancingTechnique getInstancingTechnique () const
 
size_t getMaxOrBestNumInstancesPerBatch (const String &materialName, size_t suggestedSize, uint16 flags)
 Calculates the maximum (or the best amount, depending on flags) of instances per batch given the suggested size for the technique this manager was created for. More...
 
const IdString getName () const
 
unsigned char getNumCustomParams () const
 
SceneManagergetSceneManager () const
 
bool getSetting (BatchSettingId id, IdString materialName) const
 If settings for the given material didn't exist, default value is returned. More...
 
bool hasSettings (IdString materialName) const
 Returns true if settings were already created for the given material name. More...
 
void operator delete (void *ptr)
 
void operator delete (void *ptr, void *)
 
void operator delete (void *ptr, const char *, int, const char *)
 
void operator delete[] (void *ptr)
 
void operator delete[] (void *ptr, const char *, int, const char *)
 
void * operator new (size_t sz, const char *file, int line, const char *func)
 operator new, with debug line info More...
 
void * operator new (size_t sz)
 
void * operator new (size_t sz, void *ptr)
 placement operator new More...
 
void * operator new[] (size_t sz, const char *file, int line, const char *func)
 array operator new, with debug line info More...
 
void * operator new[] (size_t sz)
 
void setBatchesAsStatic (bool bStatic)
 Tells this batch to stop updating animations, positions, rotations, and display all it's active instances. More...
 
void setInstancesPerBatch (size_t instancesPerBatch)
 Raises an exception if trying to change it after creating the first InstancedEntity. More...
 
void setMaxLookupTableInstances (size_t maxLookupTableInstances)
 Sets the size of the lookup table for techniques supporting bone lookup table. More...
 
void setNumCustomParams (unsigned char numCustomParams)
 Sets the number of custom parameters per instance. More...
 
void setSetting (BatchSettingId id, bool enabled, IdString materialName=IdString())
 Applies a setting for all batches using the same material_ existing ones and those that will be created in the future. More...
 

Private Types

typedef map< IdString,
BatchSettings >::type 
BatchSettingsMap
 
typedef map< IdString,
InstanceBatchVec >::type 
InstanceBatchMap
 
typedef vector< InstanceBatch * >
::type 
InstanceBatchVec
 

Private Member Functions

void applySettingToBatches (BatchSettingId id, bool value, const InstanceBatchVec &container)
 
InstanceBatchbuildNewBatch (const String &materialName, SceneMemoryMgrTypes sceneType, bool firstTime)
 Called when batches are fully exhausted (can't return more instances) so a new batch is created. More...
 
void defragmentBatches (bool optimizeCull, vector< InstancedEntity * >::type &entities, vector< Ogre::Vector4 >::type &usedParams, InstanceBatchVec &fragmentedBatches)
 
InstanceBatchgetFreeBatch (const String &materialName, SceneMemoryMgrTypes sceneType)
 Finds a batch with at least one free instanced entity we can use. More...
 
void unshareVertices (const Ogre::MeshPtr &mesh)
 Called when we you use a mesh which has shared vertices, the function creates separate vertex/index buffers and also recreates the bone assignments. More...
 

Private Attributes

BatchSettingsMap mBatchSettings
 
InstanceBatchVec mDirtyStaticBatches
 
InstanceBatchVec mDynamicBatches
 
size_t mIdCount
 
InstanceBatchMap mInstanceBatches
 
size_t mInstancesPerBatch
 
uint16 mInstancingFlags
 
InstancingTechnique mInstancingTechnique
 
size_t mMaxLookupTableInstances
 
MeshPtr mMeshReference
 
const IdString mName
 
unsigned char mNumCustomParams
 
SceneManagermSceneManager
 
RenderOperation mSharedRenderOperation
 
unsigned short mSubMeshIdx
 

Detailed Description

This is the main starting point for the new instancing system.

Each InstanceManager can control one technique and one mesh, but it can manage multiple materials at the same time.

See also
SceneManager::createInstanceManager, which creates this InstanceManager. Each one must have a unique name. It's wasteless to create two InstanceManagers with the same mesh reference, instancing technique and instances per batch count. This class takes care of managing batches automatically, so that more are created when needed, and reuse existing ones as much as possible; thus the user doesn't have to worry of managing all those low level issues.
InstanceBatch &
InstanceEntity for more information.
Remarks
Design discussion webpage: http://www.ogre3d.org/forums/viewtopic.php?f=4&t=59902
Author
Matias N. Goldberg ("dark_sylinc")
Version
1.0

Definition at line 63 of file OgreInstanceManager.h.

Member Function Documentation

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr)
inlineinherited

Definition at line 96 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr,
void *   
)
inlineinherited

Definition at line 102 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete ( void *  ptr,
const char *  ,
int  ,
const char *   
)
inlineinherited

Definition at line 108 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete[] ( void *  ptr)
inlineinherited

Definition at line 113 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void Ogre::AllocatedObject< Alloc >::operator delete[] ( void *  ptr,
const char *  ,
int  ,
const char *   
)
inlineinherited

Definition at line 119 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz,
const char *  file,
int  line,
const char *  func 
)
inlineinherited

operator new, with debug line info

Definition at line 68 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz)
inlineinherited

Definition at line 73 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new ( size_t  sz,
void *  ptr 
)
inlineinherited

placement operator new

Definition at line 79 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new[] ( size_t  sz,
const char *  file,
int  line,
const char *  func 
)
inlineinherited

array operator new, with debug line info

Definition at line 86 of file OgreMemoryAllocatedObject.h.

template<class Alloc >
void* Ogre::AllocatedObject< Alloc >::operator new[] ( size_t  sz)
inlineinherited

Definition at line 91 of file OgreMemoryAllocatedObject.h.


The documentation for this class was generated from the following file: