- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

# OgreStaticGeometry.h

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __StaticGeometry_H__
    00030 #define __StaticGeometry_H__
    00031
    00032 #include "OgrePrerequisites.h"
    00033 #include "OgreMovableObject.h"
    00034 #include "OgreRenderable.h"
    00035
    00036 namespace Ogre {
    00037
    00113     class _OgreExport StaticGeometry
    00114     {
    00115     public:
    00128         class _OgrePrivate OptimisedSubMeshGeometry
    00129         {
    00130         public:
    00131             OptimisedSubMeshGeometry() :vertexData(0), indexData(0) {}
    00132             ~OptimisedSubMeshGeometry()
    00133             {
    00134                 delete vertexData;
    00135                 delete indexData;
    00136             }
    00137             VertexData *vertexData;
    00138             IndexData *indexData;
    00139         };
    00140         typedef std::list<OptimisedSubMeshGeometry*> OptimisedSubMeshGeometryList;
    00143         struct SubMeshLodGeometryLink
    00144         {
    00145             VertexData* vertexData;
    00146             IndexData* indexData;
    00147         };
    00148         typedef std::vector<SubMeshLodGeometryLink> SubMeshLodGeometryLinkList;
    00149         typedef std::map<SubMesh*, SubMeshLodGeometryLinkList*> SubMeshGeometryLookup;
    00151         struct QueuedSubMesh
    00152         {
    00153             SubMesh* submesh;
    00155             SubMeshLodGeometryLinkList* geometryLodList;
    00156             String materialName;
    00157             Vector3 position;
    00158             Quaternion orientation;
    00159             Vector3 scale;
    00161             AxisAlignedBox worldBounds;
    00162         };
    00163         typedef std::vector<QueuedSubMesh*> QueuedSubMeshList;
    00165         struct QueuedGeometry
    00166         {
    00167             SubMeshLodGeometryLink* geometry;
    00168             Vector3 position;
    00169             Quaternion orientation;
    00170             Vector3 scale;
    00171         };
    00172         typedef std::vector<QueuedGeometry*> QueuedGeometryList;
    00173
    00174         // forward declarations
    00175         class LODBucket;
    00176         class MaterialBucket;
    00177         class Region;
    00178
    00183         class _OgreExport GeometryBucket :  public Renderable
    00184         {
    00185         protected:
    00187             QueuedGeometryList mQueuedGeometry;
    00189             MaterialBucket* mParent;
    00191             String mFormatString;
    00194             VertexData* mVertexData;
    00197             IndexData* mIndexData;
    00199             HardwareIndexBuffer::IndexType mIndexType;
    00201             size_t mMaxVertexIndex;
    00202
    00203             template<typename T>
    00204             void copyIndexes(const T* src, T* dst, size_t count, size_t indexOffset)
    00205             {
    00206                 if (indexOffset == 0)
    00207                 {
    00208                     memcpy(dst, src, sizeof(T) * count);
    00209                 }
    00210                 else
    00211                 {
    00212                     while(count--)
    00213                     {
    00214                         *dst++ = static_cast<T>(*src++ + indexOffset);
    00215                     }
    00216                 }
    00217             }
    00218         public:
    00219             GeometryBucket(MaterialBucket* parent, const String& formatString,
    00220                 const VertexData* vData, const IndexData* iData);
    00221             virtual ~GeometryBucket();
    00222             MaterialBucket* getParent(void) { return mParent; }
    00224             const VertexData* getVertexData(void) const { return mVertexData; }
    00226             const IndexData* getIndexData(void) const { return mIndexData; }
    00228             const MaterialPtr& getMaterial(void) const;
    00229             Technique* getTechnique(void) const;
    00230             void getRenderOperation(RenderOperation& op);
    00231             void getWorldTransforms(Matrix4* xform) const;
    00232             const Quaternion& getWorldOrientation(void) const;
    00233             const Vector3& getWorldPosition(void) const;
    00234             Real getSquaredViewDepth(const Camera* cam) const;
    00235             const LightList& getLights(void) const;
    00236             bool getCastsShadows(void) const;
    00237
    00241             bool assign(QueuedGeometry* qsm);
    00243             void build(bool stencilShadows);
    00245             void dump(std::ofstream& of) const;
    00246         };
    00249         class _OgreExport MaterialBucket
    00250         {
    00251         public:
    00253             typedef std::vector<GeometryBucket*> GeometryBucketList;
    00254         protected:
    00256             LODBucket* mParent;
    00258             String mMaterialName;
    00260             MaterialPtr mMaterial;
    00262             Technique* mTechnique;
    00263
    00265             GeometryBucketList mGeometryBucketList;
    00266             // index to current Geometry Buckets for a given geometry format
    00267             typedef std::map<String, GeometryBucket*> CurrentGeometryMap;
    00268             CurrentGeometryMap mCurrentGeometryMap;
    00270             String getGeometryFormatString(SubMeshLodGeometryLink* geom);
    00271
    00272         public:
    00273             MaterialBucket(LODBucket* parent, const String& materialName);
    00274             virtual ~MaterialBucket();
    00275             LODBucket* getParent(void) { return mParent; }
    00277             const String& getMaterialName(void) const { return mMaterialName; }
    00279             void assign(QueuedGeometry* qsm);
    00281             void build(bool stencilShadows);
    00283             void addRenderables(RenderQueue* queue, uint8 group,
    00284                 Real camSquaredDist);
    00286             const MaterialPtr& getMaterial(void) const { return mMaterial; }
    00288             typedef VectorIterator<GeometryBucketList> GeometryIterator;
    00290             GeometryIterator getGeometryIterator(void);
    00292             Technique* getCurrentTechnique(void) const { return mTechnique; }
    00294             void dump(std::ofstream& of) const;
    00295         };
    00301         class _OgreExport LODBucket
    00302         {
    00303         public:
    00305             typedef std::map<String, MaterialBucket*> MaterialBucketMap;
    00306         protected:
    00308             Region* mParent;
    00310             unsigned short mLod;
    00312             Real mSquaredDistance;
    00314             MaterialBucketMap mMaterialBucketMap;
    00316             QueuedGeometryList mQueuedGeometryList;
    00317         public:
    00318             LODBucket(Region* parent, unsigned short lod, Real lodDist);
    00319             virtual ~LODBucket();
    00320             Region* getParent(void) { return mParent; }
    00322             ushort getLod(void) const { return mLod; }
    00324             Real getSquaredDistance(void) const { return mSquaredDistance; }
    00326             void assign(QueuedSubMesh* qsm, ushort atLod);
    00328             void build(bool stencilShadows);
    00330             void addRenderables(RenderQueue* queue, uint8 group,
    00331                 Real camSquaredDistance);
    00333             typedef MapIterator<MaterialBucketMap> MaterialIterator;
    00335             MaterialIterator getMaterialIterator(void);
    00337             void dump(std::ofstream& of) const;
    00338
    00339         };
    00348         class _OgreExport Region : public MovableObject
    00349         {
    00350         public:
    00352             typedef std::vector<LODBucket*> LODBucketList;
    00353         protected:
    00355             class _OgreExport RegionShadowRenderable : public ShadowRenderable
    00356             {
    00357             protected:
    00358                 Region* mParent;
    00359                 // Shared link to position buffer
    00360                 HardwareVertexBufferSharedPtr mPositionBuffer;
    00361                 // Shared link to w-coord buffer (optional)
    00362                 HardwareVertexBufferSharedPtr mWBuffer;
    00363
    00364             public:
    00365                 RegionShadowRenderable(Region* parent,
    00366                     HardwareIndexBufferSharedPtr* indexBuffer, const VertexData* vertexData,
    00367                     bool createSeparateLightCap, bool isLightCap = false);
    00368                 ~RegionShadowRenderable();
    00370                 void getWorldTransforms(Matrix4* xform) const;
    00372                 const Quaternion& getWorldOrientation(void) const;
    00374                 const Vector3& getWorldPosition(void) const;
    00375                 HardwareVertexBufferSharedPtr getPositionBuffer(void) { return mPositionBuffer; }
    00376                 HardwareVertexBufferSharedPtr getWBuffer(void) { return mWBuffer; }
    00377
    00378             };
    00380             StaticGeometry* mParent;
    00382             SceneManager* mSceneMgr;
    00384             SceneNode* mNode;
    00386             QueuedSubMeshList mQueuedSubMeshes;
    00388             uint32 mRegionID;
    00390             Vector3 mCentre;
    00392             std::vector<Real> mLodSquaredDistances;
    00394             AxisAlignedBox mAABB;
    00396             Real mBoundingRadius;
    00398             ushort mCurrentLod;
    00400             Real mCamDistanceSquared;
    00402             LODBucketList mLodBucketList;
    00404             mutable LightList mLightList;
    00406             mutable ulong mLightListUpdated;
    00408             EdgeData* mEdgeList;
    00410             ShadowRenderableList mShadowRenderables;
    00412             bool mVertexProgramInUse;
    00413
    00414
    00415
    00416         public:
    00417             Region(StaticGeometry* parent, const String& name, SceneManager* mgr,
    00418                 uint32 regionID, const Vector3& centre);
    00419             virtual ~Region();
    00420             // more fields can be added in subclasses
    00421             StaticGeometry* getParent(void) const { return mParent;}
    00423             void assign(QueuedSubMesh* qmesh);
    00425             void build(bool stencilShadows);
    00427             uint32 getID(void) const { return mRegionID; }
    00429             const Vector3& getCentre(void) const { return mCentre; }
    00430             const String& getMovableType(void) const;
    00431             void _notifyCurrentCamera(Camera* cam);
    00432             const AxisAlignedBox& getBoundingBox(void) const;
    00433             Real getBoundingRadius(void) const;
    00434             void _updateRenderQueue(RenderQueue* queue);
    00435             bool isVisible(void) const;
    00436             uint32 getTypeFlags(void) const;
    00437
    00438             typedef VectorIterator<LODBucketList> LODIterator;
    00440             LODIterator getLODIterator(void);
    00442             ShadowRenderableListIterator getShadowVolumeRenderableIterator(
    00443                 ShadowTechnique shadowTechnique, const Light* light,
    00444                 HardwareIndexBufferSharedPtr* indexBuffer,
    00445                 bool extrudeVertices, Real extrusionDistance, unsigned long flags = 0 );
    00447             EdgeData* getEdgeList(void);
    00449             bool hasEdgeList(void);
    00450
    00452             void dump(std::ofstream& of) const;
    00453
    00454         };
    00462         typedef std::map<uint32, Region*> RegionMap;
    00463     protected:
    00464         // General state & settings
    00465         SceneManager* mOwner;
    00466         String mName;
    00467         bool mBuilt;
    00468         Real mUpperDistance;
    00469         Real mSquaredUpperDistance;
    00470         bool mCastShadows;
    00471         Vector3 mRegionDimensions;
    00472         Vector3 mHalfRegionDimensions;
    00473         Vector3 mOrigin;
    00474         bool mVisible;
    00476         uint8 mRenderQueueID;
    00478         bool mRenderQueueIDSet;
    00479
    00480         QueuedSubMeshList mQueuedSubMeshes;
    00481
    00484         OptimisedSubMeshGeometryList mOptimisedSubMeshGeometryList;
    00485
    00490         SubMeshGeometryLookup mSubMeshGeometryLookup;
    00491
    00493         RegionMap mRegionMap;
    00494
    00498         virtual Region* getRegion(const AxisAlignedBox& bounds, bool autoCreate);
    00500         virtual Region* getRegion(const Vector3& point, bool autoCreate);
    00502         virtual Region* getRegion(ushort x, ushort y, ushort z, bool autoCreate);
    00504         virtual Region* getRegion(uint32 index);
    00507         virtual void getRegionIndexes(const Vector3& point,
    00508             ushort& x, ushort& y, ushort& z);
    00511         virtual uint32 packIndex(ushort x, ushort y, ushort z);
    00514         virtual Real getVolumeIntersection(const AxisAlignedBox& box,
    00515             ushort x, ushort y, ushort z);
    00518         virtual AxisAlignedBox getRegionBounds(ushort x, ushort y, ushort z);
    00521         virtual Vector3 getRegionCentre(ushort x, ushort y, ushort z);
    00523         virtual AxisAlignedBox calculateBounds(VertexData* vertexData,
    00524             const Vector3& position, const Quaternion& orientation,
    00525             const Vector3& scale);
    00527         SubMeshLodGeometryLinkList* determineGeometry(SubMesh* sm);
    00529         void splitGeometry(VertexData* vd, IndexData* id,
    00530             SubMeshLodGeometryLink* targetGeomLink);
    00531
    00532         typedef std::map<size_t, size_t> IndexRemap;
    00537         template <typename T>
    00538         void buildIndexRemap(T* pBuffer, size_t numIndexes, IndexRemap& remap)
    00539         {
    00540             remap.clear();
    00541             for (size_t i = 0; i < numIndexes; ++i)
    00542             {
    00543                 // use insert since duplicates are silently discarded
    00544                 remap.insert(IndexRemap::value_type(*pBuffer++, remap.size()));
    00545                 // this will have mapped oldindex -> new index IF oldindex
    00546                 // wasn't already there
    00547             }
    00548         }
    00550         template <typename T>
    00551         void remapIndexes(T* src, T* dst, const IndexRemap& remap,
    00552                 size_t numIndexes)
    00553         {
    00554             for (size_t i = 0; i < numIndexes; ++i)
    00555             {
    00556                 // look up original and map to target
    00557                 IndexRemap::const_iterator ix = remap.find(*src++);
    00558                 assert(ix != remap.end());
    00559                 *dst++ = static_cast<T>(ix->second);
    00560             }
    00561         }
    00562
    00563     public:
    00565         StaticGeometry(SceneManager* owner, const String& name);
    00567         virtual ~StaticGeometry();
    00568
    00570         const String& getName(void) const { return mName; }
    00589         virtual void addEntity(Entity* ent, const Vector3& position,
    00590             const Quaternion& orientation = Quaternion::IDENTITY,
    00591             const Vector3& scale = Vector3::UNIT_SCALE);
    00592
    00611         virtual void addSceneNode(const SceneNode* node);
    00612
    00623         virtual void build(void);
    00624
    00630         virtual void destroy(void);
    00631
    00635         virtual void reset(void);
    00636
    00646         virtual void setRenderingDistance(Real dist) {
    00647             mUpperDistance = dist;
    00648             mSquaredUpperDistance = mUpperDistance * mUpperDistance;
    00649         }
    00650
    00652         virtual Real getRenderingDistance(void) const { return mUpperDistance; }
    00653
    00655         virtual Real getSquaredRenderingDistance(void) const
    00656         { return mSquaredUpperDistance; }
    00657
    00659         virtual void setVisible(bool visible);
    00660
    00662         virtual bool isVisible(void) const { return mVisible; }
    00663
    00681         virtual void setCastShadows(bool castShadows);
    00683         virtual bool getCastShadows(void) { return mCastShadows; }
    00684
    00695         virtual void setRegionDimensions(const Vector3& size) {
    00696             mRegionDimensions = size;
    00697             mHalfRegionDimensions = size * 0.5;
    00698         }
    00700         virtual const Vector3& getRegionDimensions(void) const { return mRegionDimensions; }
    00712         virtual void setOrigin(const Vector3& origin) { mOrigin = origin; }
    00714         virtual const Vector3& getOrigin(void) const { return mOrigin; }
    00715
    00727         virtual void setRenderQueueGroup(uint8 queueID);
    00728
    00730         virtual uint8 getRenderQueueGroup(void) const;
    00731
    00733         typedef MapIterator<RegionMap> RegionIterator;
    00735         RegionIterator getRegionIterator(void);
    00736
    00740         virtual void dump(const String& filename) const;
    00741
    00742
    00743     };
    00744
    00745 }
    00746
    00747 #endif
    00748

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Mon Jun 16 12:48:56 2008