My Project
Public Member Functions | Static Public Member Functions | Friends | List of all members
ParaTerrain::Texture Class Reference

Texture represents a 2D texture image. More...

#include <Texture.h>

Public Member Functions

 Texture (const uint8 *pBuffer, int width, int height, int stride, int borderSize, bool bClamp, bool useCompression, bool useAlpha=false)
 Creates a new 2D texture image from a raw buffer of bytes. More...
 
 Texture (const uint8 *pBuffer, int width, int height, int stride, int borderSize, bool bClamp, bool useCompression, int bytesPerPixel, int textureFormat)
 Creates a new 2D texture image from raw bytes. More...
 
 Texture (TextureEntity *pEntity)
 texture from ParaEngine's texture entity. More...
 
 Texture ()
 Creates an empty 2D texture image that is not yet suitable for use by Demeter. More...
 
 ~Texture ()
 Destroys the texture, including its image data (if still held by this time) and OpenGL texture.
 
DeviceTexturePtr_type UploadTexture ()
 Binds the 2D image data to an OpenGL texture. More...
 
void UnloadTexture ()
 Unbinds the OpenGL texture object, releasing texture memory. More...
 
uint8 * GetBuffer ()
 Gets a pointer to the 2D image data represented by this Texture object. More...
 
int GetWidth ()
 Gets the width of the 2D image in pixels.
 
int GetHeight ()
 Gets the height of the 2D image in pixels.
 
void SetWidth (int nWidth)
 set the image width. More...
 
void SetSharedIndex (int index)
 Marks this Texture as belonging to a Terrain's pool of textures to be used for detail texture painting. More...
 
int GetSharedIndex ()
 Gets the index of this Texture in the managing Terrain's pool of detail textures. More...
 
void SetFilename (const char *szFilename)
 Simply tags the Texture as having come from the specified file. More...
 
const char * GetFilename ()
 Gets the filename tag for this Texture. More...
 
void FlipVertical ()
 Flips the 2D image data of this Texture vertically. More...
 
void FlipHorizontal ()
 Flips the 2D image data of this Texture horizontally. More...
 
bool IsBound ()
 Indicates whether or not this Texture has already been bound to an OpenGL texture object.
 
int GetBitsPerPixel ()
 Gets the color depth of this Texture.
 
int GetBytesPerPixel ()
 
bool IsClamped ()
 Indicates whether or not this Texture uses clamp extensions when bound to an OpenGL texture object.
 
bool UseCompression ()
 Indicates whether or not this Texture uses compression extensions when bound to an OpenGL texture object.
 
int GetBorderSize ()
 Gets the OpenGL border size of this Texture.
 
int GetFormat ()
 Gets the OpenGL texture format of this Texture. For example, GL_RGBA, etc.
 
void SetBufferPersistent (bool persist)
 Specified whether or not this Texture's 2D image data should be retained after it is bound to an OpenGL texture object. More...
 
TextureEntityGetTextureEntity ()
 get the TextureEntity associated with this texture object. More...
 
bool SetTextureEntity (TextureEntity *texture)
 set the TextureEnity. More...
 
DeviceTexturePtr_type GetDevicePointer ()
 get Texture device pointer
 
bool IsEqual (ParaEngine::TextureEntity *pEntity)
 

Static Public Member Functions

static void SetDefaultTextureFormat (int GLTextureFormat)
 Specifies the default OpenGL texture format that textures should be created as when they are bound to OpenGL texture objects. More...
 
static void SetAlphaTextureFormat (int GLTextureFormat)
 Specifies the default OpenGL texture format that textures containing ONLY alpha values should be created as when they are bound to OpenGL texture objects. More...
 
static void SetRgbaTextureFormat (int GLTextureFormat)
 Specifies the default OpenGL texture format that textures should be created as when they are bound to OpenGL texture objects. The default is GL_RGBA. More...
 
static void SetCompressedTextureFormat (int GLTextureFormat)
 Specifies the default OpenGL texture format that textures should be created as when they are bound to OpenGL texture objects. More...
 

Friends

class DetailTexture
 

Detailed Description

Texture represents a 2D texture image.

Instances of this class are used for the overall terrain texture, for common textures, and for detail textures. See the Documentation at terrainengine.com for details on each of these different uses of textures. Most users simply let TextureLoaders create instances of this class for them, but you can use the static SetXXXTextureFormat methods of this class to specify which OpenGL texture formats Demeter should create even if you aren't directly creating your own instances of this class. You can create your own instances of this class for advanced texturing, such as when implementing a TextureFactory or doing detail texture painting.

