My Project
|
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. | |
DetailTexture * | GetDetail (int index) |
Gets the specified DetailTexture layer. More... | |
DetailTexture * | GetDetail (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... | |
Texture * | GetTexture () |
Gets the overall base detail texture's texture object. More... | |
DetailTexture * | GetDetailBase () |
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. | |
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.
TextureCell::TextureCell | ( | int | index | ) |
Constructs a TextureCell that fits in the specified slot on the managing Terrain.
index | Specifies where in the Terrain's grid of TextureCells this cell should be placed. |
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.
DeviceTexturePtr_type TextureCell::BindDetail | ( | int | index | ) |
Binds the detail texture of the specified DetailTexture layer.
index | if this is -1, the base layer is binded |
DeviceTexturePtr_type TextureCell::BindMask | ( | int | index | ) |
Binds the mask of the specified DetailTexture layer.
index | if this is -1, the base layer is binded |
DetailTexture * TextureCell::GetDetail | ( | int | index | ) |
Gets the specified DetailTexture layer.
index | if this is -1, the base layer is returned |
DetailTexture * TextureCell::GetDetail | ( | Texture * | pTexture | ) |
Gets the specified DetailTexture layer.
pTexture | if NULL, base layer is returned. |
DetailTexture * TextureCell::GetDetailBase | ( | ) |
get the base detailed texture.
int TextureCell::GetDetailIndex | ( | Texture * | pTexture | ) |
same as GetDetail(), except that the local detail texture index is returned.
Texture * TextureCell::GetTexture | ( | ) |
Gets the overall base detail texture's texture object.
Obsoleted, use GetDetailBase() instead.
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.
index | if this is -1, the base layer is used |
fScale | the 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. |
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.
read mask file from disk.
it will remove all existing mask file.
bool ParaTerrain::TextureCell::RemoveAllDetail | ( | ) |
remove all detailed textures.
bool ParaTerrain::TextureCell::RemoveDetail | ( | int | nIndex | ) |
remove a detailed texture by local index.
optimize and then write to disk.