OgreInstanceBatch.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 __InstanceBatch_H__
#define __InstanceBatch_H__
#include "OgrePrerequisites.h"
#include "OgreRenderOperation.h"
#include "OgreRenderable.h"
#include "OgreMovableObject.h"
#include "OgreMesh.h"
#include "OgreHeaderPrefix.h"
namespace Ogre
{
class _OgreExport InstanceBatch : public Renderable, public MovableObject
{
public:
typedef vector<InstancedEntity*>::type InstancedEntityVec;
typedef vector<Vector4>::type CustomParamsVec;
protected:
RenderOperation mRenderOperation;
size_t mInstancesPerBatch;
InstanceManager *mCreator;
MaterialPtr mMaterial;
MeshPtr mMeshReference;
Mesh::IndexMap const *mIndexToBoneMap;
//InstancedEntities are all allocated at build time and kept as "unused"
//when they're requested, they're removed from there when requested,
//and put back again when they're no longer needed
//Note each InstancedEntity has a unique ID ranging from [0; mInstancesPerBatch)
InstancedEntityVec mInstancedEntities;
InstancedEntityVec mUnusedEntities;
CustomParamsVec mCustomParams;
AxisAlignedBox mFullBoundingBox;
Real mBoundingRadius;
bool mBoundsDirty;
bool mBoundsUpdated; //Set to false by derived classes that need it
Camera *mCurrentCamera;
unsigned short mMaterialLodIndex;
bool mDirtyAnimation; //Set to false at start of each _updateRenderQueue
bool mTechnSupportsSkeletal;
mutable Real mCachedCameraDist;
mutable const Camera *mCachedCamera;
bool mTransformSharingDirty;
bool mRemoveOwnVertexData;
bool mRemoveOwnIndexData;
virtual void setupVertices( const SubMesh* baseSubMesh ) = 0;
virtual void setupIndices( const SubMesh* baseSubMesh ) = 0;
virtual void createAllInstancedEntities(void);
virtual void deleteAllInstancedEntities(void);
virtual void deleteUnusedInstancedEntities(void);
virtual InstancedEntity* generateInstancedEntity(size_t num);
void makeMatrixCameraRelative3x4( float *mat3x4, size_t numFloats );
virtual bool checkSubMeshCompatibility( const SubMesh* baseSubMesh );
void updateVisibility(void);
void defragmentBatchNoCull( InstancedEntityVec &usedEntities, CustomParamsVec &usedParams );
void defragmentBatchDoCull( InstancedEntityVec &usedEntities, CustomParamsVec &usedParams );
public:
InstanceBatch( InstanceManager *creator, MeshPtr &meshReference, const MaterialPtr &material,
size_t instancesPerBatch, const Mesh::IndexMap *indexToBoneMap,
const String &batchName );
virtual ~InstanceBatch();
MeshPtr& _getMeshRef() { return mMeshReference; }
void _setInstancesPerBatch( size_t instancesPerBatch );
const Mesh::IndexMap* _getIndexToBoneMap() const { return mIndexToBoneMap; }
bool _supportsSkeletalAnimation() const { return mTechnSupportsSkeletal; }
void _updateBounds(void);
virtual size_t calculateMaxNumInstances( const SubMesh *baseSubMesh, uint16 flags ) const = 0;
virtual RenderOperation build( const SubMesh* baseSubMesh );
virtual void buildFrom( const SubMesh *baseSubMesh, const RenderOperation &renderOperation );
const Ogre::MeshPtr& _getMeshReference(void) const { return mMeshReference; }
bool isBatchFull(void) const { return mUnusedEntities.empty(); }
bool isBatchUnused(void) const { return mUnusedEntities.size() == mInstancedEntities.size(); }
void getInstancedEntitiesInUse( InstancedEntityVec &outEntities, CustomParamsVec &outParams );
void _defragmentBatch( bool optimizeCulling, InstancedEntityVec &usedEntities,
CustomParamsVec &usedParams );
void _defragmentBatchDiscard(void);
virtual void _boundsDirty(void);
virtual void setStaticAndUpdate( bool bStatic ) {}
virtual bool isStatic() const { return false; }
InstancedEntity* createInstancedEntity();
void removeInstancedEntity( InstancedEntity *instancedEntity );
virtual bool useBoneWorldMatrices() const { return true; }
void _markTransformSharingDirty() { mTransformSharingDirty = true; }
void _setCustomParam( InstancedEntity *instancedEntity, unsigned char idx, const Vector4 &newParam );
const Vector4& _getCustomParam( InstancedEntity *instancedEntity, unsigned char idx );
//Renderable overloads
const MaterialPtr& getMaterial(void) const { return mMaterial; }
void getRenderOperation( RenderOperation& op ) { op = mRenderOperation; }
Real getSquaredViewDepth( const Camera* cam ) const;
const LightList& getLights( void ) const;
Technique* getTechnique(void) const;
const String& getMovableType(void) const;
void _notifyCurrentCamera( Camera* cam );
const AxisAlignedBox& getBoundingBox(void) const;
Real getBoundingRadius(void) const;
virtual void _updateRenderQueue(RenderQueue* queue);
void visitRenderables( Renderable::Visitor* visitor, bool debugRenderables = false );
// resolve ambiguity of get/setUserAny due to inheriting from Renderable and MovableObject
using Renderable::getUserAny;
using Renderable::setUserAny;
};
} // namespace Ogre
#include "OgreHeaderSuffix.h"
#endif // __InstanceBatch_H__
Ogre::InstanceBatch::_getMeshRef
MeshPtr & _getMeshRef()
Definition: OgreInstanceBatch.h:178
Ogre::InstanceBatch::_markTransformSharingDirty
void _markTransformSharingDirty()
Tells that the list of entity instances with shared transforms has changed.
Definition: OgreInstanceBatch.h:323
Ogre::InstanceBatch::isBatchUnused
bool isBatchUnused(void) const
Returns true if it no instanced entity has been requested or all of them have been removed...
Definition: OgreInstanceBatch.h:247
Ogre::Renderable
Abstract class defining the interface all renderable objects must implement.
Definition: OgreRenderable.h:63
Ogre::InstanceBatch::mMaterial
MaterialPtr mMaterial
Definition: OgreInstanceBatch.h:99
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::MovableObject
Abstract class defining a movable object in a scene.
Definition: OgreMovableObject.h:60
Ogre::InstanceBatch::isStatic
virtual bool isStatic() const
Returns true if this batch was set as static.
Definition: OgreInstanceBatch.h:299
OgreRenderable.h
OgreMovableObject.h
Ogre::InstanceBatch::mMeshReference
MeshPtr mMeshReference
Definition: OgreInstanceBatch.h:101
OgreMesh.h
Ogre::Vector4
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
Ogre::InstanceBatch::mUnusedEntities
InstancedEntityVec mUnusedEntities
Definition: OgreInstanceBatch.h:109
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Renderable::setUserAny
virtual OGRE_DEPRECATED void setUserAny(const Any &anything)
Definition: OgreRenderable.h:344
Ogre::InstanceBatch::mIndexToBoneMap
Mesh::IndexMap const * mIndexToBoneMap
Definition: OgreInstanceBatch.h:102
Ogre::RenderQueue
Class to manage the scene object rendering queue.
Definition: OgreRenderQueue.h:92
Ogre::InstanceBatch::mDirtyAnimation
bool mDirtyAnimation
Definition: OgreInstanceBatch.h:125
Ogre::InstanceBatch::mTechnSupportsSkeletal
bool mTechnSupportsSkeletal
False if a technique doesn&#39;t support skeletal animation.
Definition: OgreInstanceBatch.h:128
Ogre::Renderable::getUserAny
virtual OGRE_DEPRECATED const Any & getUserAny(void) const
Definition: OgreRenderable.h:349
Ogre::SubMesh
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:62
Ogre::InstanceBatch::_getMeshReference
const Ogre::MeshPtr & _getMeshReference(void) const
Definition: OgreInstanceBatch.h:238
Ogre::InstanceBatch::mRemoveOwnIndexData
bool mRemoveOwnIndexData
When true remove the memory of the IndexData we&#39;ve created because no one else will.
Definition: OgreInstanceBatch.h:141
OgrePrerequisites.h
Ogre::InstanceBatch::setStaticAndUpdate
virtual void setStaticAndUpdate(bool bStatic)
Tells this batch to stop updating animations, positions, rotations, and display all it&#39;s active insta...
Definition: OgreInstanceBatch.h:295
Ogre::HashedVector
A hashed vector.
Definition: OgreCommon.h:332
Ogre::Renderable::Visitor
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
Definition: OgreRenderable.h:377
Ogre::InstanceBatch::isBatchFull
bool isBatchFull(void) const
Definition: OgreInstanceBatch.h:243
OgreRenderOperation.h
Ogre::InstanceBatch::mBoundsUpdated
bool mBoundsUpdated
Definition: OgreInstanceBatch.h:120
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::InstanceManager
This is the main starting point for the new instancing system.
Definition: OgreInstanceManager.h:63
Ogre::InstanceBatch::_supportsSkeletalAnimation
bool _supportsSkeletalAnimation() const
Returns true if this technique supports skeletal animation.
Definition: OgreInstanceBatch.h:192
Ogre::InstanceBatch::mCurrentCamera
Camera * mCurrentCamera
Definition: OgreInstanceBatch.h:121
Ogre::InstanceBatch::mCreator
InstanceManager * mCreator
Definition: OgreInstanceBatch.h:97
Ogre::InstanceBatch::mInstancesPerBatch
size_t mInstancesPerBatch
Definition: OgreInstanceBatch.h:95
Ogre::Camera
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
OgreHeaderSuffix.h
Ogre::InstanceBatch::mMaterialLodIndex
unsigned short mMaterialLodIndex
Definition: OgreInstanceBatch.h:123
Ogre::InstanceBatch
InstanceBatch forms part of the new Instancing system This is an abstract class that must be derived ...
Definition: OgreInstanceBatch.h:88
Ogre::InstanceBatch::mCachedCamera
const Camera * mCachedCamera
The camera for which the cached distance is valid.
Definition: OgreInstanceBatch.h:133
Ogre::InstanceBatch::InstancedEntityVec
vector< InstancedEntity * >::type InstancedEntityVec
Definition: OgreInstanceBatch.h:91
Ogre::InstanceBatch::getMaterial
const MaterialPtr & getMaterial(void) const
Definition: OgreInstanceBatch.h:333
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::InstanceBatch::CustomParamsVec
vector< Vector4 >::type CustomParamsVec
Definition: OgreInstanceBatch.h:92
Ogre::SharedPtr< Material >
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::InstanceBatch::_getIndexToBoneMap
const Mesh::IndexMap * _getIndexToBoneMap() const
Definition: OgreInstanceBatch.h:184
OgreHeaderPrefix.h
Ogre::InstanceBatch::mRenderOperation
RenderOperation mRenderOperation
Definition: OgreInstanceBatch.h:94
Ogre::InstanceBatch::useBoneWorldMatrices
virtual bool useBoneWorldMatrices() const
Tells whether world bone matrices need to be calculated.
Definition: OgreInstanceBatch.h:320
Ogre::RenderOperation
&#39;New&#39; rendering operation using vertex buffers.
Definition: OgreRenderOperation.h:45
Ogre::Technique
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:53
Ogre::InstanceBatch::mTransformSharingDirty
bool mTransformSharingDirty
Tells that the list of entity instances with shared transforms has changed.
Definition: OgreInstanceBatch.h:136
Ogre::InstanceBatch::mRemoveOwnVertexData
bool mRemoveOwnVertexData
When true remove the memory of the VertexData we&#39;ve created because no one else will.
Definition: OgreInstanceBatch.h:139
Ogre::InstanceBatch::mBoundingRadius
Real mBoundingRadius
Definition: OgreInstanceBatch.h:118
Ogre::InstanceBatch::mCustomParams
CustomParamsVec mCustomParams
Definition: OgreInstanceBatch.h:114
Ogre::Mesh::IndexMap
vector< unsigned short >::type IndexMap
Definition: OgreMesh.h:108
Ogre::InstanceBatch::mInstancedEntities
InstancedEntityVec mInstancedEntities
Definition: OgreInstanceBatch.h:108
Ogre::InstanceBatch::mCachedCameraDist
Real mCachedCameraDist
Cached distance to last camera for getSquaredViewDepth.
Definition: OgreInstanceBatch.h:131
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
Ogre::InstanceBatch::mBoundsDirty
bool mBoundsDirty
Definition: OgreInstanceBatch.h:119
Ogre::InstancedEntity
Definition: OgreInstancedEntity.h:77
Ogre::InstanceBatch::getRenderOperation
void getRenderOperation(RenderOperation &op)
Definition: OgreInstanceBatch.h:335
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::InstanceBatch::mFullBoundingBox
AxisAlignedBox mFullBoundingBox
This bbox contains all (visible) instanced entities.
Definition: OgreInstanceBatch.h:117

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