Public Member Functions | Protected Member Functions | Protected Attributes

sp::video::Texture Class Reference
[Texture Mapping]

#include <spTextureBase.hpp>

Inheritance diagram for sp::video::Texture:
sp::BaseObject sp::video::Direct3D11Texture sp::video::Direct3D9Texture sp::video::GLTextureBase sp::video::OpenGLES1Texture sp::video::OpenGLES2Texture sp::video::OpenGLTexture

List of all members.

Public Member Functions

 Texture ()
 Texture (const STextureCreationFlags &CreationFlags)
virtual ~Texture ()
virtual bool valid () const
 Returns true if the texture is correctly created by the used renderer.
virtual void saveBackup ()
 Save backup from the current image buffer. This can be useful before modifying the image buffer.
virtual void loadBackup ()
 Load backup to the current image buffer.
virtual void clearBackup ()
 Clear the image buffer backup.
virtual void setRenderTarget (bool Enable)
virtual bool setDimension (const ETextureDimensions Type, s32 Depth=1)
virtual void setCubeMapFace (const ECubeMapDirections Face)
virtual void setArrayLayer (u32 Layer)
 Sets the current array layer. This can be used for render targets when rendering into an individual layer (e.g. for texture arrays).
virtual void addMultiRenderTarget (Texture *Tex)
virtual void removeMultiRenderTarget (Texture *Tex)
 Removes the specified multi-render-target.
virtual void clearMultiRenderTarget ()
 Clears all multi-render-targets.
virtual void setDepthBufferSource (Texture *DepthBufferSourceTexture)
virtual void setHardwareFormat (const EHWTextureFormats HardwareFormat)
 Sets the new hardware format type.
virtual void setMipMapping (bool MipMaps)
virtual bool shareImageBuffer ()
 Copies the hardware image buffer into the texture image buffer.
virtual bool updateImageBuffer ()
 Copies the texture image buffer into the hardware image buffer (recreating the renderer texture).
virtual bool updateImageBuffer (const dim::point2di &Pos, const dim::size2di &Size)
 Copies only a specified area into the hardware image buffer.
virtual bool setupImageBuffer (const void *NewImageBuffer)
 Copies the given image buffer into the texture buffer. This image buffer must have the same size (ImageBuffer::getBufferSize()).
virtual bool setupImageBuffer (const ImageBuffer *NewImageBuffer)
 Replaces the old image buffer by copying the new one.
virtual bool setupImageBuffer (const ImageBuffer *SubImageBuffer, const dim::point2di &Position, const dim::size2di &Size)
 Copies the specified area from the image buffer.
virtual void generateMipMap ()
 Generates the mipmaps if enabled.
virtual void bind (s32 Level=0) const
virtual void unbind (s32 Level=0) const
virtual void addAnimFrame (Texture *AnimFrame)
 Adds the specified texture to the animation frame list.
virtual void removeAnimFrame (Texture *AnimFrame)
virtual void setAnimation (bool Enable)
 Enables or disables texture frame animation.
virtual void setAnimFrame (u32 Frame)
 Sets the new animation frame.
virtual void setFilter (const ETextureFilters Filter)
virtual void setFilter (const ETextureFilters MagFilter, const ETextureFilters MinFilter)
virtual void setMagFilter (const ETextureFilters Filter)
virtual void setMinFilter (const ETextureFilters Filter)
virtual void setMipMapFilter (const ETextureMipMapFilters MipMapFilter)
virtual void setWrapMode (const ETextureWrapModes Wrap)
virtual void setWrapMode (const ETextureWrapModes WrapU, const ETextureWrapModes WrapV, const ETextureWrapModes WrapW=TEXWRAP_REPEAT)
virtual void setMultiSamples (s32 Samples)
 Sets multi samples (for anti-aliased textures).
void setFormat (const EPixelFormats Format)
void setSize (const dim::size2di &Size)
void setColorKey (const color &Color, u8 Tolerance=0)
void setColorKey (const dim::point2di &Pos, u8 Alpha=0, u8 Tolerance=0)
void setColorKeyAlpha (const EAlphaBlendingTypes Mode=BLENDING_BRIGHT)
void setColorKeyMask (ImageBuffer *MaskImage, const EAlphaBlendingTypes Mode=BLENDING_BRIGHT)
void ensurePOT ()
void setFilename (const io::stringc &Filename)
 Sets a new filename.
io::stringc getFilename () const
 Returns filename. This will be set after this texture has been loaded.
