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-2013 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 __InstanceBatch_H__ 00029 #define __InstanceBatch_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreRenderOperation.h" 00033 #include "OgreRenderable.h" 00034 #include "OgreMovableObject.h" 00035 #include "OgreMesh.h" 00036 #include "OgreHeaderPrefix.h" 00037 00038 namespace Ogre 00039 { 00088 class _OgreExport InstanceBatch : public Renderable, public MovableObject 00089 { 00090 public: 00091 typedef vector<InstancedEntity*>::type InstancedEntityVec; 00092 typedef vector<Vector4>::type CustomParamsVec; 00093 protected: 00094 RenderOperation mRenderOperation; 00095 size_t mInstancesPerBatch; 00096 00097 InstanceManager *mCreator; 00098 00099 MaterialPtr mMaterial; 00100 00101 MeshPtr mMeshReference; 00102 Mesh::IndexMap const *mIndexToBoneMap; 00103 00104 //InstancedEntities are all allocated at build time and kept as "unused" 00105 //when they're requested, they're removed from there when requested, 00106 //and put back again when they're no longer needed 00107 //Note each InstancedEntity has a unique ID ranging from [0; mInstancesPerBatch) 00108 InstancedEntityVec mInstancedEntities; 00109 InstancedEntityVec mUnusedEntities; 00110 00114 CustomParamsVec mCustomParams; 00115 00117 AxisAlignedBox mFullBoundingBox; 00118 Real mBoundingRadius; 00119 bool mBoundsDirty; 00120 bool mBoundsUpdated; //Set to false by derived classes that need it 00121 Camera *mCurrentCamera; 00122 00123 unsigned short mMaterialLodIndex; 00124 00125 bool mDirtyAnimation; //Set to false at start of each _updateRenderQueue 00126 00128 bool mTechnSupportsSkeletal; 00129 00131 mutable Real mCachedCameraDist; 00133 mutable const Camera *mCachedCamera; 00134 00136 bool mTransformSharingDirty; 00137 00139 bool mRemoveOwnVertexData; 00141 bool mRemoveOwnIndexData; 00142 00143 virtual void setupVertices( const SubMesh* baseSubMesh ) = 0; 00144 virtual void setupIndices( const SubMesh* baseSubMesh ) = 0; 00145 virtual void createAllInstancedEntities(void); 00146 virtual void deleteAllInstancedEntities(void); 00147 virtual void deleteUnusedInstancedEntities(void); 00149 virtual InstancedEntity* generateInstancedEntity(size_t num); 00150 00155 void makeMatrixCameraRelative3x4( float *mat3x4, size_t numFloats ); 00156 00158 virtual bool checkSubMeshCompatibility( const SubMesh* baseSubMesh ); 00159 00160 void updateVisibility(void); 00161 00163 void defragmentBatchNoCull( InstancedEntityVec &usedEntities, CustomParamsVec &usedParams ); 00164 00170 void defragmentBatchDoCull( InstancedEntityVec &usedEntities, CustomParamsVec &usedParams ); 00171 00172 public: 00173 InstanceBatch( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material, 00174 size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap, 00175 const String &batchName ); 00176 virtual ~InstanceBatch(); 00177 00178 MeshPtr& _getMeshRef() { return mMeshReference; } 00179 00182 void _setInstancesPerBatch( size_t instancesPerBatch ); 00183 00184 const Mesh::IndexMap* _getIndexToBoneMap() const { return mIndexToBoneMap; } 00185 00192 bool _supportsSkeletalAnimation() const { return mTechnSupportsSkeletal; } 00193 00195 void _updateBounds(void); 00196 00207 virtual size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const = 0; 00208 00222 virtual RenderOperation build( const SubMesh* baseSubMesh ); 00223 00236 virtual void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation ); 00237 00238 const Ogre::MeshPtr& _getMeshReference(void) const { return mMeshReference; } 00239 00243 bool isBatchFull(void) const { return mUnusedEntities.empty(); } 00244 00247 bool isBatchUnused(void) const { return mUnusedEntities.size() == mInstancedEntities.size(); } 00248 00252 void getInstancedEntitiesInUse( InstancedEntityVec &outEntities, CustomParamsVec &outParams ); 00253 00267 void _defragmentBatch( bool optimizeCulling, InstancedEntityVec &usedEntities, 00268 CustomParamsVec &usedParams ); 00269 00275 void _defragmentBatchDiscard(void); 00276 00280 virtual void _boundsDirty(void); 00281 00295 virtual void setStaticAndUpdate( bool bStatic ) {} 00296 00299 virtual bool isStatic() const { return false; } 00300 00307 InstancedEntity* createInstancedEntity(); 00308 00315 void removeInstancedEntity( InstancedEntity *instancedEntity ); 00316 00320 virtual bool useBoneWorldMatrices() const { return true; } 00321 00323 void _markTransformSharingDirty() { mTransformSharingDirty = true; } 00324 00326 void _setCustomParam( InstancedEntity *instancedEntity, unsigned char idx, const Vector4 &newParam ); 00327 00329 const Vector4& _getCustomParam( InstancedEntity *instancedEntity, unsigned char idx ); 00330 00331 //Renderable overloads 00333 const MaterialPtr& getMaterial(void) const { return mMaterial; } 00335 void getRenderOperation( RenderOperation& op ) { op = mRenderOperation; } 00336 00338 Real getSquaredViewDepth( const Camera* cam ) const; 00340 const LightList& getLights( void ) const; 00342 Technique* getTechnique(void) const; 00343 00345 const String& getMovableType(void) const; 00347 void _notifyCurrentCamera( Camera* cam ); 00349 const AxisAlignedBox& getBoundingBox(void) const; 00351 Real getBoundingRadius(void) const; 00352 00353 virtual void _updateRenderQueue(RenderQueue* queue); 00354 void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false ); 00355 00356 // resolve ambiguity of get/setUserAny due to inheriting from Renderable and MovableObject 00357 using Renderable::getUserAny; 00358 using Renderable::setUserAny; 00359 }; 00360 } // namespace Ogre 00361 00362 #include "OgreHeaderSuffix.h" 00363 00364 #endif // __InstanceBatch_H__
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:43