Constructor & Destructor Documentation

§ Texture() [1/4]

Texture::Texture ( const uint8 *  pBuffer,
int  width,
int  height,
int  stride,
int  borderSize,
bool  bClamp,
bool  useCompression,
bool  useAlpha = false 
)

Creates a new 2D texture image from a raw buffer of bytes.

This constructor assumes that the buffer contains RGB byte triplets or RGBA byte quartets. It makes a copy of the buffer, so the Texture object does not attempt to own the buffer for later deleting.

Parameters
pBufferA pointer to the RGB or RGBA bytes describing the image.
widthThe width of the image in pixels.
heightThe height of the image in pixels.
strideThe number of triplets or quartets in each row. For simple buffers, this will be equal to the width parameter. It will only be different if the rows in your image buffer contain padding before the next row begins.
borderSizeThe border size to use when this image is converted into an OpenGL texture. This value should be zero unless you have built border pixels into your image.
bClampSpecifies whether or not to set texture clamping when the image is converted into an OpenGL texture.
useCompressionSpecifies whether or not to use OpenGL compression extensions when this image is converted into an OpenGL texture.
useAlphaSpecifies whether or not the buffer passed in the pBuffer parameter contains RGBA quartets (where the 4th byte of each pixel is alpha) or not (if not, the buffer contains only RGB triplets.)

§ Texture() [2/4]

Texture::Texture ( const uint8 *  pBuffer,
int  width,
int  height,
int  stride,
int  borderSize,
bool  bClamp,
bool  useCompression,
int  bytesPerPixel,
int  textureFormat 
)

Creates a new 2D texture image from raw bytes.

This constructor assumes that the buffer contains RGB byte triplets or RGBA byte quartets. It makes a copy of the buffer, so the Texture object does not attempt to own the buffer for later deleting. Texture constructor detailed description.

Parameters
pBufferA pointer to the RGB or RGBA bytes describing the image.
widthThe width of the image in pixels.
heightThe height of the image in pixels.
strideThe number of triplets or quartets in each row. For simple buffers, this will be equal to the width parameter. It will only be different if the rows in your image buffer contain padding before the next row begins.
borderSizeThe border size to use when this image is converted into an OpenGL texture. This value should be zero unless you have built border pixels into your image.
bClampSpecifies whether or not to set texture clamping when the image is converted into an OpenGL texture.
useCompressionSpecifies whether or not to use OpenGL compression extensions when this image is converted into an OpenGL texture.
bytesPerPixelThe number of bytes per pixel in the image buffer. Currently, only values of 3 or 4 are legal.
textureFormatThe OpenGL texture format of the texture to be created from the image data.

§ Texture() [3/4]

Texture::Texture ( TextureEntity pEntity)

texture from ParaEngine's texture entity.

§ Texture() [4/4]

Texture::Texture ( )

Creates an empty 2D texture image that is not yet suitable for use by Demeter.

This constructor is only useful if you need to create an instance of Texture but must defer the loading of its image data until a later time.

Member Function Documentation

§ FlipHorizontal()

void Texture::FlipHorizontal ( )

Flips the 2D image data of this Texture horizontally.

If the Texture has already been bound, then it must be rebound by calling UploadTexture() before this change will be visible.

§ FlipVertical()

void Texture::FlipVertical ( )

Flips the 2D image data of this Texture vertically.

If the Texture has already been bound, then it must be rebound by calling UploadTexture() before this change will be visible.

§ GetBuffer()

uint8 * Texture::GetBuffer ( )

Gets a pointer to the 2D image data represented by this Texture object.

Returns
A pointer to the RGB or RGBA bytes representing the 2D image buffer.

§ GetFilename()

const char * Texture::GetFilename ( )

Gets the filename tag for this Texture.

Returns
A null-terminated string of the filename. It is the caller's responsibility to free this string.

§ GetSharedIndex()

int Texture::GetSharedIndex ( )

Gets the index of this Texture in the managing Terrain's pool of detail textures.

Gives you the unique ID of this Texture. This ID can then be used to call methods such as Terrain::Paint() to paint the Texture on the Terrain's surface.

Returns
The unique ID of this Texture within the owning Terrain's pool of detail textures.

§ GetTextureEntity()

TextureEntity * Texture::GetTextureEntity ( )

get the TextureEntity associated with this texture object.

if the texture type is ParaX texture entity