EPixelFormats getFormat () const
 Returns the pixel format of the image buffer.
dim::size2di getSize () const
 Returns the size of the image buffer.
color getColorKey () const
 Returns the color key of the image buffer.
bool getRenderTarget () const
 Returns true if this texture is a render-target.
ETextureDimensions getDimension () const
 Returns the texture dimension. Can be 1-, 2- or 3 dimensional or a cube-map.
ECubeMapDirections getCubeMapFace () const
 Returns the current active cube map face. By default CUBEMAP_POSITIVE_X.
u32 getArrayLayer () const
 Returns the current array layer. By default 0.
const std::vector< Texture * > & getMultiRenderTargets () const
 Returns the multi-render-targets list.
TexturegetDepthBufferSource () const
EHWTextureFormats getHardwareFormat () const
 Returns the hardware texture format.
virtual bool getMipMapping () const
 Returns true if MIP-mapping is enabled.
std::vector< Texture * > & getAnimFrameList ()
 Returns a reference to the animation frame list.
bool getAnimation () const
 Returns true if this texture has an animation.
s32 getAnimFrameCount () const
 Returns the count of animation frames.
void * getID () const
 Returns Texture's current ID. This is the current frame's texture number.
void * getOrigID () const
 Returns Texture's original ID. Normally only used internally for the renderer.
ImageBuffergetImageBuffer ()
const ImageBuffergetImageBuffer () const
ImageBuffergetImageBufferBackup ()
const ImageBuffergetImageBufferBackup () const
ETextureFilters getMagFilter () const
 Returns only the magnification filter. By default FILTER_SMOOTH.
ETextureFilters getMinFilter () const
 Returns only the minification filter. By default FILTER_SMOOTH.
ETextureMipMapFilters getMipMapFilter () const
 Returns the MIP-map filter. By default FILTER_TRILINEAR.
dim::vector3d< ETextureWrapModesgetWrapMode () const
 Returns the wrap-mode vector. By default TEXWRAP_REPEAT.
void setAnisotropicSamples (s32 Samples)
 Sets the anisotropic filter samples. By default 0 (Modern graphics-cards are able to use 16 samples or more).
s32 getAnisotropicSamples () const
 Returns the anisotropic filter samples.
s32 getMultiSamples () const
 Returns count of multi samples. By default 0.

Protected Member Functions

virtual void updateMultiRenderTargets ()

Protected Attributes

void * OrigID_
void * ID_
io::stringc Filename_
EHWTextureFormats HWFormat_
ETextureDimensions DimensionType_
ETextureFilters MagFilter_
ETextureFilters MinFilter_
ETextureMipMapFilters MipMapFilter_
dim::vector3d< ETextureWrapModesWrapMode_
bool MipMaps_
s32 AnisotropicSamples_
s32 MultiSamples_
ECubeMapDirections CubeMapFace_
u32 ArrayLayer_
bool isRenderTarget_
std::vector< Texture * > MultiRenderTargetList_
TextureDepthBufferSource_
bool isAnim_
std::vector< Texture * > AnimFrameList_
ImageBufferImageBuffer_
ImageBufferImageBufferBackup_

Detailed Description

This is the Texture base class. You only need to use this class (or rather interface). The main content of this class is an instance of the ImageBuffer class which holds the image data in the RAM which can then be uploaded to the graphics hardware.


Constructor & Destructor Documentation

sp::video::Texture::Texture (  ) 
sp::video::Texture::Texture ( const STextureCreationFlags CreationFlags  ) 
sp::video::Texture::~Texture (  )  [virtual]

Member Function Documentation

void sp::video::Texture::addAnimFrame ( Texture AnimFrame  )  [virtual]

Adds the specified texture to the animation frame list.

void sp::video::Texture::addMultiRenderTarget ( Texture Tex  )  [virtual]

Adds a new multi-render-target texture. To use several render targets at once you have to add several textures to a render-target-texture. e.g. convert a texture to a render target and add several textures.

void sp::video::Texture::bind ( s32  Level = 0  )  const [virtual]
void sp::video::Texture::clearBackup (  )  [virtual]

Clear the image buffer backup.

void sp::video::Texture::clearMultiRenderTarget (  )  [virtual]

Clears all multi-render-targets.

void sp::video::Texture::ensurePOT (  ) 

Ensures that the texture is a POT (power-of-two) texture. This is equivalent to the following code:

        if (!Tex->getImageBuffer()->isSizePOT())
            Tex->setSize(Tex->getImageBuffer()->getSizePOT());
