OGRE  2.0
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 "OgreHeaderPrefix.h"
36 
37 namespace Ogre {
38 
121  {
122  public:
136  {
137  public:
138  OptimisedSubMeshGeometry() :vertexData(0), indexData(0) {}
140  {
141  OGRE_DELETE vertexData;
142  OGRE_DELETE indexData;
143  }
146  };
151  {
154  };
159  {
169  };
173  {
178  };
180 
181  // forward declarations
182  class LODBucket;
183  class MaterialBucket;
184  class Region;
185 
191  {
192  protected:
209 
210  template<typename T>
211  void copyIndexes(const T* src, T* dst, size_t count, size_t indexOffset)
212  {
213  if (indexOffset == 0)
214  {
215  memcpy(dst, src, sizeof(T) * count);
216  }
217  else
218  {
219  while(count--)
220  {
221  *dst++ = static_cast<T>(*src++ + indexOffset);
222  }
223  }
224  }
225  public:
226  GeometryBucket(MaterialBucket* parent, const String& formatString,
227  const VertexData* vData, const IndexData* iData);
228  virtual ~GeometryBucket();
229  MaterialBucket* getParent(void) { return mParent; }
231  const VertexData* getVertexData(void) const { return mVertexData; }
233  const IndexData* getIndexData(void) const { return mIndexData; }
235  const MaterialPtr& getMaterial(void) const;
236  Technique* getTechnique(void) const;
237  void getRenderOperation(RenderOperation& op);
238  void getWorldTransforms(Matrix4* xform) const;
239  Real getSquaredViewDepth(const Camera* cam) const;
240  const LightList& getLights(void) const;
241  bool getCastsShadows(void) const;
242 
246  bool assign(QueuedGeometry* qsm);
248  void build();
250  void dump(std::ofstream& of) const;
251  };
255  {
256  public:
259  protected:
268 
271  // index to current Geometry Buckets for a given geometry format
275  String getGeometryFormatString(SubMeshLodGeometryLink* geom);
276 
277  public:
278  MaterialBucket(LODBucket* parent, const String& materialName);
279  virtual ~MaterialBucket();
280  LODBucket* getParent(void) { return mParent; }
282  const String& getMaterialName(void) const { return mMaterialName; }
284  void assign(QueuedGeometry* qsm);
286  void build();
288  void addRenderables(RenderQueue* queue, uint8 group,
289  size_t materialLod);
291  const MaterialPtr& getMaterial(void) const { return mMaterial; }
295  GeometryIterator getGeometryIterator(void);
297  Technique* getCurrentTechnique(void) const { return mTechnique; }
299  void dump(std::ofstream& of) const;
300  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables);
301  };
308  {
309  public:
312  protected:
316  unsigned short mLod;
327  public:
328  LODBucket(Region* parent, unsigned short lod, Real lodValue);
329  virtual ~LODBucket();
330  Region* getParent(void) { return mParent; }
332  ushort getLod(void) const { return mLod; }
334  Real getLodValue(void) const { return mLodValue; }
336  void assign(QueuedSubMesh* qsm, ushort atLod);
338  void build();
340  void addRenderables(RenderQueue* queue, uint8 group,
341  const FastArray<unsigned char> &currentMatLod);
345  MaterialIterator getMaterialIterator(void);
346  size_t getNumMaterials(void) const { return mMaterialBucketMap.size(); }
348  void dump(std::ofstream& of) const;
349  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables);
350  EdgeData* getEdgeList() const { return mEdgeList; }
351  bool isVertexProgramInUse() const { return mVertexProgramInUse; }
352 
353  };
363  {
364  friend class MaterialBucket;
365  friend class GeometryBucket;
366  public:
369  protected:
391  Camera const *mCamera;
394 
395  public:
396  Region( IdType id, ObjectMemoryManager *objectMemoryManager, StaticGeometry* parent,
397  SceneManager* mgr, uint32 regionID, const Vector3& centre );
398  virtual ~Region();
399  // more fields can be added in subclasses
400  StaticGeometry* getParent(void) const { return mParent;}
402  void assign(QueuedSubMesh* qmesh);
404  void build( bool parentVisible );
406  uint32 getID(void) const { return mRegionID; }
408  const Vector3& getCentre(void) const { return mCentre; }
409  const String& getMovableType(void) const;
410  void _updateRenderQueue(RenderQueue* queue, Camera *camera, const Camera *lodCamera);
412  void visitRenderables(Renderable::Visitor* visitor,
413  bool debugRenderables = false);
414  uint32 getTypeFlags(void) const;
415 
418  LODIterator getLODIterator(void);
420  EdgeData* getEdgeList(void);
422  bool hasEdgeList(void);
423 
425  void dump(std::ofstream& of) const;
426 
427  };
436  protected:
437  // General state & settings
440  bool mBuilt;
447  bool mVisible;
454 
456 
460 
466 
469 
473  virtual Region* getRegion(const AxisAlignedBox& bounds, bool autoCreate);
475  virtual Region* getRegion(const Vector3& point, bool autoCreate);
477  virtual Region* getRegion(ushort x, ushort y, ushort z, bool autoCreate);
479  virtual Region* getRegion(uint32 index);
482  virtual void getRegionIndexes(const Vector3& point,
483  ushort& x, ushort& y, ushort& z);
486  virtual uint32 packIndex(ushort x, ushort y, ushort z);
489  virtual Real getVolumeIntersection(const AxisAlignedBox& box,
490  ushort x, ushort y, ushort z);
493  virtual AxisAlignedBox getRegionBounds(ushort x, ushort y, ushort z);
496  virtual Vector3 getRegionCentre(ushort x, ushort y, ushort z);
498  virtual AxisAlignedBox calculateBounds(VertexData* vertexData,
499  const Vector3& position, const Quaternion& orientation,
500  const Vector3& scale);
502  SubMeshLodGeometryLinkList* determineGeometry(SubMesh* sm);
504  void splitGeometry(VertexData* vd, IndexData* id,
505  SubMeshLodGeometryLink* targetGeomLink);
506 
512  template <typename T>
513  void buildIndexRemap(T* pBuffer, size_t numIndexes, IndexRemap& remap)
514  {
515  remap.clear();
516  for (size_t i = 0; i < numIndexes; ++i)
517  {
518  // use insert since duplicates are silently discarded
519  remap.insert(IndexRemap::value_type(*pBuffer++, remap.size()));
520  // this will have mapped oldindex -> new index IF oldindex
521  // wasn't already there
522  }
523  }
525  template <typename T>
526  void remapIndexes(T* src, T* dst, const IndexRemap& remap,
527  size_t numIndexes)
528  {
529  for (size_t i = 0; i < numIndexes; ++i)
530  {
531  // look up original and map to target
532  IndexRemap::const_iterator ix = remap.find(*src++);
533  assert(ix != remap.end());
534  *dst++ = static_cast<T>(ix->second);
535  }
536  }
537 
538  public:
540  StaticGeometry(SceneManager* owner, const String& name);
542  virtual ~StaticGeometry();
543 
545  const String& getName(void) const { return mName; }
564  virtual void addEntity(Entity* ent, const Vector3& position,
565  const Quaternion& orientation = Quaternion::IDENTITY,
566  const Vector3& scale = Vector3::UNIT_SCALE);
567 
586  virtual void addSceneNode(const SceneNode* node);
587 
598  virtual void build(void);
599 
605  virtual void destroy(void);
606 
610  virtual void reset(void);
611 
621  virtual void setRenderingDistance(Real dist) {
622  mUpperDistance = dist;
623  mSquaredUpperDistance = mUpperDistance * mUpperDistance;
624  }
625 
627  virtual Real getRenderingDistance(void) const { return mUpperDistance; }
628 
630  virtual Real getSquaredRenderingDistance(void) const
631  { return mSquaredUpperDistance; }
632 
634  virtual void setVisible(bool visible);
635 
637  virtual bool isVisible(void) const { return mVisible; }
638 
656  virtual void setCastShadows(bool castShadows);
658  virtual bool getCastShadows(void) { return mCastShadows; }
659 
670  virtual void setRegionDimensions(const Vector3& size) {
671  mRegionDimensions = size;
672  mHalfRegionDimensions = size * 0.5;
673  }
675  virtual const Vector3& getRegionDimensions(void) const { return mRegionDimensions; }
687  virtual void setOrigin(const Vector3& origin) { mOrigin = origin; }
689  virtual const Vector3& getOrigin(void) const { return mOrigin; }
690 
692  void setVisibilityFlags(uint32 flags);
694  uint32 getVisibilityFlags() const;
695 
707  virtual void setRenderQueueGroup(uint8 queueID);
708 
710  virtual uint8 getRenderQueueGroup(void) const;
712  void visitRenderables(Renderable::Visitor* visitor,
713  bool debugRenderables = false);
714 
718  RegionIterator getRegionIterator(void);
719 
723  virtual void dump(const String& filename) const;
724 
725 
726  };
730 }
731 
732 #include "OgreHeaderSuffix.h"
733 
734 #endif
735 
void copyIndexes(const T *src, T *dst, size_t count, size_t indexOffset)
unsigned char uint8
Definition: OgrePlatform.h:422
const VertexData * getVertexData(void) const
Get the vertex data for this geometry.
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:82
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
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:420
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:255
HardwareIndexBuffer::IndexType mIndexType
Size of indexes.
map< size_t, size_t >::type IndexRemap
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.
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.
A 3D box aligned with the x/y/z axes.
virtual const Vector3 & getRegionDimensions(void) const
Gets the size of a single batch of geometry.
GeometryBucketList mGeometryBucketList
list of Geometry Buckets in this region
Mesh::LodValueArray mLodValues
LOD values as built up - use the max at each level.
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:50
const MaterialPtr & getMaterial(void) const
Get the material for this bucket.
Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.
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:53
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.
list< OptimisedSubMeshGeometry * >::type OptimisedSubMeshGeometryList
A LODBucket is a collection of smaller buckets with the same LOD.
Region * mParent
Pointer to parent region.
Vector3 mCentre
Center of the region.
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
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.
Camera const * mCamera
Current camera.
vector< QueuedSubMesh * >::type QueuedSubMeshList
const IndexData * getIndexData(void) const
Get the index data for this geometry.
Ogre::uint32 IdType
Big projects with lots, lots of units for very long periods of time (MMORPGs?) may want to define thi...
Definition: OgreId.h:36
#define _OgrePrivate
Definition: OgrePlatform.h:256
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.
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:81
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:60
#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:50
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
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...
_StringBase String
Definition: OgreCommon.h:53
virtual bool isVisible(void) const
Are the batches visible?
MapIterator< MaterialBucketMap > MaterialIterator
Iterator over the materials in this LOD.
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:814
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?