OgreInstanceManager.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 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 __InstanceManager_H__
#define __InstanceManager_H__
#include "OgrePrerequisites.h"
#include "OgreMesh.h"
#include "OgreRenderOperation.h"
#include "OgreHeaderPrefix.h"
namespace Ogre
{
class _OgreExport InstanceManager : public FactoryAlloc
{
public:
enum InstancingTechnique
{
ShaderBased,
TextureVTF,
HWInstancingBasic,
HWInstancingVTF,
InstancingTechniquesCount
};
enum BatchSettingId
{
CAST_SHADOWS = 0,
SHOW_BOUNDINGBOX,
NUM_SETTINGS
};
private:
struct BatchSettings
{
//These are all per material
bool setting[NUM_SETTINGS];
BatchSettings()
{
setting[CAST_SHADOWS] = true;
setting[SHOW_BOUNDINGBOX] = false;
}
};
typedef vector<InstanceBatch*>::type InstanceBatchVec; //vec[batchN] = Batch
typedef map<String, InstanceBatchVec>::type InstanceBatchMap; //map[materialName] = Vec
typedef map<String, BatchSettings>::type BatchSettingsMap;
const String mName; //Not the name of the mesh
MeshPtr mMeshReference;
InstanceBatchMap mInstanceBatches;
size_t mIdCount;
InstanceBatchVec mDirtyBatches;
RenderOperation mSharedRenderOperation;
size_t mInstancesPerBatch;
InstancingTechnique mInstancingTechnique;
uint16 mInstancingFlags;
unsigned short mSubMeshIdx;
BatchSettingsMap mBatchSettings;
SceneManager* mSceneManager;
size_t mMaxLookupTableInstances;
unsigned char mNumCustomParams; //Number of custom params per instance.
inline InstanceBatch* getFreeBatch( const String &materialName );
InstanceBatch* buildNewBatch( const String &materialName, bool firstTime );
void defragmentBatches( bool optimizeCull, vector<InstancedEntity*>::type &entities,
vector<Ogre::Vector4>::type &usedParams,
InstanceBatchVec &fragmentedBatches );
void applySettingToBatches( BatchSettingId id, bool value, const InstanceBatchVec &container );
void unshareVertices(const Ogre::MeshPtr &mesh);
public:
InstanceManager( const String &customName, SceneManager *sceneManager,
const String &meshName, const String &groupName,
InstancingTechnique instancingTechnique, uint16 instancingFlags,
size_t instancesPerBatch, unsigned short subMeshIdx, bool useBoneMatrixLookup = false);
virtual ~InstanceManager();
const String& getName() const { return mName; }
SceneManager* getSceneManager() const { return mSceneManager; }
void setInstancesPerBatch( size_t instancesPerBatch );
void setMaxLookupTableInstances( size_t maxLookupTableInstances );
void setNumCustomParams( unsigned char numCustomParams );
unsigned char getNumCustomParams() const
{ return mNumCustomParams; }
InstancingTechnique getInstancingTechnique() const
{ return mInstancingTechnique; }
size_t getMaxOrBestNumInstancesPerBatch( String materialName, size_t suggestedSize, uint16 flags );
InstancedEntity* createInstancedEntity( const String &materialName );
void cleanupEmptyBatches(void);
void defragmentBatches( bool optimizeCulling );
void setSetting( BatchSettingId id, bool enabled, const String &materialName = StringUtil::BLANK );
bool getSetting( BatchSettingId id, const String &materialName ) const;
bool hasSettings( const String &materialName ) const
{ return mBatchSettings.find( materialName ) != mBatchSettings.end(); }
void setBatchesAsStaticAndUpdate( bool bStatic );
void _addDirtyBatch( InstanceBatch *dirtyBatch );
void _updateDirtyBatches(void);
typedef ConstMapIterator<InstanceBatchMap> InstanceBatchMapIterator;
typedef ConstVectorIterator<InstanceBatchVec> InstanceBatchIterator;
InstanceBatchMapIterator getInstanceBatchMapIterator(void) const
{ return InstanceBatchMapIterator( mInstanceBatches.begin(), mInstanceBatches.end() ); }
InstanceBatchIterator getInstanceBatchIterator( const String &materialName ) const
{
InstanceBatchMap::const_iterator it = mInstanceBatches.find( materialName );
if(it != mInstanceBatches.end())
return InstanceBatchIterator( it->second.begin(), it->second.end() );
else
OGRE_EXCEPT(Exception::ERR_INVALID_STATE, "Cannot create instance batch iterator. "
"Material " + materialName + " cannot be found.", "InstanceManager::getInstanceBatchIterator");
}
};
} // namespace Ogre
#include "OgreHeaderSuffix.h"
#endif // __InstanceManager_H__
Ogre::InstanceManager::InstanceBatchMap
map< String, InstanceBatchVec >::type InstanceBatchMap
Definition: OgreInstanceManager.h:100
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::InstanceManager::InstanceBatchVec
vector< InstanceBatch * >::type InstanceBatchVec
Definition: OgreInstanceManager.h:99
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
OgreMesh.h
Ogre::InstanceManager::getInstanceBatchMapIterator
InstanceBatchMapIterator getInstanceBatchMapIterator(void) const
Get non-updateable iterator over instance batches per material.
Definition: OgreInstanceManager.h:301
Ogre::ConstMapIterator
Concrete IteratorWrapper for const access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:352
Ogre::InstanceManager::InstancingTechnique
InstancingTechnique
Definition: OgreInstanceManager.h:66
Ogre::InstanceManager::mMaxLookupTableInstances
size_t mMaxLookupTableInstances
Definition: OgreInstanceManager.h:121
Ogre::InstanceManager::mSubMeshIdx
unsigned short mSubMeshIdx
Definition: OgreInstanceManager.h:116
Ogre::InstanceManager::hasSettings
bool hasSettings(const String &materialName) const
Returns true if settings were already created for the given material name.
Definition: OgreInstanceManager.h:283
Ogre::InstanceManager::mName
const String mName
Definition: OgreInstanceManager.h:104
Ogre::InstanceManager::mIdCount
size_t mIdCount
Definition: OgreInstanceManager.h:107
Ogre::InstanceManager::InstanceBatchMapIterator
ConstMapIterator< InstanceBatchMap > InstanceBatchMapIterator
Definition: OgreInstanceManager.h:297
Ogre::InstanceManager::BatchSettings::BatchSettings
BatchSettings()
Definition: OgreInstanceManager.h:92
Ogre::InstanceManager::mSceneManager
SceneManager * mSceneManager
Definition: OgreInstanceManager.h:119
Ogre::InstanceManager::HWInstancingBasic
Needs SM 3.0+ and HW instancing support.
Definition: OgreInstanceManager.h:70
OgrePrerequisites.h
Ogre::InstanceManager::mSharedRenderOperation
RenderOperation mSharedRenderOperation
Definition: OgreInstanceManager.h:111
Ogre::InstanceManager::mInstancingFlags
uint16 mInstancingFlags
Definition: OgreInstanceManager.h:115
Ogre::InstanceManager::InstanceBatchIterator
ConstVectorIterator< InstanceBatchVec > InstanceBatchIterator
Definition: OgreInstanceManager.h:298
Ogre::InstanceManager::mDirtyBatches
InstanceBatchVec mDirtyBatches
Definition: OgreInstanceManager.h:109
Ogre::InstanceManager::mInstancingTechnique
InstancingTechnique mInstancingTechnique
Definition: OgreInstanceManager.h:114
OgreRenderOperation.h
Ogre::InstanceManager::getNumCustomParams
unsigned char getNumCustomParams() const
Definition: OgreInstanceManager.h:204
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::InstanceManager::mBatchSettings
BatchSettingsMap mBatchSettings
Definition: OgreInstanceManager.h:118
Ogre::InstanceManager::getSceneManager
SceneManager * getSceneManager() const
Definition: OgreInstanceManager.h:165
Ogre::InstanceManager
This is the main starting point for the new instancing system.
Definition: OgreInstanceManager.h:63
Ogre::InstanceManager::mNumCustomParams
unsigned char mNumCustomParams
Definition: OgreInstanceManager.h:122
OgreHeaderSuffix.h
Ogre::Exception::ERR_INVALID_STATE
Definition: OgreException.h:102
Ogre::InstanceManager::SHOW_BOUNDINGBOX
Makes each batch to display it&#39;s bounding box. Useful for debugging or profiling. ...
Definition: OgreInstanceManager.h:81
Ogre::InstanceBatch
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
Definition: OgreInstanceBatch.h:88
OGRE_EXCEPT
#define OGRE_EXCEPT(num, desc, src)
Definition: OgreException.h:334
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::InstanceManager::BatchSettingsMap
map< String, BatchSettings >::type BatchSettingsMap
Definition: OgreInstanceManager.h:102
Ogre::InstanceManager::TextureVTF
Needs Vertex Texture Fetch & SM 3.0+.
Definition: OgreInstanceManager.h:69
Ogre::SharedPtr< Mesh >
Ogre::ConstVectorIterator
Concrete IteratorWrapper for const access to the underlying container.
Definition: OgreIteratorWrapper.h:217
Ogre::InstanceManager::getInstancingTechnique
InstancingTechnique getInstancingTechnique() const
Definition: OgreInstanceManager.h:208
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::InstanceManager::mMeshReference
MeshPtr mMeshReference
Definition: OgreInstanceManager.h:105
OgreHeaderPrefix.h
Ogre::InstanceManager::getName
const String & getName() const
Definition: OgreInstanceManager.h:163
Ogre::RenderOperation
&#39;New&#39; rendering operation using vertex buffers.
Definition: OgreRenderOperation.h:45
Ogre::InstanceManager::BatchSettings
Definition: OgreInstanceManager.h:87
Ogre::InstanceManager::BatchSettingId
BatchSettingId
Values to be used in setSetting() & BatchSettings::setting.
Definition: OgreInstanceManager.h:76
Ogre::map
Definition: OgrePrerequisites.h:533
Ogre::InstanceManager::mInstancesPerBatch
size_t mInstancesPerBatch
Definition: OgreInstanceManager.h:113
Ogre::InstanceManager::ShaderBased
Any SM 2.0+.
Definition: OgreInstanceManager.h:68
Ogre::SceneManager
Manages the organisation and rendering of a &#39;scene&#39; i.e.
Definition: OgreSceneManager.h:143
Ogre::InstancedEntity
Definition: OgreInstancedEntity.h:77
Ogre::InstanceManager::mInstanceBatches
InstanceBatchMap mInstanceBatches
Definition: OgreInstanceManager.h:106
Ogre::InstanceManager::HWInstancingVTF
Needs SM 3.0+, HW instancing support & VTF.
Definition: OgreInstanceManager.h:71
Ogre::StringUtil::BLANK
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:196
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::InstanceManager::getInstanceBatchIterator
InstanceBatchIterator getInstanceBatchIterator(const String &materialName) const
Get non-updateable iterator over instance batches for given material.
Definition: OgreInstanceManager.h:310

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