void sp::video::Texture::generateMipMap (  )  [virtual]

Generates the mipmaps if enabled.

Reimplemented in sp::video::GLTextureBase.

bool sp::video::Texture::getAnimation (  )  const [inline]

Returns true if this texture has an animation.

s32 sp::video::Texture::getAnimFrameCount (  )  const [inline]

Returns the count of animation frames.

std::vector<Texture*>& sp::video::Texture::getAnimFrameList (  )  [inline]

Returns a reference to the animation frame list.

s32 sp::video::Texture::getAnisotropicSamples (  )  const [inline]

Returns the anisotropic filter samples.

u32 sp::video::Texture::getArrayLayer (  )  const [inline]

Returns the current array layer. By default 0.

color sp::video::Texture::getColorKey (  )  const [inline]

Returns the color key of the image buffer.

ECubeMapDirections sp::video::Texture::getCubeMapFace (  )  const [inline]

Returns the current active cube map face. By default CUBEMAP_POSITIVE_X.

Texture* sp::video::Texture::getDepthBufferSource (  )  const [inline]

Returns pointer to the Texture object which holds the depth buffer. This can be used when several render targets shall share the same depth buffer. By default 0 which means the render target has its own depth buffer.

ETextureDimensions sp::video::Texture::getDimension (  )  const [inline]

Returns the texture dimension. Can be 1-, 2- or 3 dimensional or a cube-map.

io::stringc sp::video::Texture::getFilename (  )  const [inline]

Returns filename. This will be set after this texture has been loaded.

EPixelFormats sp::video::Texture::getFormat (  )  const [inline]

Returns the pixel format of the image buffer.

EHWTextureFormats sp::video::Texture::getHardwareFormat (  )  const [inline]

Returns the hardware texture format.

void* sp::video::Texture::getID (  )  const [inline]

Returns Texture's current ID. This is the current frame's texture number.

ImageBuffer* sp::video::Texture::getImageBuffer (  )  [inline]

Gets the ImageBuffer object. Use this function to get access to the image data. e.g. when you want to turn the image write:

        // Turn the image buffer.
        Tex->getImageBuffer()->turnImage(TURNDEGREE_90);
        // Update the image buffer: this uploades the buffer to the graphics hardware.
        Tex->updateImageBuffer();
Returns:
Pointer to the ImageBuffer instance.
const ImageBuffer* sp::video::Texture::getImageBuffer (  )  const [inline]
const ImageBuffer* sp::video::Texture::getImageBufferBackup (  )  const [inline]
ImageBuffer* sp::video::Texture::getImageBufferBackup (  )  [inline]
ETextureFilters sp::video::Texture::getMagFilter (  )  const [inline]

Returns only the magnification filter. By default FILTER_SMOOTH.

ETextureFilters sp::video::Texture::getMinFilter (  )  const [inline]

Returns only the minification filter. By default FILTER_SMOOTH.

ETextureMipMapFilters sp::video::Texture::getMipMapFilter (  )  const [inline]

Returns the MIP-map filter. By default FILTER_TRILINEAR.

virtual bool sp::video::Texture::getMipMapping (  )  const [inline, virtual]

Returns true if MIP-mapping is enabled.

const std::vector<Texture*>& sp::video::Texture::getMultiRenderTargets (  )  const [inline]

Returns the multi-render-targets list.

s32 sp::video::Texture::getMultiSamples (  )  const [inline]

Returns count of multi samples. By default 0.

void* sp::video::Texture::getOrigID (  )  const [inline]

Returns Texture's original ID. Normally only used internally for the renderer.

bool sp::video::Texture::getRenderTarget (  )  const [inline]

Returns true if this texture is a render-target.

dim::size2di sp::video::Texture::getSize (  )  const [inline]

Returns the size of the image buffer.

dim::vector3d<ETextureWrapModes> sp::video::Texture::getWrapMode (  )  const [inline]

Returns the wrap-mode vector. By default TEXWRAP_REPEAT.

void sp::video::Texture::loadBackup (  )  [virtual]

Load backup to the current image buffer.

void sp::video::Texture::removeAnimFrame ( Texture AnimFrame  )  [virtual]
void sp::video::Texture::removeMultiRenderTarget ( Texture Tex  )  [virtual]

Removes the specified multi-render-target.

void sp::video::Texture::saveBackup (  )  [virtual]

Save backup from the current image buffer. This can be useful before modifying the image buffer.

