OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ESMTerrain::Storage Class Referenceabstract

Feeds data from ESM terrain records (ESM::Land, ESM::LandTexture) into the terrain component, converting it on the fly as needed. More...

#include <storage.hpp>

Inheritance diagram for ESMTerrain::Storage:
Collaboration diagram for ESMTerrain::Storage:

Public Member Functions

 Storage (const VFS::Manager *vfs, const std::string &normalMapPattern="", const std::string &normalHeightMapPattern="", bool autoUseNormalMaps=false, const std::string &specularMapPattern="", bool autoUseSpecularMaps=false)
 
const ESM::Land::LandDatagetLandData (int cellX, int cellY, int flags)
 
virtual void getBounds (float &minX, float &maxX, float &minY, float &maxY)=0
 Get bounds of the whole terrain in cell units. More...
 
virtual bool getMinMaxHeights (float size, const osg::Vec2f &center, float &min, float &max)
 
virtual void fillVertexBuffers (int lodLevel, float size, const osg::Vec2f &center, osg::ref_ptr< osg::Vec3Array > positions, osg::ref_ptr< osg::Vec3Array > normals, osg::ref_ptr< osg::Vec4Array > colours)
 
virtual void getBlendmaps (float chunkSize, const osg::Vec2f &chunkCenter, bool pack, ImageVector &blendmaps, std::vector< Terrain::LayerInfo > &layerList)
 
virtual float getHeightAt (const osg::Vec3f &worldPos)
 
virtual Terrain::LayerInfo getDefaultLayer ()
 
virtual float getCellWorldSize ()
 Get the transformation factor for mapping cell units to world units. More...
 
virtual int getCellVertices ()
 Get the number of vertices on one side for each cell. Should be (power of two)+1. More...
 
- Public Member Functions inherited from Terrain::Storage
virtual ~Storage ()
 

Private Types

typedef std::pair< short, short > UniqueTextureId
 

Private Member Functions

virtual const ESM::LandgetLand (int cellX, int cellY)=0
 
virtual const ESM::LandTexturegetLandTexture (int index, short plugin)=0
 
void fixNormal (osg::Vec3f &normal, int cellX, int cellY, int col, int row)
 
void fixColour (osg::Vec4f &colour, int cellX, int cellY, int col, int row)
 
void averageNormal (osg::Vec3f &normal, int cellX, int cellY, int col, int row)
 
float getVertexHeight (const ESM::Land *land, int x, int y)
 
UniqueTextureId getVtexIndexAt (int cellX, int cellY, int x, int y)
 
std::string getTextureName (UniqueTextureId id)
 
Terrain::LayerInfo getLayerInfo (const std::string &texture)
 

Private Attributes

const VFS::ManagermVFS
 
std::map< std::string,
Terrain::LayerInfo
mLayerInfoMap
 
OpenThreads::Mutex mLayerInfoMutex
 
std::string mNormalMapPattern
 
std::string mNormalHeightMapPattern
 
bool mAutoUseNormalMaps
 
std::string mSpecularMapPattern
 
bool mAutoUseSpecularMaps
 

Additional Inherited Members

- Public Types inherited from Terrain::Storage
typedef std::vector
< osg::ref_ptr< osg::Image > > 
ImageVector
 

Detailed Description

Feeds data from ESM terrain records (ESM::Land, ESM::LandTexture) into the terrain component, converting it on the fly as needed.

Member Typedef Documentation

typedef std::pair<short, short> ESMTerrain::Storage::UniqueTextureId
private

Constructor & Destructor Documentation

ESMTerrain::Storage::Storage ( const VFS::Manager vfs,
const std::string &  normalMapPattern = "",
const std::string &  normalHeightMapPattern = "",
bool  autoUseNormalMaps = false,
const std::string &  specularMapPattern = "",
bool  autoUseSpecularMaps = false 
)

Member Function Documentation

void ESMTerrain::Storage::averageNormal ( osg::Vec3f &  normal,
int  cellX,
int  cellY,
int  col,
int  row 
)
private

Here is the call graph for this function:

Here is the caller graph for this function:

void ESMTerrain::Storage::fillVertexBuffers ( int  lodLevel,
float  size,
const osg::Vec2f &  center,
osg::ref_ptr< osg::Vec3Array >  positions,
osg::ref_ptr< osg::Vec3Array >  normals,
osg::ref_ptr< osg::Vec4Array >  colours 
)
virtual

Fill vertex buffers for a terrain chunk.

Note
May be called from background threads. Make sure to only call thread-safe functions from here!
Vertices should be written in row-major order (a row is defined as parallel to the x-axis). The specified positions should be in local space, i.e. relative to the center of the terrain chunk.
Parameters
lodLevelLOD level, 0 = most detailed
sizesize of the terrain chunk in cell units
centercenter of the chunk in cell units
positionsbuffer to write vertices
normalsbuffer to write vertex normals
coloursbuffer to write vertex colours

Implements Terrain::Storage.

Here is the call graph for this function:

void ESMTerrain::Storage::fixColour ( osg::Vec4f &  colour,
int  cellX,
int  cellY,
int  col,
int  row 
)
private

