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  {
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 

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 Wed Oct 16 2013 14:35:45