OgreTerrain.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 
29 #ifndef __Ogre_Terrain_H__
30 #define __Ogre_Terrain_H__
31 
33 #include "OgreCommon.h"
34 #include "OgreVector3.h"
35 #include "OgreAxisAlignedBox.h"
36 #include "OgreSceneManager.h"
39 #include "OgreWorkQueue.h"
40 #include "OgreTerrainLodManager.h"
41 
42 namespace Ogre
43 {
264  {
265  public:
266  friend class TerrainLodManager;
267 
271  Terrain(SceneManager* sm);
272  virtual ~Terrain();
273 
274  static const uint32 TERRAIN_CHUNK_ID;
278 
291 
292  static const size_t LOD_MORPH_CUSTOM_PARAM;
293 
295 
299  {
304 
306  : worldSize(100) {}
307  };
309 
312  {
314  ALIGN_X_Z = 0,
316  ALIGN_X_Y = 1,
318  ALIGN_Y_Z = 2
319  };
320 
324  struct ImportData
325  {
347 
353 
356 
363 
368  float* inputFloat;
369 
374 
383 
388 
399 
401  : terrainAlign(ALIGN_X_Z)
402  , terrainSize(1025)
403  , maxBatchSize(65)
404  , minBatchSize(17)
405  , pos(Vector3::ZERO)
406  , worldSize(1000)
407  , inputImage(0)
408  , inputFloat(0)
409  , constantHeight(0)
410  , deleteInputData(false)
411  , inputScale(1.0)
412  , inputBias(0.0)
413  {
414 
415  }
416 
417  ImportData(const ImportData& rhs)
418  : terrainAlign(ALIGN_X_Z)
419  , terrainSize(1025)
420  , maxBatchSize(65)
421  , minBatchSize(17)
422  , pos(Vector3::ZERO)
423  , worldSize(1000)
424  , inputImage(0)
425  , inputFloat(0)
426  , constantHeight(0)
427  , deleteInputData(false)
428  , inputScale(1.0)
429  , inputBias(0.0)
430  {
431  *this = rhs;
432  }
433 
435  {
436  // basic copy
437  terrainAlign = rhs.terrainAlign;
438  terrainSize = rhs.terrainSize;
439  maxBatchSize = rhs.maxBatchSize;
440  minBatchSize = rhs.minBatchSize;
441  pos = rhs.pos;
442  worldSize = rhs.worldSize;
443  constantHeight = rhs.constantHeight;
444  deleteInputData = rhs.deleteInputData;
445  inputScale = rhs.inputScale;
446  inputBias = rhs.inputBias;
447  layerDeclaration = rhs.layerDeclaration;
448  layerList = rhs.layerList;
449 
450  // By-value copies in ownership cases
451  if (rhs.deleteInputData)
452  {
453  if (rhs.inputImage)
454  inputImage = OGRE_NEW Image(*rhs.inputImage);
455  else
456  inputImage = 0;
457 
458  if (rhs.inputFloat)
459  {
460  inputFloat = OGRE_ALLOC_T(float, terrainSize*terrainSize, MEMCATEGORY_GEOMETRY);
461  memcpy(inputFloat, rhs.inputFloat, sizeof(float) * terrainSize*terrainSize);
462  }
463  else
464  inputFloat = 0;
465  }
466  else
467  {
468  // re-use pointers
469  inputImage = rhs.inputImage;
470  inputFloat = rhs.inputFloat;
471  }
472  return *this;
473  }
474 
476  void destroy()
477  {
478  if (deleteInputData)
479  {
480  OGRE_DELETE inputImage;
481  OGRE_FREE(inputFloat, MEMCATEGORY_GEOMETRY);
482  inputImage = 0;
483  inputFloat = 0;
484  }
485 
486  }
487 
489  {
490  destroy();
491  }
492 
493  };
494 
497  {
498  NEIGHBOUR_EAST = 0,
499  NEIGHBOUR_NORTHEAST = 1,
500  NEIGHBOUR_NORTH = 2,
501  NEIGHBOUR_NORTHWEST = 3,
502  NEIGHBOUR_WEST = 4,
503  NEIGHBOUR_SOUTHWEST = 5,
504  NEIGHBOUR_SOUTH = 6,
505  NEIGHBOUR_SOUTHEAST = 7,
506 
507  NEIGHBOUR_COUNT = 8
508  };
509 
510  SceneManager* getSceneManager() const { return mSceneMgr; }
511 
513  enum Space
514  {
516  WORLD_SPACE = 0,
518  LOCAL_SPACE = 1,
522  TERRAIN_SPACE = 2,
526  POINT_SPACE = 3
527  };
528 
534  {
535  public:
537  virtual ~GpuBufferAllocator() {}
538 
544  virtual void allocateVertexBuffers(Terrain* forTerrain, size_t numVertices, HardwareVertexBufferSharedPtr& destPos, HardwareVertexBufferSharedPtr& destDelta) = 0;
547  virtual void freeVertexBuffers(const HardwareVertexBufferSharedPtr& posbuf, const HardwareVertexBufferSharedPtr& deltabuf) = 0;
548 
563  virtual HardwareIndexBufferSharedPtr getSharedIndexBuffer(uint16 batchSize,
564  uint16 vdatasize, size_t vertexIncrement, uint16 xoffset, uint16 yoffset, uint16 numSkirtRowsCols,
565  uint16 skirtRowColSkip) = 0;
566 
568  virtual void freeAllBuffers() = 0;
569 
570  };
573  {
574  public:
576  virtual ~DefaultGpuBufferAllocator();
577  void allocateVertexBuffers(Terrain* forTerrain, size_t numVertices, HardwareVertexBufferSharedPtr& destPos, HardwareVertexBufferSharedPtr& destDelta);
578  void freeVertexBuffers(const HardwareVertexBufferSharedPtr& posbuf, const HardwareVertexBufferSharedPtr& deltabuf);
579  HardwareIndexBufferSharedPtr getSharedIndexBuffer(uint16 batchSize,
580  uint16 vdatasize, size_t vertexIncrement, uint16 xoffset, uint16 yoffset, uint16 numSkirtRowsCols,
581  uint16 skirtRowColSkip);
582  void freeAllBuffers();
583 
587  void warmStart(size_t numInstances, uint16 terrainSize, uint16 maxBatchSize,
588  uint16 minBatchSize);
589 
590  protected:
596 
597  uint32 hashIndexBuffer(uint16 batchSize,
598  uint16 vdatasize, size_t vertexIncrement, uint16 xoffset, uint16 yoffset, uint16 numSkirtRowsCols,
599  uint16 skirtRowColSkip);
600  HardwareVertexBufferSharedPtr getVertexBuffer(VBufList& list, size_t vertexSize, size_t numVertices);
601 
602  };
603 
608  void setGpuBufferAllocator(GpuBufferAllocator* alloc);
609 
611  GpuBufferAllocator* getGpuBufferAllocator();
612 
614  static size_t _getNumIndexesForBatchSize(uint16 batchSize);
626  static void _populateIndexBuffer(uint16* pIndexes, uint16 batchSize,
627  uint16 vdatasize, size_t vertexIncrement, uint16 xoffset, uint16 yoffset, uint16 numSkirtRowsCols,
628  uint16 skirtRowColSkip);
629 
631  static uint16 _calcSkirtVertexIndex(uint16 mainIndex, uint16 vdatasize, bool isCol,
632  uint16 numSkirtRowsCols, uint16 skirtRowColSkip);
633 
640  void convertPosition(Space inSpace, const Vector3& inPos, Space outSpace, Vector3& outPos) const;
647  Vector3 convertPosition(Space inSpace, const Vector3& inPos, Space outSpace) const;
654  void convertDirection(Space inSpace, const Vector3& inDir, Space outSpace, Vector3& outDir) const;
661  Vector3 convertDirection(Space inSpace, const Vector3& inDir, Space outSpace) const;
662 
667  void setResourceGroup(const String& resGroup) { mResourceGroup = resGroup; }
668 
672  const String& getResourceGroup() const { return mResourceGroup; }
673 
676  const String& _getDerivedResourceGroup() const;
677 
686  void save(const String& filename);
692  void save(StreamSerialiser& stream);
693 
700  bool prepare(const String& filename);
707  bool prepare(DataStreamPtr& stream);
714  bool prepare(StreamSerialiser& stream);
715 
721  bool prepare(const ImportData& importData);
722 
728  void load(const String& filename);
729 
735  void load(StreamSerialiser& stream);
736 
743  void load(int lodLevel = 0, bool synchronous = true);
744 
750  bool isLoaded() const { return mIsLoaded; }
751 
756  bool isModified() const { return mModified; }
757 
758 
763  bool isHeightDataModified() const { return mHeightDataModified; }
764 
765 
770  void unload();
771 
776  void unprepare();
777 
778 
788  float* getHeightData() const;
789 
792  float* getHeightData(long x, long y) const;
793 
798  float getHeightAtPoint(long x, long y) const;
799 
806  void setHeightAtPoint(long x, long y, float h);
807 
811  float getHeightAtTerrainPosition(Real x, Real y);
812 
818  float getHeightAtWorldPosition(Real x, Real y, Real z);
819 
825  float getHeightAtWorldPosition(const Vector3& pos);
826 
833  const float* getDeltaData();
834 
837  const float* getDeltaData(long x, long y);
838 
843  void getPoint(long x, long y, Vector3* outpos);
844 
850  void getPointFromSelfOrNeighbour(long x, long y, Vector3* outpos);
851 
856  void getPoint(long x, long y, float height, Vector3* outpos);
860  void getPointTransform(Matrix4* outXform) const;
865  void getTerrainVector(const Vector3& inVec, Vector3* outVec);
870  void getTerrainVectorAlign(const Vector3& inVec, Alignment align, Vector3* outVec);
871 
876  void getTerrainVector(Real x, Real y, Real z, Vector3* outVec);
881  void getTerrainVectorAlign(Real x, Real y, Real z, Alignment align, Vector3* outVec);
882 
887  void getVector(const Vector3& inVec, Vector3* outVec);
892  void getVectorAlign(const Vector3& inVec, Alignment align, Vector3* outVec);
893 
898  void getVector(Real x, Real y, Real z, Vector3* outVec);
903  void getVectorAlign(Real x, Real y, Real z, Alignment align, Vector3* outVec);
904 
905 
913  void getPosition(const Vector3& TSpos, Vector3* outWSpos);
921  void getPosition(Real x, Real y, Real z, Vector3* outWSpos);
922 
929  void getTerrainPosition(const Vector3& WSpos, Vector3* outTSpos);
936  void getTerrainPosition(Real x, Real y, Real z, Vector3* outTSpos);
943  void getPositionAlign(const Vector3& TSpos, Alignment align, Vector3* outWSpos);
950  void getPositionAlign(Real x, Real y, Real z, Alignment align, Vector3* outWSpos);
951 
958  void getTerrainPositionAlign(const Vector3& WSpos, Alignment align, Vector3* outTSpos);
965  void getTerrainPositionAlign(Real x, Real y, Real z, Alignment align, Vector3* outTSpos);
966 
967 
969  Alignment getAlignment() const;
971  uint16 getSize() const;
976  void setSize(uint16 newSize);
978  uint16 getMaxBatchSize() const;
980  uint16 getMinBatchSize() const;
982  Real getWorldSize() const;
986  void setWorldSize(Real newWorldSize);
987 
989  uint8 getLayerCount() const { return static_cast<uint8>(mLayers.size()); }
990 
992  const TerrainLayerDeclaration& getLayerDeclaration() const { return mLayerDecl; }
993 
1000  void addLayer(Real worldSize = 0, const StringVector* textureNames = 0);
1001 
1009  void addLayer(uint8 index, Real worldSize = 0, const StringVector* textureNames = 0);
1010 
1013  void removeLayer(uint8 index);
1014 
1024  void replaceLayer(uint8 index, bool keepBlends, Real worldSize = 0, const StringVector* textureNames = 0);
1025 
1029  uint8 getMaxLayers() const;
1030 
1035  Real getLayerWorldSize(uint8 index) const;
1041  void setLayerWorldSize(uint8 index, Real size);
1042 
1051  Real getLayerUVMultiplier(uint8 index) const;
1052 
1058  const String& getLayerTextureName(uint8 layerIndex, uint8 samplerIndex) const;
1065  void setLayerTextureName(uint8 layerIndex, uint8 samplerIndex, const String& textureName);
1066 
1073  uint16 getLayerBlendMapSize() const { return mLayerBlendMapSize; }
1074 
1080  uint16 getLightmapSize() const { return mLightmapSize; }
1081 
1083  const TexturePtr& getLightmap() const { return mLightmap; }
1084 
1090  uint16 getCompositeMapSize() const { return mCompositeMapSize; }
1091 
1093  const TexturePtr& getCompositeMap() const { return mCompositeMap; }
1094 
1096  const Vector3& getPosition() const { return mPos; }
1098  void setPosition(const Vector3& pos);
1100  SceneNode* _getRootSceneNode() const;
1107  void dirty();
1108 
1117  void dirtyRect(const Rect& rect);
1118 
1124  void _dirtyCompositeMapRect(const Rect& rect);
1125 
1136  void dirtyLightmapRect(const Rect& rect);
1137 
1148  void dirtyLightmap();
1149 
1172  void update(bool synchronous = false);
1173 
1178  void updateGeometry();
1184  void updateGeometryWithoutNotifyNeighbours();
1185 
1186  // Used as a type mask for updateDerivedData
1190  static const uint8 DERIVED_DATA_ALL;
1191 
1203  void updateDerivedData(bool synchronous = false, uint8 typeMask = 0xFF);
1204 
1213  void updateCompositeMap();
1214 
1228  void updateCompositeMapWithDelay(Real delay = 2);
1229 
1230 
1234  Real getSkirtSize() const { return mSkirtSize; }
1235 
1237  uint16 getNumLodLevels() const { return mNumLodLevels; }
1238 
1240  uint16 getNumLodLevelsPerLeaf() const { return mNumLodLevelsPerLeafNode; }
1241 
1249  Rect calculateHeightDeltas(const Rect& rect);
1250 
1258  void finaliseHeightDeltas(const Rect& rect, bool cpuData);
1259 
1265  PixelBox* calculateNormals(const Rect& rect, Rect& outFinalRect);
1266 
1274  void finaliseNormals(const Rect& rect, PixelBox* normalsBox);
1275 
1283  PixelBox* calculateLightmap(const Rect& rect, const Rect& extraTargetRect, Rect& outFinalRect);
1284 
1292  void finaliseLightmap(const Rect& rect, PixelBox* lightmapBox);
1293 
1297  uint16 getResolutionAtLod(uint16 lodLevel);
1298 
1310  std::pair<bool, Vector3> rayIntersects(const Ray& ray,
1311  bool cascadeToNeighbours = false, Real distanceLimit = 0); //const;
1312 
1314  const AxisAlignedBox& getAABB() const;
1316  AxisAlignedBox getWorldAABB() const;
1318  Real getMinHeight() const;
1320  Real getMaxHeight() const;
1322  Real getBoundingRadius() const;
1323 
1325  const MaterialPtr& getMaterial() const;
1327  const MaterialPtr& _getMaterial() const { return mMaterial; }
1329  const MaterialPtr& getCompositeMapMaterial() const;
1331  const MaterialPtr& _getCompositeMapMaterial() const { return mCompositeMapMaterial; }
1332 
1334  const String& getMaterialName() const { return mMaterialName; }
1335 
1337  void preFindVisibleObjects(SceneManager* source,
1340  void sceneManagerDestroyed(SceneManager* source);
1341 
1343  uint8 getRenderQueueGroup(void) const { return mRenderQueueGroup; }
1347  void setRenderQueueGroup(uint8 grp) { mRenderQueueGroup = grp; }
1348 
1350  uint32 getVisibilityFlags(void) const { return mVisibilityFlags; }
1354  void setVisibilityFlags(uint32 flags) { mVisibilityFlags = flags; }
1355 
1357  uint32 getQueryFlags(void) const { return mQueryFlags; }
1361  void setQueryFlags(uint32 flags) { mQueryFlags = flags; }
1362 
1364  void addQueryFlags(uint32 flags) { mQueryFlags |= flags; }
1365 
1366  /* As setQueryFlags, except the flags passed as parameters are removed from the existing flags on this object. */
1367  void removeQueryFlags(uint32 flags) { mQueryFlags &= ~flags; }
1368 
1369 
1382  TerrainLayerBlendMap* getLayerBlendMap(uint8 layerIndex);
1383 
1389  uint8 getBlendTextureIndex(uint8 layerIndex) const;
1390 
1392  uint8 getBlendTextureCount() const;
1394  uint8 getBlendTextureCount(uint8 numLayers) const;
1395 
1396 
1401  const String& getBlendTextureName(uint8 textureIndex) const;
1402 
1415  void setGlobalColourMapEnabled(bool enabled, uint16 size = 0);
1417  bool getGlobalColourMapEnabled() const { return mGlobalColourMapEnabled; }
1419  uint16 getGlobalColourMapSize() const { return mGlobalColourMapSize; }
1421  const TexturePtr& getGlobalColourMap() const { return mColourMap; }
1422 
1428  void widenRectByVector(const Vector3& vec, const Rect& inRect, Rect& outRect);
1429 
1437  void widenRectByVector(const Vector3& vec, const Rect& inRect,
1438  Real minHeight, Real maxHeight, Rect& outRect);
1439 
1449  void freeTemporaryResources();
1450 
1455  const TexturePtr& getLayerBlendTexture(uint8 index) const;
1456 
1463  std::pair<uint8,uint8> getLayerBlendTextureIndex(uint8 layerIndex) const;
1464 
1475  void _setMorphRequired(bool morph) { mLodMorphRequired = morph; }
1477  bool _getMorphRequired() const { return mLodMorphRequired; }
1478 
1490  void _setNormalMapRequired(bool normalMap);
1491 
1505  void _setLightMapRequired(bool lightMap, bool shadowsOnly = false);
1506 
1525  void _setCompositeMapRequired(bool compositeMap);
1526 
1528  bool _getUseVertexCompression() const;
1529 
1531  bool canHandleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
1533  WorkQueue::Response* handleRequest(const WorkQueue::Request* req, const WorkQueue* srcQ);
1535  bool canHandleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
1537  void handleResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
1539  void handleGenerateMaterialResponse(const WorkQueue::Response* res, const WorkQueue* srcQ);
1540 
1543 
1545  uint16 getLODLevelWhenVertexEliminated(long x, long y);
1547  uint16 getLODLevelWhenVertexEliminated(long rowOrColulmn);
1548 
1549 
1551  TerrainQuadTreeNode* getQuadTree() { return mQuadTree; }
1552 
1554  TexturePtr getTerrainNormalMap() const { return mTerrainNormalMap; }
1555 
1563  Terrain* getNeighbour(NeighbourIndex index);
1564 
1582  void setNeighbour(NeighbourIndex index, Terrain* neighbour, bool recalculate = false, bool notifyOther = true);
1583 
1588  static NeighbourIndex getOppositeNeighbour(NeighbourIndex index);
1589 
1592  static NeighbourIndex getNeighbourIndex(long offsetx, long offsety);
1593 
1601  void notifyNeighbours();
1602 
1610  void neighbourModified(NeighbourIndex index, const Rect& edgerect, const Rect& shadowrect);
1611 
1617  Terrain* raySelectNeighbour(const Ray& ray, Real distanceLimit = 0);
1618 
1623  void _dumpTextures(const String& prefix, const String& suffix);
1624 
1626  bool isDerivedDataUpdateInProgress() const { return mDerivedDataUpdateInProgress; }
1627 
1628 
1630  static void convertWorldToTerrainAxes(Alignment align, const Vector3& worldVec, Vector3* terrainVec);
1632  static void convertTerrainToWorldAxes(Alignment align, const Vector3& terrainVec, Vector3* worldVec);
1633 
1635  static void writeLayerDeclaration(const TerrainLayerDeclaration& decl, StreamSerialiser& ser);
1637  static bool readLayerDeclaration(StreamSerialiser& ser, TerrainLayerDeclaration& targetdecl);
1639  static void writeLayerInstanceList(const Terrain::LayerInstanceList& lst, StreamSerialiser& ser);
1641  static bool readLayerInstanceList(StreamSerialiser& ser, size_t numSamplers, Terrain::LayerInstanceList& targetlst);
1642 
1643  // This mutex is write-locked by neighbours if they are in the process of deleting themselves.
1644  // It should be read-locked whenever using neighbours in calculations which are possibly running in a
1645  // background thread.
1646  OGRE_RW_MUTEX(mNeighbourMutex);
1647 
1648  protected:
1651  uint getGeoDataSizeAtLod(uint16 lodLevel);
1657  inline int getPositiveLodLevel( int lodLevel )
1658  {
1659  return (lodLevel>=0) ? lodLevel : mNumLodLevels+lodLevel;
1660  }
1661  void freeLodData();
1662 
1663  void freeCPUResources();
1664  void freeGPUResources();
1665  void determineLodLevels();
1666  void distributeVertexData();
1667  void updateBaseScale();
1668  void createGPUBlendTextures();
1669  void createLayerBlendMaps();
1670  void createOrDestroyGPUNormalMap();
1671  void createOrDestroyGPUColourMap();
1672  void createOrDestroyGPULightmap();
1673  void createOrDestroyGPUCompositeMap();
1674  void waitForDerivedProcesses();
1675  void convertSpace(Space inSpace, const Vector3& inVec, Space outSpace, Vector3& outVec, bool translation) const;
1676  Vector3 convertWorldToTerrainAxes(const Vector3& inVec) const;
1677  Vector3 convertTerrainToWorldAxes(const Vector3& inVec) const;
1681  void getPointAlign(long x, long y, Alignment align, Vector3* outpos);
1686  void getPointAlign(long x, long y, float height, Alignment align, Vector3* outpos);
1687  void calculateCurrentLod(Viewport* vp);
1689  std::pair<bool, Vector3> checkQuadIntersection(int x, int y, const Ray& ray); //const;
1690 
1692  void deleteBlendMaps(uint8 lowIndex);
1694  void shiftUpGPUBlendChannels(uint8 index);
1696  void shiftDownGPUBlendChannels(uint8 index);
1698  void copyBlendTextureChannel(uint8 srcIndex, uint8 srcChannel, uint8 destIndex, uint8 destChannel );
1700  void clearGPUBlendChannel(uint8 index, uint channel);
1701 
1702  void copyGlobalOptions();
1703  void checkLayers(bool includeGPUResources);
1704  void checkDeclaration();
1705  void deriveUVMultipliers();
1706  PixelFormat getBlendTextureFormat(uint8 textureIndex, uint8 numLayers);
1707 
1708  void updateDerivedDataImpl(const Rect& rect, const Rect& lightmapExtraRect, bool synchronous, uint8 typeMask);
1709 
1710  void getEdgeRect(NeighbourIndex index, long range, Rect* outRect);
1711  // get the equivalent of the passed in edge rectangle in neighbour
1712  void getNeighbourEdgeRect(NeighbourIndex index, const Rect& inRect, Rect* outRect);
1713  // get the equivalent of the passed in edge point in neighbour
1714  void getNeighbourPoint(NeighbourIndex index, long x, long y, long *outx, long *outy);
1715  // overflow a point into a neighbour index and point
1716  void getNeighbourPointOverflow(long x, long y, NeighbourIndex *outindex, long *outx, long *outy);
1717 
1719  void removeFromNeighbours();
1720 
1728 
1730  float* mHeightData;
1732  float* mDeltaData;
1750 
1755 
1763 
1766  mutable bool mPrepareInProgress;
1769  {
1771  // types requested
1775  _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const DerivedDataRequest& r)
1776  { return o; }
1777  };
1778 
1781  {
1794  _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const DerivedDataResponse& r)
1795  { return o; }
1796  };
1797 
1800  GEN_COMPOSITE_MAP_MATERIAL
1801  };
1804  {
1806  unsigned long startTime;
1809  _OgreTerrainExport friend std::ostream& operator<<(std::ostream& o, const GenerateMaterialRequest& r)
1810  { return o; }
1811  };
1812 
1816  mutable unsigned long long int mMaterialGenerationCount;
1817  mutable bool mMaterialDirty;
1818  mutable bool mMaterialParamsDirty;
1819 
1828 
1833 
1838 
1845  unsigned long mLastMillis;
1849 
1850 
1855 
1863 
1866 
1868  unsigned long mLastLODFrame;
1870 
1871  Terrain* mNeighbours[NEIGHBOUR_COUNT];
1872 
1875 
1876  size_t getPositionBufVertexSize() const;
1877  size_t getDeltaBufVertexSize() const;
1878 
1880 
1881  public:
1885  void increaseLodLevel(bool synchronous = false);
1889  void decreaseLodLevel();
1890 
1891  int getHighestLodPrepared() { return (mLodManager) ? mLodManager->getHighestLodPrepared() : -1; };
1892  int getHighestLodLoaded() { return (mLodManager) ? mLodManager->getHighestLodLoaded() : -1; };
1893  int getTargetLodLevel() { return (mLodManager) ? mLodManager->getTargetLodLevel() : -1; };
1894  };
1895 
1896 
1906  class _OgreTerrainExport TerrainGlobalOptions : public TerrainAlloc, public Singleton<TerrainGlobalOptions>
1907  {
1908  protected:
1909 
1929 
1930  public:
1933 
1934 
1938  Real getSkirtSize() { return mSkirtSize; }
1944  void setSkirtSize(Real skirtSz) { mSkirtSize = skirtSz; }
1946  const Vector3& getLightMapDirection() { return mLightMapDir; }
1948  void setLightMapDirection(const Vector3& v) { mLightMapDir = v; }
1950  const ColourValue& getCompositeMapAmbient() { return mCompositeMapAmbient; }
1952  void setCompositeMapAmbient(const ColourValue& c) { mCompositeMapAmbient = c; }
1954  const ColourValue& getCompositeMapDiffuse() { return mCompositeMapDiffuse; }
1956  void setCompositeMapDiffuse(const ColourValue& c) { mCompositeMapDiffuse = c; }
1958  Real getCompositeMapDistance() { return mCompositeMapDistance; }
1960  void setCompositeMapDistance(Real c) { mCompositeMapDistance = c; }
1961 
1962 
1966  bool getCastsDynamicShadows() { return mCastsShadows; }
1967 
1973  void setCastsDynamicShadows(bool s) { mCastsShadows = s; }
1974 
1976  Real getMaxPixelError() { return mMaxPixelError; }
1977 
1983  void setMaxPixelError(Real pixerr) { mMaxPixelError = pixerr; }
1984 
1986  uint8 getRenderQueueGroup(void) { return mRenderQueueGroup; }
1991  void setRenderQueueGroup(uint8 grp) { mRenderQueueGroup = grp; }
1992 
1994  uint32 getVisibilityFlags(void) { return mVisibilityFlags; }
1999  void setVisibilityFlags(uint32 flags) { mVisibilityFlags = flags; }
2000 
2005  void setQueryFlags(uint32 flags) { mQueryFlags = flags; }
2008  uint32 getQueryFlags(void) { return mQueryFlags; }
2009 
2011  void addQueryFlags(uint32 flags) { mQueryFlags |= flags; }
2012 
2013  /* As setQueryFlags, except the flags passed as parameters are removed from the existing flags on this object. */
2014  void removeQueryFlags(uint32 flags) { mQueryFlags &= ~flags; }
2015 
2020  bool getUseRayBoxDistanceCalculation() { return mUseRayBoxDistanceCalculation; }
2021 
2033  void setUseRayBoxDistanceCalculation(bool rb) { mUseRayBoxDistanceCalculation = rb; }
2034 
2037  TerrainMaterialGeneratorPtr getDefaultMaterialGenerator();
2038 
2041  void setDefaultMaterialGenerator(TerrainMaterialGeneratorPtr gen);
2042 
2045  uint16 getLayerBlendMapSize() { return mLayerBlendMapSize; }
2046 
2051  void setLayerBlendMapSize(uint16 sz) { mLayerBlendMapSize = sz;}
2052 
2055  Real getDefaultLayerTextureWorldSize() { return mDefaultLayerTextureWorldSize; }
2056 
2059  void setDefaultLayerTextureWorldSize(Real sz) { mDefaultLayerTextureWorldSize = sz; }
2060 
2063  uint16 getDefaultGlobalColourMapSize() { return mDefaultGlobalColourMapSize; }
2064 
2068  void setDefaultGlobalColourMapSize(uint16 sz) { mDefaultGlobalColourMapSize = sz;}
2069 
2070 
2073  uint16 getLightMapSize() { return mLightmapSize; }
2074 
2077  void setLightMapSize(uint16 sz) { mLightmapSize = sz;}
2078 
2081  uint16 getCompositeMapSize() { return mCompositeMapSize; }
2082 
2085  void setCompositeMapSize(uint16 sz) { mCompositeMapSize = sz;}
2086 
2089  void setDefaultResourceGroup(const String& grp) { mResourceGroup = grp; }
2090 
2093  const String& getDefaultResourceGroup() { return mResourceGroup; }
2094 
2098  bool getUseVertexCompressionWhenAvailable() const { return mUseVertexCompressionWhenAvailable; }
2099 
2107  void setUseVertexCompressionWhenAvailable(bool enable) { mUseVertexCompressionWhenAvailable = enable; }
2108 
2124  static TerrainGlobalOptions& getSingleton(void);
2140  static TerrainGlobalOptions* getSingletonPtr(void);
2141 
2142 
2143  };
2144 
2145 
2148 }
2149 
2150 
2151 
2152 
2153 #endif

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 23 2013 06:57:26