void sp::video::Texture::setAnimation ( bool  Enable  )  [virtual]

Enables or disables texture frame animation.

void sp::video::Texture::setAnimFrame ( u32  Frame  )  [virtual]

Sets the new animation frame.

void sp::video::Texture::setAnisotropicSamples ( s32  Samples  )  [inline]

Sets the anisotropic filter samples. By default 0 (Modern graphics-cards are able to use 16 samples or more).

void sp::video::Texture::setArrayLayer ( u32  Layer  )  [virtual]

Sets the current array layer. This can be used for render targets when rendering into an individual layer (e.g. for texture arrays).

void sp::video::Texture::setColorKey ( const color Color,
u8  Tolerance = 0 
)

Sets the color key with the given tolerance. This is equivalent to:

        Tex->getImageBuffer()->setColorKey(Color, Tolerance);
        Tex->updateImageBuffer();
void sp::video::Texture::setColorKey ( const dim::point2di Pos,
u8  Alpha = 0,
u8  Tolerance = 0 
)
void sp::video::Texture::setColorKeyAlpha ( const EAlphaBlendingTypes  Mode = BLENDING_BRIGHT  ) 
void sp::video::Texture::setColorKeyMask ( ImageBuffer MaskImage,
const EAlphaBlendingTypes  Mode = BLENDING_BRIGHT 
)
void sp::video::Texture::setCubeMapFace ( const ECubeMapDirections  Face  )  [virtual]

Sets the current CubeMap render-target face. Use this function to switch between the six faces (+X, -X, +Y, -Y, +Z, -Z) when rendering the CubeMap.

void sp::video::Texture::setDepthBufferSource ( Texture DepthBufferSourceTexture  )  [virtual]

Sets the source texture of the depth buffer for render targets.

Parameters:
DepthBufferSourceTexture,: Specifies the texture from which the depth buffer is to be used. This needs to be a render target texture. By default 0.
bool sp::video::Texture::setDimension ( const ETextureDimensions  Type,
s32  Depth = 1 
) [virtual]

Sets the texture's dimension. The dimension can be: 1D, 2D, 3D or CubeMap. If the dimension is set to a CubeMap the texture has 6 faces (+X, -X, +Y, -Y, +Z, -Z). If the dimension is set to a 3D texture "setDepth" or "getDepth" functions can be used to configure texture's depth.

Parameters:
Type,: Dimension type. There are 1D, 2D, 3D or CubeMap.
Depth,: Depth for a 3D texture. By default 1.
Returns:
True if the dimension could be set. Otherwise the height could not be divided by the specified depth.
void sp::video::Texture::setFilename ( const io::stringc Filename  )  [inline]

Sets a new filename.

void sp::video::Texture::setFilter ( const ETextureFilters  Filter  )  [virtual]

Texture's filter mode. By default FILTER_SMOOTH. The renderers normally calls this type "linear". But in this engine a "linear" texture has none-smoothed texels. This is the second value: FILTER_LINEAR. Mag (magnification) is the filter when the texels are bigger then one pixel on the screen. Min (minification) is the filter when the texels are smaller then one pixel on the screen (normally using MipMaps).

Reimplemented in sp::video::Direct3D11Texture, and sp::video::GLTextureBase.

void sp::video::Texture::setFilter ( const ETextureFilters  MagFilter,
const ETextureFilters  MinFilter 
) [virtual]
void sp::video::Texture::setFormat ( const EPixelFormats  Format  ) 

Sets the new pixel format of the image buffer. This is equivalent to:

        Tex->getImageBuffer()->setFormat(Format);
        Tex->updateImageBuffer();
void sp::video::Texture::setHardwareFormat ( const EHWTextureFormats  HardwareFormat  )  [virtual]

Sets the new hardware format type.

Reimplemented in sp::video::Direct3D11Texture.

void sp::video::Texture::setMagFilter ( const ETextureFilters  Filter  )  [virtual]
void sp::video::Texture::setMinFilter ( const ETextureFilters  Filter  )  [virtual]
void sp::video::Texture::setMipMapFilter ( const ETextureMipMapFilters  MipMapFilter  )  [virtual]

Texture's mipmap filter. By default FILTER_TRILINEAR. Three filter types are supported: FILTER_BILINEAR, FILTER_TRILINEAR and FILTER_ANISOTROPIC. If the filter is FILTER_ANISOTROPIC the anisotropy factor can be set by "setAnisotropicSamples". The texture quality grows with these parameters. i.e. FILTER_BILINEAR looks worst and FILTER_ANISOTROPIC looks best. This is the method on how MIP-mapping is computed. If the texture has no MIP-maps the filter is unnecessary.

