OGRE  1.9.0
OgreInstanceManager.h
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __InstanceManager_H__
29#define __InstanceManager_H__
30
31#include "OgrePrerequisites.h"
32#include "OgreMesh.h"
33#include "OgreRenderOperation.h"
34#include "OgreHeaderPrefix.h"
35
36namespace Ogre
37{
64 {
65 public:
67 {
72 InstancingTechniquesCount
73 };
74
77 {
79 CAST_SHADOWS = 0,
82
83 NUM_SETTINGS
84 };
85
86 private:
88 {
89 //These are all per material
90 bool setting[NUM_SETTINGS];
91
93 {
94 setting[CAST_SHADOWS] = true;
95 setting[SHOW_BOUNDINGBOX] = false;
96 }
97 };
98
99 typedef vector<InstanceBatch*>::type InstanceBatchVec; //vec[batchN] = Batch
100 typedef map<String, InstanceBatchVec>::type InstanceBatchMap; //map[materialName] = Vec
101
103
104 const String mName; //Not the name of the mesh
107 size_t mIdCount;
108
110
112
116 unsigned short mSubMeshIdx;
117
120
122 unsigned char mNumCustomParams; //Number of custom params per instance.
123
127 inline InstanceBatch* getFreeBatch( const String &materialName );
128
138 InstanceBatch* buildNewBatch( const String &materialName, bool firstTime );
139
145
150
155
156 public:
158 const String &meshName, const String &groupName,
160 size_t instancesPerBatch, unsigned short subMeshIdx, bool useBoneMatrixLookup = false);
162
163 const String& getName() const { return mName; }
164
165 SceneManager* getSceneManager() const { return mSceneManager; }
166
173
183
202 void setNumCustomParams( unsigned char numCustomParams );
203
204 unsigned char getNumCustomParams() const
205 { return mNumCustomParams; }
206
209 { return mInstancingTechnique; }
210
222 size_t getMaxOrBestNumInstancesPerBatch( String materialName, size_t suggestedSize, uint16 flags );
223
226
234
259
275 void setSetting( BatchSettingId id, bool enabled, const String &materialName = StringUtil::BLANK );
276
278 bool getSetting( BatchSettingId id, const String &materialName ) const;
279
283 bool hasSettings( const String &materialName ) const
284 { return mBatchSettings.find( materialName ) != mBatchSettings.end(); }
285
288
293
296
299
302 { return InstanceBatchMapIterator( mInstanceBatches.begin(), mInstanceBatches.end() ); }
303
311 {
312 InstanceBatchMap::const_iterator it = mInstanceBatches.find( materialName );
313 if(it != mInstanceBatches.end())
314 return InstanceBatchIterator( it->second.begin(), it->second.end() );
315 else
316 OGRE_EXCEPT(Exception::ERR_INVALID_STATE, "Cannot create instance batch iterator. "
317 "Material " + materialName + " cannot be found.", "InstanceManager::getInstanceBatchIterator");
318 }
319 };
320} // namespace Ogre
321
322#include "OgreHeaderSuffix.h"
323
324#endif // __InstanceManager_H__
#define _OgreExport
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
This is the main starting point for the new instancing system.
'New' rendering operation using vertex buffers.
Manages the organisation and rendering of a 'scene' i.e.
#define OGRE_EXCEPT(code, desc, src)
RenderOperation mSharedRenderOperation
bool getSetting(BatchSettingId id, const String &materialName) const
If settings for the given material didn't exist, default value is returned.
InstanceBatchIterator getInstanceBatchIterator(const String &materialName) const
Get non-updateable iterator over instance batches for given material.
void applySettingToBatches(BatchSettingId id, bool value, const InstanceBatchVec &container)
void setInstancesPerBatch(size_t instancesPerBatch)
Raises an exception if trying to change it after creating the first InstancedEntity.
SceneManager * getSceneManager() const
size_t getMaxOrBestNumInstancesPerBatch(String materialName, size_t suggestedSize, uint16 flags)
Calculates the maximum (or the best amount, depending on flags) of instances per batch given the sugg...
map< String, InstanceBatchVec >::type InstanceBatchMap
InstancingTechnique getInstancingTechnique() const
virtual ~InstanceManager()
vector< InstanceBatch * >::type InstanceBatchVec
void _addDirtyBatch(InstanceBatch *dirtyBatch)
Called by an InstanceBatch when it requests their bounds to be updated for proper culling.
InstanceBatchVec mDirtyBatches
ConstMapIterator< InstanceBatchMap > InstanceBatchMapIterator
InstanceBatch * getFreeBatch(const String &materialName)
Finds a batch with at least one free instanced entity we can use.
void _updateDirtyBatches(void)
Called by SceneManager when we told it we have at least one dirty batch.
BatchSettingId
Values to be used in setSetting() & BatchSettings::setting.
void setMaxLookupTableInstances(size_t maxLookupTableInstances)
Sets the size of the lookup table for techniques supporting bone lookup table.
void cleanupEmptyBatches(void)
This function can be useful to improve CPU speed after having too many instances created,...
InstanceBatch * buildNewBatch(const String &materialName, bool firstTime)
Called when batches are fully exhausted (can't return more instances) so a new batch is created.
ConstVectorIterator< InstanceBatchVec > InstanceBatchIterator
BatchSettingsMap mBatchSettings
const String & getName() const
InstanceBatchMapIterator getInstanceBatchMapIterator(void) const
Get non-updateable iterator over instance batches per material.
InstanceBatchMap mInstanceBatches
void defragmentBatches(bool optimizeCull, vector< InstancedEntity * >::type &entities, vector< Ogre::Vector4 >::type &usedParams, InstanceBatchVec &fragmentedBatches)
void setNumCustomParams(unsigned char numCustomParams)
Sets the number of custom parameters per instance.
void setBatchesAsStaticAndUpdate(bool bStatic)
Tells this batch to stop updating animations, positions, rotations, and display all it's active insta...
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)
unsigned char getNumCustomParams() const
void unshareVertices(const Ogre::MeshPtr &mesh)
Called when we you use a mesh which has shared vertices, the function creates separate vertex/index b...
InstancedEntity * createInstancedEntity(const String &materialName)
Creates an InstancedEntity based on an existing InstanceManager (.
bool hasSettings(const String &materialName) const
Returns true if settings were already created for the given material name.
InstancingTechnique mInstancingTechnique
void defragmentBatches(bool optimizeCulling)
After creating many entities (which turns in many batches) and then removing entities that are in the...
map< String, BatchSettings >::type BatchSettingsMap
void setSetting(BatchSettingId id, bool enabled, const String &materialName=StringUtil::BLANK)
Applies a setting for all batches using the same material_ existing ones and those that will be creat...
@ SHOW_BOUNDINGBOX
Makes each batch to display it's bounding box. Useful for debugging or profiling.
@ HWInstancingBasic
Needs SM 3.0+ and HW instancing support.
@ TextureVTF
Needs Vertex Texture Fetch & SM 3.0+.
@ HWInstancingVTF
Needs SM 3.0+, HW instancing support & VTF.
_StringBase String
std::map< K, V, P, A > type
std::vector< T, A > type