PixelLightAPI  .
Public Types | Public Member Functions | Protected Member Functions
PLRenderer::Texture Class Reference

Texture resource class. More...

#include <Texture.h>

Inheritance diagram for PLRenderer::Texture:
Inheritance graph
[legend]

List of all members.

Public Types

enum  ECompressionFormat {
  Default = 0, DXT1 = 1, DXT3 = 2, DXT5 = 3,
  DXT5_xGxR = 4, LATC1 = 5, LATC2 = 6, LATC2_XYSwizzle = 7,
  None = 8
}
 Texture compression formats. More...

Public Member Functions

virtual PLRENDERER_API ~Texture ()
 Destructor.
TextureManagerGetTextureManager () const
 Returns the texture manager this texture is in.
PLRENDERER_API TextureBufferGetTextureBuffer () const
 Returns the texture buffer.
PLRENDERER_API void SetTextureBuffer (TextureBuffer *pTextureBuffer=nullptr)
 Sets the texture buffer.
ECompressionFormat GetCompressionHint () const
 Returns the texture compression hint.
void SetCompressionHint (ECompressionFormat nFormat=Default)
 Sets the texture compression hint.
const PLMath::Vector3iGetOriginalSize () const
 Returns the original texture size.
PLRENDERER_API bool Bind (PLCore::uint32 nStage=0) const
 Makes the texture to the current renderer texture.
virtual PLRENDERER_API bool IsAnimated () const
 Returns whether or not this texture is animated.
virtual PLRENDERER_API bool LoadByFilename (const PLCore::String &sFilename, const PLCore::String &sParams="", const PLCore::String &sMethod="") override
 Loads the loadable from a file given by filename.
virtual PLRENDERER_API bool SaveByFilename (const PLCore::String &sFilename, const PLCore::String &sParams="", const PLCore::String &sMethod="") override
 Saves the loadable to a file given by filename.
virtual PLRENDERER_API bool SaveByFile (PLCore::File &cFile, const PLCore::String &sParams="", const PLCore::String &sMethod="") override
 Saves the loadable to a file given by reference.
virtual PLRENDERER_API bool Unload () override
 Unloads the loadable.
virtual PLRENDERER_API
PLCore::String 
GetLoadableTypeName () const override
 Returns the loadable type name.

Protected Member Functions

 Texture (TextureManager &cManager, const PLCore::String &sName)
 Constructor.
PLCore::uint32 GetCorrectTextureSize (PLCore::uint32 nSize, PLCore::uint32 nMinSize, PLCore::uint32 nMaxSize, bool bRectangle) const
 Returns a correct texture size.
void DestroyTextureBuffer ()
 Destroys the used texture buffer.

Detailed Description

Texture resource class.

Remarks:
This generic texture class encapsulates the concrete renderer textures for easier and universal usage. 'Texture animation' is also 'just a texture'. This class can load the data automatically using internally the 'Image'-class - so all image formats the image class supports can also be used as textures.

The texture class has own special texture compression information standing 'above' the real renderer texture compression. A good example for the usage of this is 'normal map compression'. Because normal maps don't look good when using classic compression, it's better do don't compress them - or to use some tricks so we don't loose to much quality. So, the compression information just indicates for instance the usage like 'DXT5_xGxR' were a texture is compressed as 'DXT5', but the data is stored in a slightly other way. A scene renderer implementation can use this proved information to tell the shader programs about the special usage of the data. When loading a texture, by default the texture data is used as provided. If a 'tga' image is used, no GPU compression is used. If a 'dds' image provides 'fitting' compressed data, this data is directly send to the GPU.

To have some control over the loading and usage of a texture, we provide a XML based file format called 'plt'. If you for instance load in a texture called 'Data/Textures/Soldier_normal.dds', we look whether or not there's a file called 'Soldier_normal.plt' within the same directory. If so, we take the information this file contains into account. A 'plt' file for a compressed normal map may look like this: <?xml version="1.0"?> <Texture version="1"> <General compression="DXT5_xGxR"> </Texture> We can automatically detect whether or not a texture is compressed, but we CAN'T find out automatically HOW the data is organized internally. In the sample above 'DXT5_xGxR' tells us that 'swizzled DXT5' is used. It's the job of a scene renderer or of YOU as programmer to take this information into account.


Member Enumeration Documentation

Texture compression formats.

Enumerator:
Default 

Data is used as provided (for instance 'tga' is not compressed, 'dds' may be compressed)

DXT1 

DXT1 compression (known as BC1 in DirectX 10, RGB compression: 8:1, 8 bytes per block)

DXT3 

DXT3 compression (known as BC2 in DirectX 10, RGBA compression: 4:1, 16 bytes per block)

DXT5 

DXT5 compression (known as BC3 in DirectX 10, RGBA compression: 4:1, 16 bytes per block)

DXT5_xGxR 

Swizzled DXT5 (same as above!) format for normal map compression (red stored in alpha, blue unused)

LATC1 

1 component texture compression (also known as 3DC+/ATI1N, known as BC4 in DirectX 10, 8 bytes per block)

LATC2 

2 component texture compression (luminance & alpha compression 4:1 -> normal map compression, also known as 3DC/ATI2N, known as BC5 in DirectX 10, 16 bytes per block)

LATC2_XYSwizzle 

Alternate XY swizzle LATC2 (same as above!) format for normal map compression (texture can be used just like DXT5_xGxR)