Reimplemented in sp::video::Direct3D11Texture, and sp::video::GLTextureBase.

void sp::video::Texture::setMipMapping ( bool  MipMaps  )  [virtual]

Enables or disables MIP-mapping. By default MIP-mapping is enabled and in 3D graphics normally it shoudl be always enabled. If MIP-mapping is disabled the texture can look very ugly when the count of rendered pixels are considerably less then the count of texels stored in the texture. Moreover using MIP-mapping makes the render process faster! This is due to the fact that less memory must be transmited for rendering operations. Particularly conspicuous in software rendering. However when using render-targets which are updated non-stop a texture without MIP-maps makes sense because auto.-MIP-map generation is not very fast with non-stop changes.

void sp::video::Texture::setMultiSamples ( s32  Samples  )  [virtual]

Sets multi samples (for anti-aliased textures).

void sp::video::Texture::setRenderTarget ( bool  Enable  )  [virtual]

Enables or disables render target mode for the texture. If enabled the texture's image buffer can not be changed by the CPU only by the GPU via rendering into the texture.

void sp::video::Texture::setSize ( const dim::size2di Size  ) 

Sets the new size of the image buffer. This is equivalent to:

        Tex->getImageBuffer()->setSize(Size);
        Tex->updateImageBuffer();
bool sp::video::Texture::setupImageBuffer ( const void *  NewImageBuffer  )  [virtual]

Copies the given image buffer into the texture buffer. This image buffer must have the same size (ImageBuffer::getBufferSize()).

bool sp::video::Texture::setupImageBuffer ( const ImageBuffer SubImageBuffer,
const dim::point2di Position,
const dim::size2di Size 
) [virtual]

Copies the specified area from the image buffer.

bool sp::video::Texture::setupImageBuffer ( const ImageBuffer NewImageBuffer  )  [virtual]

Replaces the old image buffer by copying the new one.

void sp::video::Texture::setWrapMode ( const ETextureWrapModes  Wrap  )  [virtual]

Texture coordinate wrap mode. This type says the renderer how to handle the texture coordinate greater then 1.0 or smaller then 0.0. Three types are supported: TEXWRAP_REPEAT (default value), TEXWRAP_MIRROR, TEXWRAP_CLAMP (normall used for SkyBoxes).

Reimplemented in sp::video::Direct3D11Texture, and sp::video::GLTextureBase.

void sp::video::Texture::setWrapMode ( const ETextureWrapModes  WrapU,
const ETextureWrapModes  WrapV,
const ETextureWrapModes  WrapW = TEXWRAP_REPEAT 
) [virtual]
bool sp::video::Texture::shareImageBuffer (  )  [virtual]

Copies the hardware image buffer into the texture image buffer.

Reimplemented in sp::video::Direct3D9Texture, and sp::video::Direct3D11Texture.

void sp::video::Texture::unbind ( s32  Level = 0  )  const [virtual]
bool sp::video::Texture::updateImageBuffer ( const dim::point2di Pos,
const dim::size2di Size 
) [virtual]

Copies only a specified area into the hardware image buffer.

bool sp::video::Texture::updateImageBuffer (  )  [virtual]

Copies the texture image buffer into the hardware image buffer (recreating the renderer texture).

Reimplemented in sp::video::Direct3D9Texture, sp::video::Direct3D11Texture, and sp::video::OpenGLES1Texture.

void sp::video::Texture::updateMultiRenderTargets (  )  [protected, virtual]
bool sp::video::Texture::valid (  )  const [virtual]

Returns true if the texture is correctly created by the used renderer.

Reimplemented in sp::video::Direct3D9Texture, sp::video::Direct3D11Texture, and sp::video::GLTextureBase.


Member Data Documentation

std::vector<Texture*> sp::video::Texture::AnimFrameList_ [protected]
void* sp::video::Texture::ID_ [protected]

Used image buffer (pixel buffer) This image buffer represents the current texture pixel buffer (normal, resized or with manipulated surface)

Backup of the current image buffer (by default 0) This image buffer can be saved and loaded when changing format, size etc. Its format is always RGBA.

bool sp::video::Texture::isAnim_ [protected]
bool sp::video::Texture::MipMaps_ [protected]
void* sp::video::Texture::OrigID_ [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines