My Project
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ParaTerrain::TextureCell Class Reference

Represents a square region on a Terrain surface that is textured. More...

#include <TextureCell.h>

Public Types

typedef std::vector< DetailTexture * > DetailTextureArray_type
 

Public Member Functions

 TextureCell ()
 Constructs an empty TextureCell.
 
 TextureCell (int index)
 Constructs a TextureCell that fits in the specified slot on the managing Terrain. More...
 
void SetTexture (Texture *pTexture)
 Sets the overall Texture for this cell.
 
void AddDetail (DetailTexture *pDetailTexture)
 Adds a new detail texture layer to this cell. More...
 
bool RemoveDetail (int nIndex)
 remove a detailed texture by local index. More...
 
bool RemoveAllDetail ()
 remove all detailed textures. More...
 
DeviceTexturePtr_type BindTexture ()
 Binds the overall texture to a texture object. Used for rendering.
 
DeviceTexturePtr_type BindMask ()
 Binds the overall mask to a texture object.Used for rendering.
 
int GetNumberOfDetails ()
 Gets the number of DetailTexture layers that have been added.
 
DeviceTexturePtr_type BindMask (int index)
 Binds the mask of the specified DetailTexture layer. More...
 
DeviceTexturePtr_type BindDetail (int index)
 Binds the detail texture of the specified DetailTexture layer. More...
 
void UnbindAll ()
 Unbinds the overall texture and all DetailTexture masks and detail textures.
 
DetailTextureGetDetail (int index)
 Gets the specified DetailTexture layer. More...
 
DetailTextureGetDetail (Texture *pTexture)
 Gets the specified DetailTexture layer. More...
 
int GetDetailIndex (Texture *pTexture)
 same as GetDetail(), except that the local detail texture index is returned. More...
 
int NormalizeMask (int index, float fScale=1.0f)
 normalize the given texture mask layer, so that the alpha of the specified layer is unchanged(or scaled by fScale) and the sum of all alpha values of all mask layers at all pixels in the cell is 1. More...
 
TextureGetTexture ()
 Gets the overall base detail texture's texture object. More...
 
DetailTextureGetDetailBase ()
 get the base detailed texture. More...
 
void WriteMask (CParaFile &file, Terrain *pTerrain)
 optimize and then write to disk. More...
 
void ReadMask (CParaFile &file, Terrain *pTerrain)
 read mask file from disk. More...
 
void ResizeTextureMaskWidth (int nWidth)
 resize all texture mask width of all layers
 
void FlipHorizontal ()
 Performs Texture::FlipHorizontal on the overall texture and all DetailTexture layers.
 
void FlipVertical ()
 Performs Texture::FlipVertical on the overall texture and all DetailTexture layers.
 
int GetDetailTextureImageWidth (int detailIndex)
 Gets the width of the specified detail texture in pixels.
 
int GetDetailTextureImageHeight (int detailIndex)
 Gets the height of the specified detail texture in pixels.
 
int GetDetailTextureImageBitsPerPixel (int detailIndex)
 Gets the color depth of the specified detail texture.
 
int GetDetailMaskImageBitsPerPixel (int detailIndex)
 Gets the color depth of the specified detail texture mask.
 
int GetBaseTextureImageWidth ()
 Gets the width of the overall texture in pixels.
 
int GetBaseTextureImageHeight ()
 Gets the height of the overall texture in pixels.
 
int GetBaseTextureImageBitsPerPixel ()
 Gets the color depth of the overall texture.
 
void OptimizeLayer ()
 optimize layers in the cell, by removing those layers whose texture mask is constant 0. More...
 

Static Public Member Functions

static int GetDetailMaskImageWidth (int detailIndex)
 Gets the width of the specified detail texture mask in pixels.
 
static int GetDetailMaskImageHeight (int detailIndex)
 Gets the height of the specified detail texture mask in pixels.
 

Detailed Description

Represents a square region on a Terrain surface that is textured.

A Terrain's surface is divided into a grid of square regions. Each of these regions, a TextureCell, contains a texture which is part of the overall terrain texture (usually an RGB texture), and any number of detail textures (possibly zero.) Each DetailTexture is blending according to its alpha mask with the overall texture underneath it (and with any other DetailTextures underneath it.) The number texture cells in a Terrain is set in one of two ways: (the size of the overall terrain texture / 256) ^ 2, OR by what you specify in a call to Terrain::AllocateTextureCells(). The latter option is only useful if you are managing the overall terrain texture for yourself rather than letting Demeter do it automatically. There is virtually no reason to create instances of this class for yourself unless you are overriding the way Terrain manages its cells. Generally, you will use the instances of this class that are provided for you by the managing Terrain object.

Constructor & Destructor Documentation

§ TextureCell()

TextureCell::TextureCell ( int  index)

Constructs a TextureCell that fits in the specified slot on the managing Terrain.

Parameters
indexSpecifies where in the Terrain's grid of TextureCells this cell should be placed.

Member Function Documentation

§ AddDetail()

void TextureCell::AddDetail ( DetailTexture pDetailTexture)

Adds a new detail texture layer to this cell.

Add a detailed texture layer. Layers will be rendered in the same order they were added in fixed function pipeline. the final result is the same for programmable pipeline though.

§ BindDetail()

DeviceTexturePtr_type TextureCell::BindDetail ( int  index)

Binds the detail texture of the specified DetailTexture layer.

Parameters
indexif this is -1, the base layer is binded

§ BindMask()

DeviceTexturePtr_type TextureCell::BindMask ( int  index)

Binds the mask of the specified DetailTexture layer.

Parameters
indexif this is -1, the base layer is binded

§ GetDetail() [1/2]

DetailTexture * TextureCell::GetDetail ( int  index)

Gets the specified DetailTexture layer.

Parameters
indexif this is -1, the base layer is returned

§ GetDetail() [2/2]

DetailTexture * TextureCell::GetDetail ( Texture pTexture)

Gets the specified DetailTexture layer.

Parameters
pTextureif NULL, base layer is returned.

§ GetDetailBase()

DetailTexture * TextureCell::GetDetailBase ( )

get the base detailed texture.

§ GetDetailIndex()

int TextureCell::GetDetailIndex ( Texture pTexture)

same as GetDetail(), except that the local detail texture index is returned.

Returns
: positive index if found. -1 if it is base layer, or -2 if not found.

§ GetTexture()

Texture * TextureCell::GetTexture ( )

Gets the overall base detail texture's texture object.

Obsoleted, use GetDetailBase() instead.

§ NormalizeMask()

int TextureCell::NormalizeMask ( int  index,
float  fScale = 1.0f 
)

normalize the given texture mask layer, so that the alpha of the specified layer is unchanged(or scaled by fScale) and the sum of all alpha values of all mask layers at all pixels in the cell is 1.

it is good practice to keep every pixel mask normalized, so that we do not get overly lighted terrain surface.

Parameters
indexif this is -1, the base layer is used
fScalethe base layer alpha will be scaled by this value. default to 1.0f, which means that the alpha value of the base reference layer is unchanged. it can also be 0.f, which will simply delete the mask layer.
Returns
: the number of layers affected.

§ OptimizeLayer()

void TextureCell::OptimizeLayer ( )

optimize layers in the cell, by removing those layers whose texture mask is constant 0.

this function is usually called when saving texture cells to disk.

§ ReadMask()

void TextureCell::ReadMask ( CParaFile file,
Terrain pTerrain 
)

read mask file from disk.

it will remove all existing mask file.

§ RemoveAllDetail()

bool ParaTerrain::TextureCell::RemoveAllDetail ( )

remove all detailed textures.

Returns
: true if removed.

§ RemoveDetail()

bool ParaTerrain::TextureCell::RemoveDetail ( int  nIndex)

remove a detailed texture by local index.

Returns
: true if removed.

§ WriteMask()

void TextureCell::WriteMask ( CParaFile file,
Terrain pTerrain 
)

optimize and then write to disk.


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