Here is the call graph for this function:

Here is the caller graph for this function:

void ESMTerrain::Storage::fixNormal ( osg::Vec3f &  normal,
int  cellX,
int  cellY,
int  col,
int  row 
)
private

Here is the call graph for this function:

Here is the caller graph for this function:

void ESMTerrain::Storage::getBlendmaps ( float  chunkSize,
const osg::Vec2f &  chunkCenter,
bool  pack,
ImageVector blendmaps,
std::vector< Terrain::LayerInfo > &  layerList 
)
virtual

Create textures holding layer blend values for a terrain chunk.

Note
The terrain chunk shouldn't be larger than one cell since otherwise we might have to do a ridiculous amount of different layers. For larger chunks, composite maps should be used.
May be called from background threads.
Parameters
chunkSizesize of the terrain chunk in cell units
chunkCentercenter of the chunk in cell units
packWhether to pack blend values for up to 4 layers into one texture (one in each channel) - otherwise, each texture contains blend values for one layer only. Shader-based rendering can utilize packing, FFP can't.
blendmapscreated blendmaps will be written here
layerListnames of the layer textures used will be written here

Implements Terrain::Storage.

Here is the call graph for this function:

virtual void ESMTerrain::Storage::getBounds ( float &  minX,
float &  maxX,
float &  minY,
float &  maxY 
)
pure virtual

Get bounds of the whole terrain in cell units.

Implements Terrain::Storage.

Implemented in CSVRender::TerrainStorage, and MWRender::TerrainStorage.

int ESMTerrain::Storage::getCellVertices ( )
virtual

Get the number of vertices on one side for each cell. Should be (power of two)+1.

Implements Terrain::Storage.

float ESMTerrain::Storage::getCellWorldSize ( )
virtual

Get the transformation factor for mapping cell units to world units.

Implements Terrain::Storage.

Terrain::LayerInfo ESMTerrain::Storage::getDefaultLayer ( )
virtual

Implements Terrain::Storage.

float ESMTerrain::Storage::getHeightAt ( const osg::Vec3f &  worldPos)
virtual

Implements Terrain::Storage.

Here is the call graph for this function:

virtual const ESM::Land* ESMTerrain::Storage::getLand ( int  cellX,
int  cellY 
)
privatepure virtual

Implemented in CSVRender::TerrainStorage, and MWRender::TerrainStorage.

Here is the caller graph for this function:

const ESM::Land::LandData * ESMTerrain::Storage::getLandData ( int  cellX,
int  cellY,
int  flags 
)

Data is loaded first, if necessary. Will return a 0-pointer if there is no data for any of the data types specified via flags. Will also return a 0-pointer if there is no land record for the coordinates cellX / cellY.

Here is the call graph for this function:

Here is the caller graph for this function:

virtual const ESM::LandTexture* ESMTerrain::Storage::getLandTexture ( int  index,
short  plugin 
)
privatepure virtual

Implemented in CSVRender::TerrainStorage, and MWRender::TerrainStorage.

Here is the caller graph for this function:

Terrain::LayerInfo ESMTerrain::Storage::getLayerInfo ( const std::string &  texture)
private

Here is the call graph for this function:

Here is the caller graph for this function:

bool ESMTerrain::Storage::getMinMaxHeights ( float  size,
const osg::Vec2f &  center,
float &  min,
float &  max 
)
virtual

Get the minimum and maximum heights of a terrain region.

Note
Will only be called for chunks with size = minBatchSize, i.e. leafs of the quad tree. Larger chunks can simply merge AABB of children.
Parameters
sizesize of the chunk in cell units
centercenter of the chunk in cell units
minmin height will be stored here
maxmax height will be stored here
Returns
true if there was data available for this terrain chunk
Todo:
investigate if min/max heights should be stored at load time in ESM::Land instead

Implements Terrain::Storage.

Here is the call graph for this function:

std::string ESMTerrain::Storage::getTextureName ( UniqueTextureId  id)
private

Here is the call graph for this function:

Here is the caller graph for this function:

float ESMTerrain::Storage::getVertexHeight ( const ESM::Land land,
int  x,
int  y 
)
private

Here is the call graph for this function:

Here is the caller graph for this function:

Storage::UniqueTextureId ESMTerrain::Storage::getVtexIndexAt ( int  cellX,
int  cellY,
int  x,
int  y 
)
private

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

bool ESMTerrain::Storage::mAutoUseNormalMaps
private
bool ESMTerrain::Storage::mAutoUseSpecularMaps
private
std::map<std::string, Terrain::LayerInfo> ESMTerrain::Storage::mLayerInfoMap
private
OpenThreads::Mutex ESMTerrain::Storage::mLayerInfoMutex
private
std::string ESMTerrain::Storage::mNormalHeightMapPattern
private
std::string ESMTerrain::Storage::mNormalMapPattern
private
std::string ESMTerrain::Storage::mSpecularMapPattern
private
const VFS::Manager* ESMTerrain::Storage::mVFS
private

The documentation for this class was generated from the following files: