00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __InstanceManager_H__ 00029 #define __InstanceManager_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreMesh.h" 00033 #include "OgreRenderOperation.h" 00034 00035 namespace Ogre 00036 { 00062 class _OgreExport InstanceManager : public FactoryAlloc 00063 { 00064 public: 00065 enum InstancingTechnique 00066 { 00067 ShaderBased, //Any SM 2.0+ @See InstanceBatchShader 00068 TextureVTF, //Needs Vertex Texture Fetch & SM 3.0+ @See InstanceBatchVTF 00069 HWInstancingBasic, //Needs SM 3.0+ and HW instancing support @See InstanceBatchHW 00070 HWInstancingVTF, //Needs SM 3.0+, HW instancing support & VTF @See InstanceBatchHW_VTF 00071 InstancingTechniquesCount 00072 }; 00073 00075 enum BatchSettingId 00076 { 00078 CAST_SHADOWS = 0, 00080 SHOW_BOUNDINGBOX, 00081 00082 NUM_SETTINGS 00083 }; 00084 00085 private: 00086 struct BatchSettings 00087 { 00088 //These are all per material 00089 bool setting[NUM_SETTINGS]; 00090 00091 BatchSettings() 00092 { 00093 setting[CAST_SHADOWS] = true; 00094 setting[SHOW_BOUNDINGBOX] = false; 00095 } 00096 }; 00097 00098 typedef vector<InstanceBatch*>::type InstanceBatchVec; //vec[batchN] = Batch 00099 typedef map<String, InstanceBatchVec>::type InstanceBatchMap; //map[materialName] = Vec 00100 00101 typedef map<String, BatchSettings>::type BatchSettingsMap; 00102 00103 const String mName; //Not the name of the mesh 00104 MeshPtr mMeshReference; 00105 InstanceBatchMap mInstanceBatches; 00106 size_t mIdCount; 00107 00108 InstanceBatchVec mDirtyBatches; 00109 00110 RenderOperation mSharedRenderOperation; 00111 00112 size_t mInstancesPerBatch; 00113 InstancingTechnique mInstancingTechnique; 00114 uint16 mInstancingFlags; //@see InstanceManagerFlags 00115 unsigned short mSubMeshIdx; 00116 00117 BatchSettingsMap mBatchSettings; 00118 SceneManager* mSceneManager; 00119 00120 size_t mMaxLookupTableInstances; 00124 inline InstanceBatch* getFreeBatch( const String &materialName ); 00125 00135 InstanceBatch* buildNewBatch( const String &materialName, bool firstTime ); 00136 00139 void defragmentBatches( bool optimizeCull, vector<InstancedEntity*>::type &entities, 00140 InstanceBatchVec &fragmentedBatches ); 00141 00145 void applySettingToBatches( BatchSettingId id, bool value, const InstanceBatchVec &container ); 00146 00147 public: 00148 InstanceManager( const String &customName, SceneManager *sceneManager, 00149 const String &meshName, const String &groupName, 00150 InstancingTechnique instancingTechnique, uint16 instancingFlags, 00151 size_t instancesPerBatch, unsigned short subMeshIdx, bool useBoneMatrixLookup = false); 00152 virtual ~InstanceManager(); 00153 00154 const String& getName() const { return mName; } 00155 00161 void setInstancesPerBatch( size_t instancesPerBatch ); 00162 00171 void setMaxLookupTableInstances( size_t maxLookupTableInstances ); 00172 00184 size_t getMaxOrBestNumInstancesPerBatch( String materialName, size_t suggestedSize, uint16 flags ); 00185 00187 InstancedEntity* createInstancedEntity( const String &materialName ); 00188 00195 void cleanupEmptyBatches(void); 00196 00220 void defragmentBatches( bool optimizeCulling ); 00221 00237 void setSetting( BatchSettingId id, bool value, const String &materialName = StringUtil::BLANK ); 00238 00240 bool getSetting( BatchSettingId id, const String &materialName ) const; 00241 00245 bool hasSettings( const String &materialName ) const 00246 { return mBatchSettings.find( materialName ) != mBatchSettings.end(); } 00247 00249 void setBatchesAsStaticAndUpdate( bool bStatic ); 00250 00254 void _addDirtyBatch( InstanceBatch *dirtyBatch ); 00255 00257 void _updateDirtyBatches(void); 00258 00259 typedef ConstMapIterator<InstanceBatchMap> InstanceBatchMapIterator; 00260 typedef ConstVectorIterator<InstanceBatchVec> InstanceBatchIterator; 00261 00263 InstanceBatchMapIterator getInstanceBatchMapIterator(void) const 00264 { return InstanceBatchMapIterator( mInstanceBatches.begin(), mInstanceBatches.end() ); } 00265 00272 InstanceBatchIterator getInstanceBatchIterator( const String &materialName ) const 00273 { 00274 InstanceBatchMap::const_iterator it = mInstanceBatches.find( materialName ); 00275 return InstanceBatchIterator( it->second.begin(), it->second.end() ); 00276 } 00277 }; 00278 } 00279 00280 #endif
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:24 2012