OgreStaticGeometry.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __StaticGeometry_H__
29 #define __StaticGeometry_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreMovableObject.h"
33 #include "OgreRenderable.h"
34 #include "OgreMesh.h"
35 #include "OgreLodStrategy.h"
36 #include "OgreHeaderPrefix.h"
37 
38 namespace Ogre {
39 
122  {
123  public:
137  {
138  public:
139  OptimisedSubMeshGeometry() :vertexData(0), indexData(0) {}
141  {
142  OGRE_DELETE vertexData;
143  OGRE_DELETE indexData;
144  }
147  };
152  {
155  };
160  {
163  SubMeshLodGeometryLinkList* geometryLodList;
170  };
174  {
179  };
181 
182  // forward declarations
183  class LODBucket;
184  class MaterialBucket;
185  class Region;
186 
192  {
193  protected:
195  QueuedGeometryList mQueuedGeometry;
210 
211  template<typename T>
212  void copyIndexes(const T* src, T* dst, size_t count, size_t indexOffset)
213  {
214  if (indexOffset == 0)
215  {
216  memcpy(dst, src, sizeof(T) * count);
217  }
218  else
219  {
220  while(count--)
221  {
222  *dst++ = static_cast<T>(*src++ + indexOffset);
223  }
224  }
225  }
226  public:
227  GeometryBucket(MaterialBucket* parent, const String& formatString,
228  const VertexData* vData, const IndexData* iData);
229  virtual ~GeometryBucket();
230  MaterialBucket* getParent(void) { return mParent; }
232  const VertexData* getVertexData(void) const { return mVertexData; }
234  const IndexData* getIndexData(void) const { return mIndexData; }
236  const MaterialPtr& getMaterial(void) const;
237  Technique* getTechnique(void) const;
238  void getRenderOperation(RenderOperation& op);
239  void getWorldTransforms(Matrix4* xform) const;
240  Real getSquaredViewDepth(const Camera* cam) const;
241  const LightList& getLights(void) const;
242  bool getCastsShadows(void) const;
243 
247  bool assign(QueuedGeometry* qsm);
249  void build(bool stencilShadows);
251  void dump(std::ofstream& of) const;
252  };
256  {
257  public:
260  protected:
269 
271  GeometryBucketList mGeometryBucketList;
272  // index to current Geometry Buckets for a given geometry format
274  CurrentGeometryMap mCurrentGeometryMap;
276  String getGeometryFormatString(SubMeshLodGeometryLink* geom);
277 
278  public:
279  MaterialBucket(LODBucket* parent, const String& materialName);
280  virtual ~MaterialBucket();
281  LODBucket* getParent(void) { return mParent; }
283  const String& getMaterialName(void) const { return mMaterialName; }
285  void assign(QueuedGeometry* qsm);
287  void build(bool stencilShadows);
289  void addRenderables(RenderQueue* queue, uint8 group,
290  Real lodValue);
292  const MaterialPtr& getMaterial(void) const { return mMaterial; }
296  GeometryIterator getGeometryIterator(void);
298  Technique* getCurrentTechnique(void) const { return mTechnique; }
300  void dump(std::ofstream& of) const;
301  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables);
302  };
309  {
310  public:
313  protected:
316  {
317  protected:
319  // Shared link to position buffer
321  // Shared link to w-coord buffer (optional)
323 
324  public:
326  HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
327  bool createSeparateLightCap, bool isLightCap = false);
330  void getWorldTransforms(Matrix4* xform) const;
331  HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
332  HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
334  virtual void rebindIndexBuffer(const HardwareIndexBufferSharedPtr& indexBuffer);
335 
336  };
340  unsigned short mLod;
344  MaterialBucketMap mMaterialBucketMap;
346  QueuedGeometryList mQueuedGeometryList;
353  public:
354  LODBucket(Region* parent, unsigned short lod, Real lodValue);
355  virtual ~LODBucket();
356  Region* getParent(void) { return mParent; }
358  ushort getLod(void) const { return mLod; }
360  Real getLodValue(void) const { return mLodValue; }
362  void assign(QueuedSubMesh* qsm, ushort atLod);
364  void build(bool stencilShadows);
366  void addRenderables(RenderQueue* queue, uint8 group,
367  Real lodValue);
371  MaterialIterator getMaterialIterator(void);
373  void dump(std::ofstream& of) const;
374  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables);
375  EdgeData* getEdgeList() const { return mEdgeList; }
377  bool isVertexProgramInUse() const { return mVertexProgramInUse; }
378  void updateShadowRenderables(
379  ShadowTechnique shadowTechnique, const Vector4& lightPos,
380  HardwareIndexBufferSharedPtr* indexBuffer,
381  bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
382 
383  };
393  {
394  friend class MaterialBucket;
395  friend class GeometryBucket;
396  public:
399  protected:
407  QueuedSubMeshList mQueuedSubMeshes;
423  LODBucketList mLodBucketList;
434 
435  public:
436  Region(StaticGeometry* parent, const String& name, SceneManager* mgr,
437  uint32 regionID, const Vector3& centre);
438  virtual ~Region();
439  // more fields can be added in subclasses
440  StaticGeometry* getParent(void) const { return mParent;}
442  void assign(QueuedSubMesh* qmesh);
444  void build(bool stencilShadows);
446  uint32 getID(void) const { return mRegionID; }
448  const Vector3& getCentre(void) const { return mCentre; }
449  const String& getMovableType(void) const;
450  void _notifyCurrentCamera(Camera* cam);
451  const AxisAlignedBox& getBoundingBox(void) const;
452  Real getBoundingRadius(void) const;
453  void _updateRenderQueue(RenderQueue* queue);
455  void visitRenderables(Renderable::Visitor* visitor,
456  bool debugRenderables = false);
457  bool isVisible(void) const;
458  uint32 getTypeFlags(void) const;
459 
462  LODIterator getLODIterator(void);
464  ShadowRenderableListIterator getShadowVolumeRenderableIterator(
465  ShadowTechnique shadowTechnique, const Light* light,
466  HardwareIndexBufferSharedPtr* indexBuffer, size_t* indexBufferUsedSize,
467  bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
469  EdgeData* getEdgeList(void);
471  bool hasEdgeList(void);
472 
474  void dump(std::ofstream& of) const;
475 
476  };
485  protected:
486  // General state & settings
489  bool mBuilt;
496  bool mVisible;
503 
504  QueuedSubMeshList mQueuedSubMeshes;
505 
508  OptimisedSubMeshGeometryList mOptimisedSubMeshGeometryList;
509 
514  SubMeshGeometryLookup mSubMeshGeometryLookup;
515 
517  RegionMap mRegionMap;
518 
522  virtual Region* getRegion(const AxisAlignedBox& bounds, bool autoCreate);
524  virtual Region* getRegion(const Vector3& point, bool autoCreate);
526  virtual Region* getRegion(ushort x, ushort y, ushort z, bool autoCreate);
528  virtual Region* getRegion(uint32 index);
531  virtual void getRegionIndexes(const Vector3& point,
532  ushort& x, ushort& y, ushort& z);
535  virtual uint32 packIndex(ushort x, ushort y, ushort z);
538  virtual Real getVolumeIntersection(const AxisAlignedBox& box,
539  ushort x, ushort y, ushort z);
542  virtual AxisAlignedBox getRegionBounds(ushort x, ushort y, ushort z);
545  virtual Vector3 getRegionCentre(ushort x, ushort y, ushort z);
547  virtual AxisAlignedBox calculateBounds(VertexData* vertexData,
548  const Vector3& position, const Quaternion& orientation,
549  const Vector3& scale);
551  SubMeshLodGeometryLinkList* determineGeometry(SubMesh* sm);
553  void splitGeometry(VertexData* vd, IndexData* id,
554  SubMeshLodGeometryLink* targetGeomLink);
555 
561  template <typename T>
562  void buildIndexRemap(T* pBuffer, size_t numIndexes, IndexRemap& remap)
563  {
564  remap.clear();
565  for (size_t i = 0; i < numIndexes; ++i)
566  {
567  // use insert since duplicates are silently discarded
568  remap.insert(IndexRemap::value_type(*pBuffer++, remap.size()));
569  // this will have mapped oldindex -> new index IF oldindex
570  // wasn't already there
571  }
572  }
574  template <typename T>
575  void remapIndexes(T* src, T* dst, const IndexRemap& remap,
576  size_t numIndexes)
577  {
578  for (size_t i = 0; i < numIndexes; ++i)
579  {
580  // look up original and map to target
581  IndexRemap::const_iterator ix = remap.find(*src++);
582  assert(ix != remap.end());
583  *dst++ = static_cast<T>(ix->second);
584  }
585  }
586 
587  public:
589  StaticGeometry(SceneManager* owner, const String& name);
591  virtual ~StaticGeometry();
592 
594  const String& getName(void) const { return mName; }
613  virtual void addEntity(Entity* ent, const Vector3& position,
614  const Quaternion& orientation = Quaternion::IDENTITY,
615  const Vector3& scale = Vector3::UNIT_SCALE);
616 
635  virtual void addSceneNode(const SceneNode* node);
636 
647  virtual void build(void);
648 
654  virtual void destroy(void);
655 
659  virtual void reset(void);
660 
670  virtual void setRenderingDistance(Real dist) {
671  mUpperDistance = dist;
672  mSquaredUpperDistance = mUpperDistance * mUpperDistance;
673  }
674 
676  virtual Real getRenderingDistance(void) const { return mUpperDistance; }
677 
679  virtual Real getSquaredRenderingDistance(void) const
680  { return mSquaredUpperDistance; }
681 
683  virtual void setVisible(bool visible);
684 
686  virtual bool isVisible(void) const { return mVisible; }
687 
705  virtual void setCastShadows(bool castShadows);
707  virtual bool getCastShadows(void) { return mCastShadows; }
708 
719  virtual void setRegionDimensions(const Vector3& size) {
720  mRegionDimensions = size;
721  mHalfRegionDimensions = size * 0.5;
722  }
724  virtual const Vector3& getRegionDimensions(void) const { return mRegionDimensions; }
736  virtual void setOrigin(const Vector3& origin) { mOrigin = origin; }
738  virtual const Vector3& getOrigin(void) const { return mOrigin; }
739 
741  void setVisibilityFlags(uint32 flags);
743  uint32 getVisibilityFlags() const;
744 
756  virtual void setRenderQueueGroup(uint8 queueID);
757 
759  virtual uint8 getRenderQueueGroup(void) const;
761  void visitRenderables(Renderable::Visitor* visitor,
762  bool debugRenderables = false);
763 
767  RegionIterator getRegionIterator(void);
768 
772  virtual void dump(const String& filename) const;
773 
774 
775  };
779 }
780 
781 #include "OgreHeaderSuffix.h"
782 
783 #endif
784 
Real mLodValue
LOD value at which this LOD starts to apply (squared)
Class which represents the renderable aspects of a set of shadow volume faces.
uint32 mVisibilityFlags
Stores the visibility flags for the regions.
ushort getLod(void) const
Get the LOD index.
Concrete IteratorWrapper for nonconst access to the underlying container.
MaterialBucket * mParent
Pointer to parent bucket.
LODBucket * mParent
Pointer to parent LODBucket.
vector< QueuedGeometry * >::type QueuedGeometryList
Abstract class defining the interface all renderable objects must implement.
VectorIterator< LODBucketList > LODIterator
#define _OgreExport
Definition: OgrePlatform.h:257
list< OptimisedSubMeshGeometry * >::type OptimisedSubMeshGeometryList
virtual void setRegionDimensions(const Vector3 &size)
Sets the size of a single region of geometry.
Abstract class defining a movable object in a scene.
virtual Real getSquaredRenderingDistance(void) const
Gets the squared distance at which batches are no longer rendered.
Strategy for determining level of detail.
Shared pointer implementation used to share index buffers.
ulong mLightListUpdated
The last frame that this light list was updated in.
Structure recording a queued submesh for the build.
MaterialBucketMap mMaterialBucketMap
Lookup of Material Buckets in this region.
AxisAlignedBox worldBounds
Pre-transformed world AABB.
std::vector< T, A > type
#define OGRE_DELETE
Camera * mCamera
Current camera.
bool mVertexProgramInUse
Is a vertex program in use somewhere in this group?
const String & getName(void) const
Get the name of this object.
virtual void setOrigin(const Vector3 &origin)
Sets the origin of the geometry.
Summary class collecting together vertex source information.
virtual void setRenderingDistance(Real dist)
Sets the distance at which batches are no longer rendered.
uint32 getID(void) const
Get the region ID of this region.
Implementation of a Quaternion, i.e.
QueuedSubMeshList mQueuedSubMeshes
vector< ShadowRenderable * >::type ShadowRenderableList
Vector3 mCentre
Center of the region.
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
SubMeshGeometryLookup mSubMeshGeometryLookup
Cached links from SubMeshes to (potentially optimised) geometry This is not used for deletion since t...
String mFormatString
String identifying the vertex / index format.
float Real
Software floating point type.
void copyIndexes(const T *src, T *dst, size_t count, size_t indexOffset)
size_t mMaxVertexIndex
Maximum vertex indexable.
virtual Real getRenderingDistance(void) const
Gets the distance at which batches are no longer rendered.
vector< QueuedSubMesh * >::type QueuedSubMeshList
bool mRenderQueueIDSet
Flags whether the RenderQueue&#39;s default should be used.
Class to manage the scene object rendering queue.
Summary class collecting together index data source information.
VectorIterator< GeometryBucketList > GeometryIterator
Iterator over geometry.
const VertexData * getVertexData(void) const
Get the vertex data for this geometry.
SceneNode * mNode
Scene node.
QueuedGeometryList mQueuedGeometry
Geometry which has been queued up pre-build (not for deallocation)
HardwareVertexBufferSharedPtr getPositionBuffer(void)
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:58
map< String, MaterialBucket * >::type MaterialBucketMap
Lookup of Material Buckets in this region.
Structure recording a queued geometry for low level builds.
ShadowTechnique
An enumeration of broad shadow techniques.
Definition: OgreCommon.h:190
const String & getMaterialName(void) const
Get the material name.
const IndexData * getIndexData(void) const
Get the index data for this geometry.
MapIterator< MaterialBucketMap > MaterialIterator
Iterator over the materials in this LOD.
vector< GeometryBucket * >::type GeometryBucketList
list of Geometry Buckets in this region
This class contains the information required to describe the edge connectivity of a given set of vert...
map< SubMesh *, SubMeshLodGeometryLinkList * >::type SubMeshGeometryLookup
String mMaterialName
Material being used.
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:62
unsigned short mLod
LOD level (0 == full LOD)
A LODBucket is a collection of smaller buckets with the same LOD.
ShadowCaster::ShadowRenderableList & getShadowRenderableList()
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
HardwareIndexBuffer::IndexType mIndexType
Size of indexes.
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Real mLodValue
Current LOD value, passed on to do material LOD later.
A GeometryBucket is a the lowest level bucket where geometry with the same vertex & index format is s...
Shared pointer implementation used to share vertex buffers.
uint32 mRegionID
Unique identifier for the region.
std::map< K, V, P, A > type
Technique * getCurrentTechnique(void) const
Get the current Technique.
#define _OgrePrivate
Definition: OgrePlatform.h:258
virtual const Vector3 & getRegionDimensions(void) const
Gets the size of a single batch of geometry.
StaticGeometry * mParent
Parent static geometry.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
map< String, GeometryBucket * >::type CurrentGeometryMap
vector< Real >::type LodValueList
Definition: OgreMesh.h:102
AxisAlignedBox mAABB
Local AABB relative to region centre.
unsigned char uint8
Definition: OgrePlatform.h:361
map< uint32, Region * >::type RegionMap
Indexed region map based on packed x/y/z region index, 10 bits for each axis.
virtual const Vector3 & getOrigin(void) const
Gets the origin of this geometry.
LightList mLightList
List of lights for this region.
vector< LODBucket * >::type LODBucketList
list of LOD Buckets in this region
Real getLodValue(void) const
Get the LOD value.
_StringBase String
RegionMap mRegionMap
Map of regions.
map< size_t, size_t >::type IndexRemap
static const Vector3 UNIT_SCALE
Definition: OgreVector3.h:807
EdgeData * mEdgeList
Edge list, used if stencil shadow casting is enabled.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
ushort mCurrentLod
The current LOD level, as determined from the last camera.
VertexData * mVertexData
Vertex information, includes current number of vertices committed to be a part of this bucket...
Struct holding geometry optimised per SubMesh / LOD level, ready for copying to instances.
OptimisedSubMeshGeometryList mOptimisedSubMeshGeometryList
List of geometry which has been optimised for SubMesh use This is the primary storage used for cleani...
StaticGeometry * getParent(void) const
unsigned int uint32
Definition: OgrePlatform.h:359
A MaterialBucket is a collection of smaller buckets with the same Material (and implicitly the same L...
IndexData * mIndexData
Index information, includes index type which limits the max number of vertices which are allowed in o...
GeometryBucketList mGeometryBucketList
list of Geometry Buckets in this region
vector< SubMeshLodGeometryLink >::type SubMeshLodGeometryLinkList
uint8 mRenderQueueID
The render queue to use when rendering this object.
MapIterator< RegionMap > RegionIterator
Iterator for iterating over contained regions.
Pre-transforms and batches up meshes for efficient use as static geometry in a scene.
QueuedGeometryList mQueuedGeometryList
Geometry queued for a single LOD (deallocated here)
virtual bool getCastShadows(void)
Will the geometry from this object cast shadows?
Region * mParent
Pointer to parent region.
unsigned long ulong
const Vector3 & getCentre(void) const
Get the centre point of the region.
void remapIndexes(T *src, T *dst, const IndexRemap &remap, size_t numIndexes)
Method for altering indexes based on a remap.
Technique * mTechnique
Active technique.
&#39;New&#39; rendering operation using vertex buffers.
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:53
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:82
Mesh::LodValueList mLodValues
LOD values as built up - use the max at each level.
The details of a topological region which is the highest level of partitioning for this class...
unsigned short ushort
static const Quaternion IDENTITY
virtual bool isVisible(void) const
Are the batches visible?
Real mSquaredViewDepth
Cached squared view depth value to avoid recalculation by GeometryBucket.
A 3D box aligned with the x/y/z axes.
Manages the organisation and rendering of a &#39;scene&#39; i.e.
SubMeshLodGeometryLinkList * geometryLodList
Link to LOD list of geometry, potentially optimised.
const LodStrategy * mLodStrategy
LOD strategy reference.
LODBucketList mLodBucketList
List of LOD buckets.
ShadowCaster::ShadowRenderableList mShadowRenderables
List of shadow renderables.
const MaterialPtr & getMaterial(void) const
Get the material for this bucket.
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:73
QueuedSubMeshList mQueuedSubMeshes
Local list of queued meshes (not used for deallocation)
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Real mBoundingRadius
Local bounding radius.
SceneManager * mSceneMgr
Scene manager link.
void buildIndexRemap(T *pBuffer, size_t numIndexes, IndexRemap &remap)
Method for figuring out which vertices are used by an index buffer and calculating a remap lookup for...
MaterialPtr mMaterial
Pointer to material being used.

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