Go to the documentation of this file.
29 #ifndef __Ogre_Terrain_H__
30 #define __Ogre_Terrain_H__
401 : terrainAlign(ALIGN_X_Z)
410 , deleteInputData(false)
418 : terrainAlign(ALIGN_X_Z)
427 , deleteInputData(false)
461 memcpy(inputFloat, rhs.
inputFloat,
sizeof(
float) * terrainSize*terrainSize);
499 NEIGHBOUR_NORTHEAST = 1,
501 NEIGHBOUR_NORTHWEST = 3,
503 NEIGHBOUR_SOUTHWEST = 5,
505 NEIGHBOUR_SOUTHEAST = 7,
565 uint16 skirtRowColSkip) = 0;
743 void load(
int lodLevel = 0,
bool synchronous =
true);
1311 bool cascadeToNeighbours =
false,
Real distanceLimit = 0);
1659 return (lodLevel>=0) ? lodLevel : mNumLodLevels+lodLevel;
1800 GEN_COMPOSITE_MAP_MATERIAL
Real getBoundingRadius() const
Get the bounding radius of the entire terrain.
static const uint8 DERIVED_DATA_LIGHTMAP
void setVisibilityFlags(uint32 flags)
Set the visbility flags that terrains will be rendered with.
size_t getDeltaBufVertexSize() const
void createOrDestroyGPULightmap()
uint16 getMinBatchSize() const
Get the minimum size in vertices along one side of a batch.
void finaliseNormals(const Rect &rect, PixelBox *normalsBox)
Finalise the normals.
const ColourValue & getCompositeMapAmbient() const
Get the composite map ambient light to use.
PixelBox * normalMapBox
All CPU-side data, independent of textures; to be blitted in main thread.
unsigned long long uint64
void _setNormalMapRequired(bool normalMap)
Request internal implementation options for the terrain material to use, in this case a terrain-wide ...
uint16 getSize() const
Get the size of the terrain in vertices along one side.
virtual void allocateVertexBuffers(Terrain *forTerrain, size_t numVertices, HardwareVertexBufferSharedPtr &destPos, HardwareVertexBufferSharedPtr &destDelta)=0
Allocate (or reuse) vertex buffers for a terrain LOD.
void addQueryFlags(uint32 flags)
As setQueryFlags, except the flags passed as parameters are appended to the existing flags on this ob...
void setCompositeMapAmbient(const ColourValue &c)
Set the composite map ambient light to use.
Terrain(SceneManager *sm)
Constructor.
void setLayerBlendMapSize(uint16 sz)
Sets the default size of blend maps for a new terrain.
static const uint16 TERRAINLAYERSAMPLER_CHUNK_VERSION
void getPoint(long x, long y, float height, Vector3 *outpos) const
Get a Vector3 of the world-space point on the terrain, supplying the height data manually (can be mor...
static NameGenerator msBlendTextureGenerator
SceneManager * getSceneManager() const
@ MEMCATEGORY_GEOMETRY
Geometry held in main memory.
uint8 * mCpuColourMapStorage
void getPointFromSelfOrNeighbour(long x, long y, Vector3 *outpos) const
Get a Vector3 of the world-space point on the terrain, aligned as per options.
const TerrainLayerDeclaration & getLayerDeclaration() const
Get the declaration which describes the layers in this terrain.
Alignment
The alignment of the terrain.
Interface to a general purpose request / response style background work queue.
float getHeightAtWorldPosition(const Vector3 &pos) const
Get the height data for a given world position (projecting the point down on to the terrain).
static const uint16 TERRAIN_CHUNK_VERSION
const MaterialPtr & getCompositeMapMaterial() const
Get the material being used for the terrain composite map.
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
General purpose request structure.
IlluminationRenderStage
Describes the stage of rendering when performing complex illumination.
Space
Enumeration of relative spaces that you might want to use to address the terrain.
bool isModified() const
Returns whether this terrain has been modified since it was first loaded / defined.
void getTerrainPosition(Real x, Real y, Real z, Vector3 *outTSpos) const
Convert a position from world space to terrain basis space.
vector< Real >::type RealVector
void createOrDestroyGPUColourMap()
DefaultGpuBufferAllocator mDefaultGpuBufferAllocator
bool mLightMapShadowsOnly
Rect lightmapUpdateRect
The area of lightmap that was updated.
const String & getLayerTextureName(uint8 layerIndex, uint8 samplerIndex) const
Get the name of the texture bound to a given index within a given layer.
Class that allows listening in on the various stages of SceneManager processing, so that custom behav...
virtual void freeVertexBuffers(const HardwareVertexBufferSharedPtr &posbuf, const HardwareVertexBufferSharedPtr &deltabuf)=0
Free (or return to the pool) vertex buffers for terrain.
uint8 remainingTypeMask
Remaining types not yet processed.
const TexturePtr & getLightmap() const
Get access to the lightmap, if enabled (as requested by the material generator)
void widenRectByVector(const Vector3 &vec, const Rect &inRect, Rect &outRect)
Widen a rectangular area of terrain to take into account an extrusion vector.
uint16 mDefaultGlobalColourMapSize
A viewpoint from which the scene will be rendered.
static const uint16 TERRAINLAYERINSTANCE_CHUNK_VERSION
void getTerrainPosition(const Vector3 &WSpos, Vector3 *outTSpos) const
Convert a position from world space to terrain basis space.
Options class which just stores default options for the terrain.
void _setCompositeMapRequired(bool compositeMap)
Request internal implementation options for the terrain material to use, in this case a terrain-wide ...
static NeighbourIndex getOppositeNeighbour(NeighbourIndex index)
Get the opposite neighbour relationship (useful for finding the neighbour index from the perspective ...
static const uint16 TERRAINGENERALINFO_CHUNK_VERSION
int getHighestLodPrepared()
void setCompositeMapDistance(Real c)
Set the distance at which to start using a composite map if present.
void addLayer(uint8 index, Real worldSize=0, const StringVector *textureNames=0)
Add a new layer to this terrain at a specific index.
void increaseLodLevel(bool synchronous=false)
Increase Terrain's LOD level by 1.
void addLayer(Real worldSize=0, const StringVector *textureNames=0)
Add a new layer to this terrain.
vector< TexturePtr >::type TexturePtrList
void updateGeometryWithoutNotifyNeighbours()
Performs an update on the terrain geometry based on the dirty region.
void setGpuBufferAllocator(GpuBufferAllocator *alloc)
Tell this instance to use the given GpuBufferAllocator.
std::pair< bool, Vector3 > checkQuadIntersection(int x, int y, const Ray &ray)
Test a single quad of the terrain for ray intersection.
vector< String >::type StringVector
Vector3 convertWorldToTerrainAxes(const Vector3 &inVec) const
Real mBase
Base position in world space, relative to mPos.
static bool readLayerInstanceList(StreamSerialiser &ser, size_t numSamplers, Terrain::LayerInstanceList &targetlst)
Utility method to read a layer instance list from a stream.
float * inputFloat
Optional list of terrainSize * terrainSize floats defining the terrain.
bool getGlobalColourMapEnabled() const
Get whether a global colour map is enabled on this terrain.
Real getLayerUVMultiplier(uint8 index) const
Get the layer UV multiplier.
StringVector textureNames
List of texture names to import; must match with TerrainLayerDeclaration.
Rect lightmapExtraDirtyRect
static NeighbourIndex getNeighbourIndex(long offsetx, long offsety)
Get the neighbour enum for a given offset in a grid (signed).
Class representing an image file.
void createGPUBlendTextures()
Class exposing an interface to a blend map for a given layer.
#define _OgreTerrainExport
#define OGRE_FREE(ptr, category)
Free the memory allocated with OGRE_MALLOC or OGRE_ALLOC_T. Category is required to be restated to en...
uint8 getMaxLayers() const
Get the maximum number of layers supported with the current options.
GenerateMaterialStage stage
TexturePtr getTerrainNormalMap() const
Get the (global) normal map texture.
Rect mDirtyDerivedDataRect
bool mMaterialParamsDirty
void getPoint(long x, long y, Vector3 *outpos) const
Get a Vector3 of the world-space point on the terrain, aligned as per options.
void waitForDerivedProcesses()
uint getGeoDataSizeAtLod(uint16 lodLevel) const
Gets the data size at a given LOD level.
float constantHeight
If neither inputImage or inputFloat are supplied, the constant height at which the initial terrain sh...
void getNeighbourPoint(NeighbourIndex index, long x, long y, long *outx, long *outy) const
uint8 getBlendTextureCount() const
Get the number of blend textures in use.
void updateDerivedDataImpl(const Rect &rect, const Rect &lightmapExtraRect, bool synchronous, uint8 typeMask)
DefaultGpuBufferAllocator()
void _dirtyCompositeMapRect(const Rect &rect)
Mark a region of the terrain composite map as dirty.
bool deleteInputData
Whether this structure should 'own' the input data (inputImage and inputFloat), and therefore delete ...
uint16 getLayerBlendMapSize() const
Get the requested size of the blend maps used to blend between layers for this terrain.
bool getCastsDynamicShadows() const
Whether the terrain will be able to cast shadows (texture shadows only are supported,...
The main containing class for a chunk of terrain.
Terrain LOD data manager.
bool canHandleRequest(const WorkQueue::Request *req, const WorkQueue *srcQ)
WorkQueue::RequestHandler override.
void removeQueryFlags(uint32 flags)
static size_t _getNumIndexesForBatchSize(uint16 batchSize)
Utility method to get the number of indexes required to render a given batch.
uint16 getLODLevelWhenVertexEliminated(long rowOrColulmn) const
Utility method, get the first LOD Level at which this vertex is no longer included.
RealVector mLayerUVMultiplier
_OgreTerrainExport friend std::ostream & operator<<(std::ostream &o, const DerivedDataRequest &r)
static const uint8 DERIVED_DATA_NORMALS
General purpose response structure.
Real mCompositeMapDistance
void removeFromNeighbours()
Removes this terrain instance from neighbouring terrain's list of neighbours.
Shared pointer implementation used to share index buffers.
std::pair< bool, Vector3 > rayIntersects(const Ray &ray, bool cascadeToNeighbours=false, Real distanceLimit=0)
Test for intersection of a given ray with the terrain.
void setDefaultResourceGroup(const String &grp)
Set the default resource group to use to load / save terrains.
void unload()
Unload the terrain and free GPU resources.
ColourValue mCompositeMapDiffuse
void save(const String &filename)
Save terrain data in native form to a standalone file.
static uint16 _calcSkirtVertexIndex(uint16 mainIndex, uint16 vdatasize, bool isCol, uint16 numSkirtRowsCols, uint16 skirtRowColSkip)
Utility method to calculate the skirt index for a given original vertex index.
The definition of the information each layer will contain in this terrain.
Real inputScale
How to scale the input values provided (if any)
bool _getUseVertexCompression() const
Whether we're using vertex compression or not.
TexturePtr mTerrainNormalMap
Texture storing normals for the whole terrrain.
void setRenderQueueGroup(uint8 grp)
Set the render queue group that terrains will be rendered into.
static TerrainGlobalOptions & getSingleton(void)
Override standard Singleton retrieval.
virtual ~TerrainGlobalOptions()
#define OGRE_ALLOC_T(T, count, category)
Allocate a block of memory for a primitive type, and indicate the category of usage.
list< HardwareVertexBufferSharedPtr >::type VBufList
void setDefaultMaterialGenerator(TerrainMaterialGeneratorPtr gen)
Set the default material generator.
static const uint32 TERRAINLAYERDECLARATION_CHUNK_ID
bool isHeightDataModified() const
Returns whether terrain heights have been modified since the terrain was first loaded / defined.
static const uint8 DERIVED_DATA_ALL
static const uint32 TERRAINLAYERSAMPLERELEMENT_CHUNK_ID
const MaterialPtr & _getMaterial() const
Internal getting of material.
bool mUseVertexCompressionWhenAvailable
bool mDerivedDataUpdateInProgress
Terrain * getNeighbour(NeighbourIndex index) const
Retrieve the terrain's neighbour, or null if not present.
void setWorldSize(Real newWorldSize)
Set the world size of terrain.
static void writeLayerInstanceList(const Terrain::LayerInstanceList &lst, StreamSerialiser &ser)
Utility method to write a layer instance list to a stream.
void dirtyRect(const Rect &rect)
Mark a region of the terrain as dirty.
void distributeVertexData()
Rect mDirtyLightmapFromNeighboursRect
ImportData & operator=(const ImportData &rhs)
void decreaseLodLevel()
Removes highest LOD level loaded.
Real getCompositeMapDistance() const
Get the distance at which to start using a composite map if present.
TexturePtrList mBlendTextureList
virtual ~GpuBufferAllocator()
void checkLayers(bool includeGPUResources)
void createOrDestroyGPUNormalMap()
void finaliseHeightDeltas(const Rect &rect, bool cpuData)
Finalise the height deltas.
GpuBufferAllocator * mCustomGpuBufferAllocator
void getVector(const Vector3 &inVec, Vector3 *outVec) const
Translate a vector into world space based on the alignment options.
_OgreTerrainExport friend std::ostream & operator<<(std::ostream &o, const DerivedDataResponse &r)
Class representing a node in the scene graph.
Real mScale
Relationship between one point on the terrain and world size.
void shiftUpGPUBlendChannels(uint8 index)
Shift/slide all GPU blend texture channels > index up one slot. Blend data may shift into the next te...
TerrainLayerDeclaration mLayerDecl
float * getHeightData(long x, long y) const
Get a pointer to the height data for a given point.
virtual void freeAllBuffers()=0
Free any buffers we're holding.
Alignment terrainAlign
The alignment of the terrain.
float getHeightAtWorldPosition(Real x, Real y, Real z) const
Get the height data for a given world position (projecting the point down on to the terrain).
vector< TerrainLayerBlendMap * >::type TerrainLayerBlendMapList
void getTerrainVectorAlign(Real x, Real y, Real z, Alignment align, Vector3 *outVec) const
Translate a vector from world space to local terrain space based on a specified alignment.
TerrainLayerBlendMap * getLayerBlendMap(uint8 layerIndex)
Retrieve the layer blending map for a given layer, which may be used to edit the blending information...
uint16 terrainSize
Terrain size (along one edge) in vertices; must be 2^n+1.
void getTerrainVectorAlign(const Vector3 &inVec, Alignment align, Vector3 *outVec) const
Translate a vector from world space to local terrain space based on a specified alignment.
void updateCompositeMapWithDelay(Real delay=2)
Performs an update on the terrain composite map based on its dirty region, but only at a maximum freq...
size_t getPositionBufVertexSize() const
void _setLightMapRequired(bool lightMap, bool shadowsOnly=false)
Request internal implementation options for the terrain material to use, in this case a terrain-wide ...
A node in a quad tree used to store a patch of terrain.
void setQueryFlags(uint32 flags)
Set the query flags for this terrain.
LayerInstanceList mLayers
Real getSkirtSize() const
The default size of 'skirts' used to hide terrain cracks (default 10, set for new Terrain using Terra...
const float * getDeltaData(long x, long y) const
Get a pointer to the delta data for a given point.
PixelBox * calculateLightmap(const Rect &rect, const Rect &extraTargetRect, Rect &outFinalRect)
Calculate (or recalculate) the terrain lightmap.
const ColourValue & getCompositeMapDiffuse() const
Get the composite map iffuse light to use.
static bool readLayerDeclaration(StreamSerialiser &ser, TerrainLayerDeclaration &targetdecl)
Utility method to read a layer declaration from a stream.
uint32 hashIndexBuffer(uint16 batchSize, uint16 vdatasize, size_t vertexIncrement, uint16 xoffset, uint16 yoffset, uint16 numSkirtRowsCols, uint16 skirtRowColSkip)
void getPosition(Real x, Real y, Real z, Vector3 *outWSpos) const
Convert a position from terrain basis space to world space.
vector< uint8 * >::type BytePointerList
void warmStart(size_t numInstances, uint16 terrainSize, uint16 maxBatchSize, uint16 minBatchSize)
'Warm start' the allocator based on needing x instances of terrain with the given configuration.
OGRE_RW_MUTEX(mNeighbourMutex)
uint16 getNumLodLevels() const
Get the total number of LOD levels in the terrain.
uint16 mLayerBlendMapSizeActual
static const size_t LOD_MORPH_CUSTOM_PARAM
unsigned long mLastMillis
Class encapsulating a standard 4x4 homogeneous matrix.
void getPositionAlign(const Vector3 &TSpos, Alignment align, Vector3 *outWSpos) const
Convert a position from terrain basis space to world space based on a specified alignment.
Utility class to generate a sequentially numbered series of names.
PixelFormat
The pixel format used for images, textures, and render surfaces.
int getHighestLodLoaded() const
void setVisibilityFlags(uint32 flags)
Set the visibility flags for this terrain.
void convertDirection(Space inSpace, const Vector3 &inDir, Space outSpace, Vector3 &outDir) const
Convert a direction from one space to another with respect to this terrain.
Manages the organisation and rendering of a 'scene' i.e.
uint32 getQueryFlags(void) const
Get the query flags for this terrain.
void deriveUVMultipliers()
void createLayerBlendMaps()
An abstraction of a viewport, i.e.
Interface definition for a handler of responses.
static const uint64 TERRAIN_GENERATE_MATERIAL_INTERVAL_MS
Shared pointer implementation used to share vertex buffers.
void freeTemporaryResources()
Free as many resources as possible for optimal run-time memory use.
HardwareIndexBufferSharedPtr getSharedIndexBuffer(uint16 batchSize, uint16 vdatasize, size_t vertexIncrement, uint16 xoffset, uint16 yoffset, uint16 numSkirtRowsCols, uint16 skirtRowColSkip)
Get a shared index buffer for a given number of settings.
Interface used to by the Terrain instance to allocate GPU buffers.
const TexturePtr & getCompositeMap() const
Get access to the composite map, if enabled (as requested by the material generator)
float getHeightAtPoint(long x, long y) const
Get the height data for a given terrain point.
_OgreTerrainExport friend std::ostream & operator<<(std::ostream &o, const GenerateMaterialRequest &r)
void setSize(uint16 newSize)
Set the size of terrain in vertices along one side.
static void writeLayerDeclaration(const TerrainLayerDeclaration &decl, StreamSerialiser &ser)
Utility method to write a layer declaration to a stream.
void _setMorphRequired(bool morph)
Request internal implementation options for the terrain material to use, in this case vertex morphing...
uint8 getLayerCount() const
Get the number of layers in this terrain.
static const uint8 DERIVED_DATA_DELTAS
void getTerrainPositionAlign(const Vector3 &WSpos, Alignment align, Vector3 *outTSpos) const
Convert a position from world space to terrain basis space based on a specified alignment.
const Camera * mLastLODCamera
map< uint32, HardwareIndexBufferSharedPtr >::type IBufMap
static const uint32 TERRAINLAYERINSTANCE_CHUNK_ID
static const uint16 TERRAINLAYERDECLARATION_CHUNK_VERSION
int getPositiveLodLevel(int lodLevel) const
Get the real lod level.
uint32 getVisibilityFlags(void) const
Get the visibility flags for this terrain.
void preFindVisibleObjects(SceneManager *source, SceneManager::IlluminationRenderStage irs, Viewport *v)
Overridden from SceneManager::Listener.
void getNeighbourEdgeRect(NeighbourIndex index, const Rect &inRect, Rect *outRect) const
uint16 getDefaultGlobalColourMapSize() const
Get the default size of the terrain global colour map for a new terrain.
Template class for creating single-instance global classes.
void updateGeometry()
Performs an update on the terrain geometry based on the dirty region.
virtual ~DefaultGpuBufferAllocator()
Real getMaxPixelError() const
Get the maximum screen pixel error that should be allowed when rendering.
void setDefaultGlobalColourMapSize(uint16 sz)
Set the default size of the terrain global colour map for a new terrain.
bool prepare(StreamSerialiser &stream)
Prepare terrain data from saved data.
Real worldSize
The world size of the terrain.
void load(const String &filename)
Prepare and load the terrain in one simple call from a standalone file.
static const uint32 TERRAINGENERALINFO_CHUNK_ID
uint8 * mCpuLightmapStorage
void setUseVertexCompressionWhenAvailable(bool enable)
Set whether to allow vertex compression to be used when the material generator states that it support...
bool mCompositeMapDirtyRectLightmapUpdate
True if the updates included lightmap changes (widen)
TerrainLayerBlendMapList mLayerBlendMapList
Standard implementation of a buffer allocator which re-uses buffers.
void setCastsDynamicShadows(bool s)
Whether the terrain will be able to cast shadows (texture shadows only are supported,...
static const uint16 TERRAINLAYERSAMPLERELEMENT_CHUNK_VERSION
void setRenderQueueGroup(uint8 grp)
Set the render queue group that this terrain will be rendered into.
Vector3 pos
Position of the terrain.
void getPointAlign(long x, long y, Alignment align, Vector3 *outpos) const
Get a Vector3 of the world-space point on the terrain, aligned Y-up always.
PixelBox * mCpuTerrainNormalMap
Pending data.
void getTerrainVector(Real x, Real y, Real z, Vector3 *outVec) const
Translate a vector from world space to local terrain space based on the alignment options.
bool getUseVertexCompressionWhenAvailable() const
Get whether to allow vertex compression to be used when the material generator states that it support...
uint16 mGlobalColourMapSize
Vector3 convertDirection(Space inSpace, const Vector3 &inDir, Space outSpace) const
Convert a direction from one space to another with respect to this terrain.
void unprepare()
Free CPU resources created during prepare methods.
BytePointerList mCpuBlendMapStorage
Staging post for blend map data.
A 3D box aligned with the x/y/z axes.
uint16 mNumLodLevelsPerLeafNode
const Vector3 & getLightMapDirection() const
Get the shadow map light direction to use (world space)
void save(StreamSerialiser &stream)
Save terrain data in native form to a serializing stream.
uint32 getVisibilityFlags(void) const
Get the visbility flags that terrains will be rendered with.
virtual HardwareIndexBufferSharedPtr getSharedIndexBuffer(uint16 batchSize, uint16 vdatasize, size_t vertexIncrement, uint16 xoffset, uint16 yoffset, uint16 numSkirtRowsCols, uint16 skirtRowColSkip)=0
Get a shared index buffer for a given number of settings.
static const uint16 TERRAINDERIVEDDATA_CHUNK_VERSION
Rect calculateHeightDeltas(const Rect &rect)
Calculate (or recalculate) the delta values of heights between a vertex in its recorded position,...
Rect mDirtyGeometryRectForNeighbours
TerrainLodManager * mLodManager
static const uint16 TERRAIN_MAX_BATCH_SIZE
void getEdgeRect(NeighbourIndex index, long range, Rect *outRect) const
bool prepare(const String &filename)
Prepare the terrain from a standalone file.
void handleResponse(const WorkQueue::Response *res, const WorkQueue *srcQ)
WorkQueue::ResponseHandler override.
bool isDerivedDataUpdateInProgress() const
Query whether a derived data update is in progress or not.
void dirtyLightmapRect(const Rect &rect)
Mark a region of the lightmap as dirty.
Real inputBias
How to bias the input values provided (if any)
uint16 getLightMapSize() const
Get the default size of the lightmaps for a new terrain.
void widenRectByVector(const Vector3 &vec, const Rect &inRect, Real minHeight, Real maxHeight, Rect &outRect)
Widen a rectangular area of terrain to take into account an extrusion vector, but specify the min / m...
void setHeightAtPoint(long x, long y, float h)
Set the height data for a given terrain point.
void createOrDestroyGPUCompositeMap()
bool mPrepareInProgress
Don't release Height/DeltaData when preparing.
unsigned long mCompositeMapUpdateCountdown
float * mDeltaData
The delta information defining how a vertex moves before it is removed at a lower LOD.
void notifyNeighbours()
Tell this instance to notify all neighbours that will be affected by a height change that has taken p...
Real getMaxHeight() const
Get the maximum height of the terrain.
static const uint16 WORKQUEUE_DERIVED_DATA_REQUEST
void setMaxPixelError(Real pixerr)
Set the maximum screen pixel error that should be allowed when rendering.
void freeAllBuffers()
Free any buffers we're holding.
const String & getBlendTextureName(uint8 textureIndex) const
Get the name of the packed blend texture at a specific index.
void getVector(Real x, Real y, Real z, Vector3 *outVec) const
Translate a vector into world space based on the alignment options.
bool mCompositeMapRequired
const String & getDefaultResourceGroup() const
Get the default resource group to use to load / save terrains.
void sceneManagerDestroyed(SceneManager *source)
Overridden from SceneManager::Listener.
int getHighestLodLoaded()
Real getSkirtSize() const
The default size of 'skirts' used to hide terrain cracks (default 10)
const String & getMaterialName() const
Get the name of the material being used for the terrain.
void allocateVertexBuffers(Terrain *forTerrain, size_t numVertices, HardwareVertexBufferSharedPtr &destPos, HardwareVertexBufferSharedPtr &destDelta)
Allocate (or reuse) vertex buffers for a terrain LOD.
const TexturePtr & getGlobalColourMap() const
Get access to the global colour map, if enabled.
Utility class providing helper methods for reading / writing structured data held in a DataStream.
void getVectorAlign(const Vector3 &inVec, Alignment align, Vector3 *outVec) const
Translate a vector into world space based on a specified alignment.
Alignment getAlignment() const
Get the alignment of the terrain.
Vector3 convertTerrainToWorldAxes(const Vector3 &inVec) const
void replaceLayer(uint8 index, bool keepBlends, Real worldSize=0, const StringVector *textureNames=0)
Replace an existing terrain layer, optionally preserving all other layer blend maps.
LayerInstanceList layerList
List of layer structures, one for each layer required.
void setLayerTextureName(uint8 layerIndex, uint8 samplerIndex, const String &textureName)
Set the name of the texture bound to a given index within a given layer.
Real worldSize
The world size of the texture to be applied in this layer.
const AxisAlignedBox & getAABB() const
Get the AABB (local coords) of the entire terrain.
bool prepare(const ImportData &importData)
Prepare the terrain from some import data rather than loading from native data.
ImportData(const ImportData &rhs)
void updateCompositeMap()
Performs an update on the terrain composite map based on its dirty region.
AxisAlignedBox getWorldAABB() const
Get the AABB (world coords) of the entire terrain.
void setUseRayBoxDistanceCalculation(bool rb)
Sets whether to use an accurate ray / box intersection to determine distance from a terrain tile,...
void getTerrainPositionAlign(Real x, Real y, Real z, Alignment align, Vector3 *outTSpos) const
Convert a position from world space to terrain basis space based on a specified alignment.
SceneNode * _getRootSceneNode() const
Get the root scene node for the terrain (internal use only)
bool _getMorphRequired() const
Get whether LOD morphing is needed.
static const uint16 WORKQUEUE_GENERATE_MATERIAL_REQUEST
bool mGlobalColourMapEnabled
void load(StreamSerialiser &stream)
Prepare and load the terrain in one simple call from a stream.
uint16 getLODLevelWhenVertexEliminated(long x, long y) const
Utility method, get the first LOD Level at which this vertex is no longer included.
float * getHeightData() const
Get a pointer to all the height data for this terrain.
NeighbourIndex
Neighbour index enumeration - indexed anticlockwise from East like angles.
Class representing colour.
void clearGPUBlendChannel(uint8 index, uint channel)
Reset a blend channel back to full black.
void copyBlendTextureChannel(uint8 srcIndex, uint8 srcChannel, uint8 destIndex, uint8 destChannel)
Copy a GPU blend channel from one source to another. Source and Dest are not required to be in the sa...
A data holder for communicating with the background derived data update.
void dirty()
Mark the entire terrain as dirty.
void getPosition(const Vector3 &TSpos, Vector3 *outWSpos) const
Convert a position from terrain basis space to world space.
void finaliseLightmap(const Rect &rect, PixelBox *lightmapBox)
Finalise the lightmap.
A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
const float * getDeltaData() const
Get a pointer to all the delta data for this terrain.
WorkQueue::Response * handleRequest(const WorkQueue::Request *req, const WorkQueue *srcQ)
WorkQueue::RequestHandler override.
void load(int lodLevel=0, bool synchronous=true)
Load the terrain based on the data already populated via prepare methods.
void determineLodLevels()
void calculateCurrentLod(Viewport *vp)
uint8 getRenderQueueGroup(void) const
Get the render queue group that this terrain will be rendered into.
void shiftDownGPUBlendChannels(uint8 index)
Shift/slide all GPU blend texture channels > index down one slot. Blend data may shift into the previ...
TerrainMaterialGeneratorPtr mDefaultMaterialGenerator
void getPointTransform(Matrix4 *outXform) const
Get a transform which converts Vector4(xindex, yindex, height, 1) into an object-space position inclu...
uint16 maxBatchSize
Maximum batch size (along one edge) in vertices; must be 2^n+1 and <= 65.
uint16 mCompositeMapSizeActual
HardwareVertexBufferSharedPtr getVertexBuffer(VBufList &list, size_t vertexSize, size_t numVertices)
const TexturePtr & getLayerBlendTexture(uint8 index) const
Get a blend texture with a given index.
GpuBufferAllocator * getGpuBufferAllocator()
Get the current buffer allocator.
vector< LayerInstance >::type LayerInstanceList
unsigned long long int mMaterialGenerationCount
void setLightMapDirection(const Vector3 &v)
Set the shadow map light direction to use (world space).
const Vector3 & getPosition() const
Get the world position of the terrain centre.
uint32 getQueryFlags(void) const
Get the default query flags for terrains.
Real getWorldSize() const
Get the size of the terrain in world units.
float getHeightAtTerrainPosition(Real x, Real y) const
Get the height data for a given terrain position.
void setCompositeMapDiffuse(const ColourValue &c)
Set the composite map diffuse light to use.
TerrainQuadTreeNode * mQuadTree
void getNeighbourPointOverflow(long x, long y, NeighbourIndex *outindex, long *outx, long *outy) const
Real getDefaultLayerTextureWorldSize() const
Get the default world size for a layer 'splat' texture to cover.
Vector3 convertPosition(Space inSpace, const Vector3 &inPos, Space outSpace) const
Convert a position from one space to another with respect to this terrain.
void updateDerivedData(bool synchronous=false, uint8 typeMask=0xFF)
Updates derived data for the terrain (LOD, lighting) to reflect changed height data,...
void addQueryFlags(uint32 flags)
As setQueryFlags, except the flags passed as parameters are appended to the existing flags on this ob...
unsigned long mLastLODFrame
void setNeighbour(NeighbourIndex index, Terrain *neighbour, bool recalculate=false, bool notifyOther=true)
Set a terrain's neighbour, or null to detach one.
uint16 getLightmapSize() const
Get the requested size of lightmap for this terrain.
void getPointAlign(long x, long y, float height, Alignment align, Vector3 *outpos) const
Get a Vector3 of the world-space point on the terrain, supplying the height data manually (can be mor...
Image * inputImage
Optional heightmap providing the initial heights for the terrain.
Terrain * raySelectNeighbour(const Ray &ray, Real distanceLimit=0)
Utility method to pick a neighbour based on a ray.
Interface definition for a handler of requests.
uint16 getLayerBlendMapSize() const
Get the default size of the blend maps for a new terrain.
uint8 * mCpuCompositeMapStorage
uint16 getCompositeMapSize() const
Get the default size of the composite maps for a new terrain.
float Real
Software floating point type.
int getTargetLodLevel() const
void getTerrainVector(const Vector3 &inVec, Vector3 *outVec) const
Translate a vector from world space to local terrain space based on the alignment options.
void setGlobalColourMapEnabled(bool enabled, uint16 size=0)
Set whether a global colour map is enabled.
uint16 getNumLodLevelsPerLeaf() const
Get the number of LOD levels in a leaf of the terrain quadtree.
bool isLoaded() const
Return whether the terrain is loaded.
void destroy()
Delete any input data if this struct is set to do so.
PixelFormat getBlendTextureFormat(uint8 textureIndex, uint8 numLayers) const
Real getMinHeight() const
Get the minimum height of the terrain.
void getVectorAlign(Real x, Real y, Real z, Alignment align, Vector3 *outVec) const
Translate a vector into world space based on a specified alignment.
MaterialPtr mCompositeMapMaterial
Rect mCompositeMapDirtyRect
TerrainMaterialGeneratorPtr mMaterialGenerator
int getHighestLodPrepared() const
TerrainLayerDeclaration layerDeclaration
Definition of the contents of each layer (required).
void setCompositeMapSize(uint16 sz)
Sets the default size of composite maps for a new terrain.
void setPosition(const Vector3 &pos)
Set the position of the terrain centre in world coordinates.
TerrainQuadTreeNode * getQuadTree()
Get the top level of the quad tree which is used to divide up the terrain.
void freeVertexBuffers(const HardwareVertexBufferSharedPtr &posbuf, const HardwareVertexBufferSharedPtr &deltabuf)
Free (or return to the pool) vertex buffers for terrain.
uint8 getBlendTextureCount(uint8 numLayers) const
Get the number of blend textures needed for a given number of layers.
bool getUseRayBoxDistanceCalculation() const
Returns whether or not to use an accurate calculation of camera distance from a terrain tile (ray / A...
const MaterialPtr & getMaterial() const
Get the material being used for the terrain.
uint16 mLayerBlendMapSize
static void convertWorldToTerrainAxes(Alignment align, const Vector3 &worldVec, Vector3 *terrainVec)
Utility method to convert axes from world space to terrain space (xy terrain, z up)
bool mGenerateMaterialInProgress
const MaterialPtr & _getCompositeMapMaterial() const
Internal getting of material for the terrain composite map.
An instance of a layer, with specific texture names.
void neighbourModified(NeighbourIndex index, const Rect &edgerect, const Rect &shadowrect)
Notify that a neighbour has just finished updating and that this change affects this tile.
Representation of a ray in space, i.e.
void setDefaultLayerTextureWorldSize(Real sz)
Set the default world size for a layer 'splat' texture to cover.
void removeQueryFlags(uint32 flags)
bool prepare(DataStreamPtr &stream)
Prepare terrain data from saved data.
std::pair< uint8, uint8 > getLayerBlendTextureIndex(uint8 layerIndex) const
Get the texture index and colour channel of the blend information for a given layer.
void setLightMapSize(uint16 sz)
Sets the default size of lightmaps for a new terrain.
TerrainMaterialGeneratorPtr getDefaultMaterialGenerator()
Get the default material generator.
static TerrainGlobalOptions * getSingletonPtr(void)
Override standard Singleton retrieval.
void setResourceGroup(const String &resGroup)
Set the resource group to use when loading / saving.
Real mDefaultLayerTextureWorldSize
static void _populateIndexBuffer(uint16 *pIndexes, uint16 batchSize, uint16 vdatasize, size_t vertexIncrement, uint16 xoffset, uint16 yoffset, uint16 numSkirtRowsCols, uint16 skirtRowColSkip)
Utility method to populate a (locked) index buffer.
uint8 getBlendTextureIndex(uint8 layerIndex) const
Get the index of the blend texture that a given layer uses.
uint8 mDerivedUpdatePendingMask
If another update is requested while one is already running.
static const uint32 TERRAINLAYERSAMPLER_CHUNK_ID
PixelBox * calculateNormals(const Rect &rect, Rect &outFinalRect)
Calculate (or recalculate) the normals on the terrain.
void convertPosition(Space inSpace, const Vector3 &inPos, Space outSpace, Vector3 &outPos) const
Convert a position from one space to another with respect to this terrain.
Standard 3-dimensional vector.
void getPositionAlign(Real x, Real y, Real z, Alignment align, Vector3 *outWSpos) const
Convert a position from terrain basis space to world space based on a specified alignment.
uint16 minBatchSize
Minimum batch size (along one edge) in vertices; must be 2^n+1.
void _dumpTextures(const String &prefix, const String &suffix)
Dump textures to files.
void setLayerWorldSize(uint8 index, Real size)
How large an area in world space the texture in a terrain layer covers before repeating.
static const uint32 TERRAIN_CHUNK_ID
uint16 getCompositeMapSize() const
Get the requested size of composite map for this terrain.
const String & _getDerivedResourceGroup() const
Get the final resource group to use when loading / saving.
uint16 getResolutionAtLod(uint16 lodLevel) const
Gets the resolution of the entire terrain (down one edge) at a given LOD level.
uint16 getGlobalColourMapSize() const
Get the size of the global colour map (if used)
uint16 mLayerBlendMapSize
void handleGenerateMaterialResponse(const WorkQueue::Response *res, const WorkQueue *srcQ)
Handler for GenerateMaterial.
Rect normalUpdateRect
The area of normals that was updated.
bool mUseRayBoxDistanceCalculation
ColourValue mCompositeMapAmbient
A data holder for communicating with the background derived data update.
void setQueryFlags(uint32 flags)
Set the default query flags for terrains.
float * mHeightData
The height data (world coords relative to mPos)
static NameGenerator msCompositeMapNameGenerator
Rect deltaUpdateRect
The area of deltas that was updated.
static NameGenerator msLightmapNameGenerator
void dirtyLightmap()
Mark a the entire lightmap as dirty.
void setSkirtSize(Real skirtSz)
method - the default size of 'skirts' used to hide terrain cracks (default 10)
void convertSpace(Space inSpace, const Vector3 &inVec, Space outSpace, Vector3 &outVec, bool translation) const
Structure encapsulating import data that you may use to bootstrap the terrain without loading from a ...
static void convertTerrainToWorldAxes(Alignment align, const Vector3 &terrainVec, Vector3 *worldVec)
Utility method to convert axes from terrain space (xy terrain, z up) tp world space.
static const uint32 TERRAINDERIVEDDATA_CHUNK_ID
static NameGenerator msNormalMapNameGenerator
void removeLayer(uint8 index)
Remove a layer from the terrain.
VBufList mFreeDeltaBufList
bool canHandleResponse(const WorkQueue::Response *res, const WorkQueue *srcQ)
WorkQueue::ResponseHandler override.
void update(bool synchronous=false)
Trigger the update process for the terrain.
uint8 getRenderQueueGroup(void) const
Get the render queue group that this terrain will be rendered into.
Real getLayerWorldSize(uint8 index) const
How large an area in world space the texture in a terrain layer covers before repeating.
void deleteBlendMaps(uint8 lowIndex)
Delete blend maps for all layers >= lowIndex.
A data holder for communicating with the background GetMaterial.
const String & getResourceGroup() const
Get the resource group to use when loading / saving.
uint16 mLightmapSizeActual
uint16 getMaxBatchSize() const
Get the maximum size in vertices along one side of a batch.
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.