OGRE  1.9
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2014 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  {
170  };
174  {
179  };
181 
182  // forward declarations
183  class LODBucket;
184  class MaterialBucket;
185  class Region;
186 
192  {
193  protected:
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 
272  // index to current Geometry Buckets for a given geometry format
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;
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:
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 
505 
509 
515 
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 
void copyIndexes(const T *src, T *dst, size_t count, size_t indexOffset)
unsigned char uint8
Definition: OgrePlatform.h:346
const VertexData * getVertexData(void) const
Get the vertex data for this geometry.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
map< SubMesh *, SubMeshLodGeometryLinkList * >::type SubMeshGeometryLookup
Struct holding geometry optimised per SubMesh / LOD level, ready for copying to instances.
float Real
Software floating point type.
SceneManager * mSceneMgr
Scene manager link.
LODBucket * mParent
Pointer to parent LODBucket.
unsigned int uint32
Definition: OgrePlatform.h:344
ulong mLightListUpdated
The last frame that this light list was updated in.
QueuedSubMeshList mQueuedSubMeshes
Local list of queued meshes (not used for deallocation)
#define _OgreExport
Definition: OgrePlatform.h:260
HardwareIndexBuffer::IndexType mIndexType
Size of indexes.
map< size_t, size_t >::type IndexRemap
Real mBoundingRadius
Local bounding radius.
std::vector< T, A > type
unsigned long ulong
Pre-transforms and batches up meshes for efficient use as static geometry in a scene.
uint32 mRegionID
Unique identifier for the region.
Real mSquaredViewDepth
Cached squared view depth value to avoid recalculation by GeometryBucket.
ushort mCurrentLod
The current LOD level, as determined from the last camera.
ShadowCaster::ShadowRenderableList & getShadowRenderableList()
StaticGeometry * getParent(void) const
Manages the organisation and rendering of a 'scene' i.e.
vector< LODBucket * >::type LODBucketList
list of LOD Buckets in this region
vector< SubMeshLodGeometryLink >::type SubMeshLodGeometryLinkList
bool mVertexProgramInUse
Is a vertex program in use somewhere in this group?
A GeometryBucket is a the lowest level bucket where geometry with the same vertex & index format is s...
QueuedGeometryList mQueuedGeometryList
Geometry queued for a single LOD (deallocated here)
MapIterator< RegionMap > RegionIterator
Iterator for iterating over contained regions.
Shared pointer implementation used to share vertex buffers.
A 3D box aligned with the x/y/z axes.
Real mLodValue
Current LOD value, passed on to do material LOD later.
virtual const Vector3 & getRegionDimensions(void) const
Gets the size of a single batch of geometry.
const LodStrategy * mLodStrategy
LOD strategy reference.
GeometryBucketList mGeometryBucketList
list of Geometry Buckets in this region
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:53
Strategy for determining level of detail.
const MaterialPtr & getMaterial(void) const
Get the material for this bucket.
StaticGeometry * mParent
Parent static geometry.
map< uint32, Region * >::type RegionMap
Indexed region map based on packed x/y/z region index, 10 bits for each axis.
Abstract class defining a movable object in a scene.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:58
VertexData * mVertexData
Vertex information, includes current number of vertices committed to be a part of this bucket...
VectorIterator< GeometryBucketList > GeometryIterator
Iterator over geometry.
Structure recording a queued submesh for the build.
Abstract class defining the interface all renderable objects must implement.
Implementation of a Quaternion, i.e.
Concrete IteratorWrapper for nonconst access to the underlying key-value container.
uint8 mRenderQueueID
The render queue to use when rendering this object.
Shared pointer implementation used to share index buffers.
list< OptimisedSubMeshGeometry * >::type OptimisedSubMeshGeometryList
Representation of a dynamic light source in the scene.
Definition: OgreLight.h:73
A LODBucket is a collection of smaller buckets with the same LOD.
Region * mParent
Pointer to parent region.
Vector3 mCentre
Center of the region.
ShadowCaster::ShadowRenderableList mShadowRenderables
List of shadow renderables.
String mFormatString
String identifying the vertex / index format.
Real getLodValue(void) const
Get the LOD value.
const String & getName(void) const
Get the name of this object.
static const Quaternion IDENTITY
HardwareVertexBufferSharedPtr getPositionBuffer(void)
ShadowTechnique
An enumeration of broad shadow techniques.
Definition: OgreCommon.h:190
void remapIndexes(T *src, T *dst, const IndexRemap &remap, size_t numIndexes)
Method for altering indexes based on a remap.
uint32 getID(void) const
Get the region ID of this region.
vector< QueuedSubMesh * >::type QueuedSubMeshList
const IndexData * getIndexData(void) const
Get the index data for this geometry.
#define _OgrePrivate
Definition: OgrePlatform.h:261
Structure recording a queued geometry for low level builds.
virtual Real getSquaredRenderingDistance(void) const
Gets the squared distance at which batches are no longer rendered.
Class which represents the renderable aspects of a set of shadow volume faces.
EdgeData * mEdgeList
Edge list, used if stencil shadow casting is enabled.
Defines an instance of a discrete, movable object based on a Mesh.
Definition: OgreEntity.h:82
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
SubMeshLodGeometryLinkList * geometryLodList
Link to LOD list of geometry, potentially optimised.
String mMaterialName
Material being used.
Real mLodValue
LOD value at which this LOD starts to apply (squared)
Technique * mTechnique
Active technique.
Summary class collecting together index data source information.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
The details of a topological region which is the highest level of partitioning for this class...
virtual const Vector3 & getOrigin(void) const
Gets the origin of this geometry.
vector< GeometryBucket * >::type GeometryBucketList
list of Geometry Buckets in this region
MaterialPtr mMaterial
Pointer to material being used.
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:62
AxisAlignedBox mAABB
Local AABB relative to region centre.
#define OGRE_DELETE
LODBucketList mLodBucketList
List of LOD buckets.
virtual void setOrigin(const Vector3 &origin)
Sets the origin of the geometry.
VectorIterator< LODBucketList > LODIterator
MaterialBucketMap mMaterialBucketMap
Lookup of Material Buckets in this region.
AxisAlignedBox worldBounds
Pre-transformed world AABB.
QueuedGeometryList mQueuedGeometry
Geometry which has been queued up pre-build (not for deallocation)
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
LightList mLightList
List of lights for this region.
virtual void setRenderingDistance(Real dist)
Sets the distance at which batches are no longer rendered.
virtual Real getRenderingDistance(void) const
Gets the distance at which batches are no longer rendered.
MaterialBucket * mParent
Pointer to parent bucket.
uint32 mVisibilityFlags
Stores the visibility flags for the regions.
std::map< K, V, P, A > type
unsigned short ushort
IndexData * mIndexData
Index information, includes index type which limits the max number of vertices which are allowed in o...
Technique * getCurrentTechnique(void) const
Get the current Technique.
map< String, MaterialBucket * >::type MaterialBucketMap
Lookup of Material Buckets in this region.
const Vector3 & getCentre(void) const
Get the centre point of the region.
Summary class collecting together vertex source information.
'New' rendering operation using vertex buffers.
QueuedSubMeshList mQueuedSubMeshes
vector< Real >::type LodValueList
Definition: OgreMesh.h:102
A MaterialBucket is a collection of smaller buckets with the same Material (and implicitly the same L...
SceneNode * mNode
Scene node.
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...
Class to manage the scene object rendering queue.
This class contains the information required to describe the edge connectivity of a given set of vert...
virtual void setRegionDimensions(const Vector3 &size)
Sets the size of a single region of geometry.
size_t mMaxVertexIndex
Maximum vertex indexable.
OptimisedSubMeshGeometryList mOptimisedSubMeshGeometryList
List of geometry which has been optimised for SubMesh use This is the primary storage used for cleani...
Camera * mCamera
Current camera.
_StringBase String
virtual bool isVisible(void) const
Are the batches visible?
MapIterator< MaterialBucketMap > MaterialIterator
Iterator over the materials in this LOD.
4-dimensional homogeneous vector.
Definition: OgreVector4.h:45
const String & getMaterialName(void) const
Get the material name.
Concrete IteratorWrapper for nonconst access to the underlying container.
map< String, GeometryBucket * >::type CurrentGeometryMap
bool mRenderQueueIDSet
Flags whether the RenderQueue's default should be used.
static const Vector3 UNIT_SCALE
Definition: OgreVector3.h:807
vector< QueuedGeometry * >::type QueuedGeometryList
ushort getLod(void) const
Get the LOD index.
RegionMap mRegionMap
Map of regions.
SubMeshGeometryLookup mSubMeshGeometryLookup
Cached links from SubMeshes to (potentially optimised) geometry This is not used for deletion since t...
unsigned short mLod
LOD level (0 == full LOD)
virtual bool getCastShadows(void)
Will the geometry from this object cast shadows?
Mesh::LodValueList mLodValues
LOD values as built up - use the max at each level.
vector< ShadowRenderable * >::type ShadowRenderableList