§ SetAlphaTextureFormat()

void Texture::SetAlphaTextureFormat ( int  GLTextureFormat)
static

Specifies the default OpenGL texture format that textures containing ONLY alpha values should be created as when they are bound to OpenGL texture objects.

This setting is used by Demeter whenever it creates OpenGL texture objects from the 2D image data provided by your application (or when Texture Loaders are used.) Therefore, this setting allows you to specify what the format of textures will be, even if you aren't directly creating Texture objects yourself.

§ SetBufferPersistent()

void Texture::SetBufferPersistent ( bool  persist)

Specified whether or not this Texture's 2D image data should be retained after it is bound to an OpenGL texture object.

By default, when a Texture is bound by calling UploadTexture(), its 2D image buffer is deleted. If you need to dynamically modify the texture at runtime, then you must change this behavior by calling SetBufferPersisten(true). In this mode, when UploadTexture() is called, the Texture object still has its original 2D image buffer, so you can make changes to this buffer and call UploadTexture() again to make those changes visible. Of course, this makes each Texture consume approximately twice the memory.

§ SetCompressedTextureFormat()

void Texture::SetCompressedTextureFormat ( int  GLTextureFormat)
static

Specifies the default OpenGL texture format that textures should be created as when they are bound to OpenGL texture objects.

This setting is used by Demeter whenever it creates OpenGL texture objects from the 2D image data provided by your application (or when Texture Loaders are used.) Therefore, this setting allows you to specify what the format of textures will be, even if you aren't directly creating Texture objects yourself. The default value is COMPRESSED_RGB_S3TC_DXT1_EXT.

§ SetDefaultTextureFormat()

void Texture::SetDefaultTextureFormat ( int  GLTextureFormat)
static

Specifies the default OpenGL texture format that textures should be created as when they are bound to OpenGL texture objects.

This setting is used by Demeter whenever it creates OpenGL texture objects from the 2D image data provided by your application (or when Texture Loaders are used.) Therefore, this setting allows you to specify what the format of textures will be, even if you aren't directly creating Texture objects yourself. The default value is GL_RGB8.

§ SetFilename()

void Texture::SetFilename ( const char *  szFilename)

Simply tags the Texture as having come from the specified file.

This tag is only used by Demeter when saving files from the Demeter Texture Editor. Outside of that context, you may freely use this value for your own purposes.

Parameters
szFilenameAny null-terminated string.

§ SetRgbaTextureFormat()

void Texture::SetRgbaTextureFormat ( int  GLTextureFormat)
static

Specifies the default OpenGL texture format that textures should be created as when they are bound to OpenGL texture objects. The default is GL_RGBA.

This setting is used by Demeter whenever it creates OpenGL texture objects from the 2D image data provided by your application (or when Texture Loaders are used.) Therefore, this setting allows you to specify what the format of textures will be, even if you aren't directly creating Texture objects yourself.

§ SetSharedIndex()

void Texture::SetSharedIndex ( int  index)

Marks this Texture as belonging to a Terrain's pool of textures to be used for detail texture painting.

Generally, external code has little reason to ever call this method. This method is used internally by Demeter to manage texture pools.

Parameters
indexThe new unique ID of this Texture. You must guarantee that the ID is unique relative to all other Textures in the pool. SetSharedIndex function detailed description.

§ SetTextureEntity()

bool Texture::SetTextureEntity ( TextureEntity texture)

set the TextureEnity.

The function only succeed, if the texture type is ParaX texture entity. this function can be called multiple times to replace old textures.

§ SetWidth()

void Texture::SetWidth ( int  nWidth)

set the image width.

height is also changed. it will resize the buffer (shrink or enlarge the image) if necessary.

§ UnloadTexture()

void Texture::UnloadTexture ( )

Unbinds the OpenGL texture object, releasing texture memory.

If SetBufferPersistent() has been called on this Texture object, it can be rebound by calling UploadTexture(). UnloadTexture function detailed description.

§ UploadTexture()

DeviceTexturePtr_type Texture::UploadTexture ( )

Binds the 2D image data to an OpenGL texture.

If SetBufferPersistent() has been called on this Texture object, then the associated 2D image data is maintained in system RAM for later calls to UploadTexture(). Otherwise, the image data is freed from system RAM and only the OpenGL texture remains (hopefully residing in video RAM.)

Returns
The texture id of the OpenGL texture object.

create d3d managed texture

create texture using the normal way from memory buffer.


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