OgreInstanceBatch.h

Go to the documentation of this file.
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 __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 
00037 namespace Ogre
00038 {
00087     class _OgreExport InstanceBatch : public Renderable, public MovableObject
00088     {
00089     public:
00090         typedef vector<InstancedEntity*>::type InstancedEntityVec;
00091     protected:
00092         RenderOperation     mRenderOperation;
00093         size_t              mInstancesPerBatch;
00094 
00095         InstanceManager     *mCreator;
00096 
00097         MaterialPtr         mMaterial;
00098 
00099         MeshPtr              mMeshReference;
00100         Mesh::IndexMap const *mIndexToBoneMap;
00101 
00102         //InstancedEntities are all allocated at build time and kept as "unused"
00103         //when they're requested, they're removed from there when requested,
00104         //and put back again when they're no longer needed
00105         //Note each InstancedEntity has a unique ID ranging from [0; mInstancesPerBatch)
00106         InstancedEntityVec  mInstancedEntities;
00107         InstancedEntityVec  mUnusedEntities;
00108 
00110         AxisAlignedBox      mFullBoundingBox;
00111         Real                mBoundingRadius;
00112         bool                mBoundsDirty;
00114         bool                mBoundsUpdated;
00115         Camera              *mCurrentCamera;
00116 
00117         unsigned short      mMaterialLodIndex;
00118 
00120         bool                mDirtyAnimation;
00121 
00123         bool                mTechnSupportsSkeletal;
00124 
00126         mutable Real mCachedCameraDist;
00128         mutable const Camera *mCachedCamera;
00129 
00131         bool mTransformSharingDirty;
00132 
00134         bool mRemoveOwnVertexData;
00136         bool mRemoveOwnIndexData;
00137 
00138         virtual void setupVertices( const SubMesh* baseSubMesh ) = 0;
00139         virtual void setupIndices( const SubMesh* baseSubMesh ) = 0;
00140         virtual void createAllInstancedEntities(void);
00141         virtual void deleteAllInstancedEntities(void);
00142         virtual void deleteUnusedInstancedEntities(void);
00144         virtual InstancedEntity* generateInstancedEntity(size_t num);
00145 
00150         void makeMatrixCameraRelative3x4( float *mat3x4, size_t numFloats );
00151 
00153         virtual bool checkSubMeshCompatibility( const SubMesh* baseSubMesh );
00154 
00155         void updateVisibility(void);
00156 
00158         void defragmentBatchNoCull( InstancedEntityVec &usedEntities );
00159 
00165         void defragmentBatchDoCull( InstancedEntityVec &usedEntities );
00166 
00167     public:
00168         InstanceBatch( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
00169                         size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
00170                         const String &batchName );
00171         virtual ~InstanceBatch();
00172 
00173         MeshPtr& _getMeshRef() { return mMeshReference; }
00174 
00177         void _setInstancesPerBatch( size_t instancesPerBatch );
00178 
00179         const Mesh::IndexMap* _getIndexToBoneMap() const { return mIndexToBoneMap; }
00180 
00187         bool _supportsSkeletalAnimation() const { return mTechnSupportsSkeletal; }
00188 
00190         void _updateBounds(void);
00191 
00202         virtual size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const = 0;
00203 
00217         virtual RenderOperation build( const SubMesh* baseSubMesh );
00218 
00231         virtual void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
00232 
00233         const Ogre::MeshPtr& _getMeshReference(void) const { return mMeshReference; }
00234 
00238         bool isBatchFull(void) const { return mUnusedEntities.empty(); }
00239 
00242         bool isBatchUnused(void) const { return mUnusedEntities.size() == mInstancedEntities.size(); }
00243 
00247         void getInstancedEntitiesInUse( InstancedEntityVec &outEntities );
00248 
00260         void _defragmentBatch( bool optimizeCulling, InstancedEntityVec &usedEntities );
00261 
00267         void _defragmentBatchDiscard(void);
00268 
00272         virtual void _boundsDirty(void);
00273 
00287         virtual void setStaticAndUpdate( bool bStatic )     {}
00288 
00291         virtual bool isStatic() const                       { return false; }
00292 
00299         InstancedEntity* createInstancedEntity();
00300 
00307         void removeInstancedEntity( InstancedEntity *instancedEntity );
00308 
00312         virtual bool useBoneWorldMatrices() const { return true; }
00313 
00315         void _markTransformSharingDirty() { mTransformSharingDirty = true; }
00316 
00317         //Renderable overloads
00319         const MaterialPtr& getMaterial(void) const      { return mMaterial; }
00321         void getRenderOperation( RenderOperation& op )  { op = mRenderOperation; }
00322 
00324         Real getSquaredViewDepth( const Camera* cam ) const;
00326         const LightList& getLights( void ) const;
00328         Technique* getTechnique(void) const;
00329 
00331         const String& getMovableType(void) const;
00333         void _notifyCurrentCamera( Camera* cam );
00335         const AxisAlignedBox& getBoundingBox(void) const;
00337         Real getBoundingRadius(void) const;
00338 
00339         virtual void _updateRenderQueue(RenderQueue* queue);
00340         void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false );
00341     };
00342 }
00343 
00344 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:24 2012