None 

No compression is used


Constructor & Destructor Documentation

virtual PLRENDERER_API PLRenderer::Texture::~Texture ( ) [virtual]

Destructor.

PLRenderer::Texture::Texture ( TextureManager cManager,
const PLCore::String sName 
) [protected]

Constructor.

Parameters:
[in]cManagerTexture manager using this resource
[in]sNameResource name to set

Member Function Documentation

Returns the texture manager this texture is in.

Returns:
The texture manager this texture is in

Returns the texture buffer.

Returns:
The texture buffer, there you can e.g. upload other texture data, can be a null pointer
PLRENDERER_API void PLRenderer::Texture::SetTextureBuffer ( TextureBuffer pTextureBuffer = nullptr)

Sets the texture buffer.

Parameters:
[in]pTextureBufferTexture buffer to set, can be a null pointer

Returns the texture compression hint.

Returns:
The texture compression hint
Remarks:
The texture compression hint JUST indicates the format or it's special usage. It must not match the real internal format of the used renderer texture.

Sets the texture compression hint.

Parameters:
[in]nFormatThe texture compression hint
See also:

Returns the original texture size.

Returns:
The original texture size
Remarks:
If a texture dimension can't be used by the GPU, the texture is scaled automatically during loading. Use the 'GetOriginalSize()'-function to request the original texture dimension. Use GetResource() to get the internal renderer texture where you can request more information about the texture on the GPU.
PLRENDERER_API bool PLRenderer::Texture::Bind ( PLCore::uint32  nStage = 0) const

Makes the texture to the current renderer texture.

Parameters:
[in]nStageWhich texture stage?
Returns:
'true' if all went fine, else 'false'
virtual PLRENDERER_API bool PLRenderer::Texture::IsAnimated ( ) const [virtual]

Returns whether or not this texture is animated.

Returns:
'true' if this texture is animated, else 'false'
Remarks:
If this is an animated texture (tani filename extension) you can cast to 'TextureAni' to get the texture animation data.

Reimplemented in PLRenderer::TextureAni.

PLCore::uint32 PLRenderer::Texture::GetCorrectTextureSize ( PLCore::uint32  nSize,
PLCore::uint32  nMinSize,
PLCore::uint32  nMaxSize,
bool  bRectangle 
) const [protected]

Returns a correct texture size.

Parameters:
[in]nSizeSize to correct
[in]nMinSizeMinimum valid size
[in]nMaxSizeMaximum valid size
[in]bRectangleIs this a rectangle texture?
Returns:
The correct texture size

Destroys the used texture buffer.

virtual PLRENDERER_API bool PLRenderer::Texture::LoadByFilename ( const PLCore::String sFilename,
const PLCore::String sParams = "",
const PLCore::String sMethod = "" 
) [override, virtual]

Loads the loadable from a file given by filename.

Parameters:
[in]sFilenameLoadable filename
[in]sParamsOptional load method parameters, can be an empty string
[in]sMethodOptional name of the load method to use, can be an empty string
Returns:
'true' if all went fine, else 'false'
Note:
  • If no method name was provided, 'Load' if sParams is empty, or 'LoadParams' if sParams is not empty is used automatically

Reimplemented from PLCore::Loadable.

Reimplemented in PLRenderer::TextureAni.

virtual PLRENDERER_API bool PLRenderer::Texture::SaveByFilename ( const PLCore::String sFilename,
const PLCore::String sParams = "",
const PLCore::String sMethod = "" 
) [override, virtual]

Saves the loadable to a file given by filename.

Parameters:
[in]sFilenameLoadable filename
[in]sParamsOptional save method parameters, can be an empty string
[in]sMethodOptional name of the save method to use, can be an empty string
Returns:
'true' if all went fine, else 'false'
Note:
  • If no method name was provided, 'Save' if sParams is empty, or 'SaveParams' if sParams is not empty is used automatically

Reimplemented from PLCore::Loadable.

Reimplemented in PLRenderer::TextureAni.

virtual PLRENDERER_API bool PLRenderer::Texture::SaveByFile ( PLCore::File cFile,
const PLCore::String sParams = "",
const PLCore::String sMethod = "" 
) [override, virtual]

Saves the loadable to a file given by reference.

Parameters:
[in]cFileFile to save into, must be opened and writable
[in]sParamsOptional save method parameters, can be an empty string
[in]sMethodOptional name of the save method to use, can be an empty string
Returns:
'true' if all went fine, else 'false'
Note:
  • If no method name was provided, 'Save' if sParams is empty, or 'SaveParams' if sParams is not empty is used automatically

Reimplemented from PLCore::Loadable.

Reimplemented in PLRenderer::TextureAni.

virtual PLRENDERER_API bool PLRenderer::Texture::Unload ( ) [override, virtual]

Unloads the loadable.

Returns:
'true' if all went fine, else 'false'

Reimplemented from PLCore::Loadable.

Reimplemented in PLRenderer::TextureAni.

virtual PLRENDERER_API PLCore::String PLRenderer::Texture::GetLoadableTypeName ( ) const [override, virtual]

Returns the loadable type name.

Returns:
The loadable type name

Reimplemented from PLCore::Loadable.

Reimplemented in PLRenderer::TextureAni.


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


PixelLight PixelLight 0.9.11-R1
Copyright (C) 2002-2012 by The PixelLight Team
Last modified Thu Feb 23 2012 14:09:40
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported