Class TGPUCompressedImage

Unit

Declaration

type TGPUCompressedImage = class(TEncodedImage)

Description

Image compressed using one of the GPU texture compression algorithms.

Hierarchy

Overview

Methods

Public constructor Create(const AWidth, AHeight, ADepth: Cardinal; const ACompression: TTextureCompression);
Public function Size: Cardinal; override;
Public function HasAlpha: boolean; override;
Public function AlphaChannel( const AlphaTolerance: Byte): TAlphaChannel; override;
Public procedure FlipVertical; override;
Public function Decompress: TCastleImage;
Public function MakeCopy: TGPUCompressedImage;
Public function CreateCopy: TEncodedImage; override;

Properties

Public property Compression: TTextureCompression read FCompression;

Description

Methods

Public constructor Create(const AWidth, AHeight, ADepth: Cardinal; const ACompression: TTextureCompression);

This item has no description.

Public function Size: Cardinal; override;

Size of the whole image data inside RawPixels, in bytes.

Public function HasAlpha: boolean; override;

This item has no description. Showing description inherited from TEncodedImage.HasAlpha.

Does an image have an alpha channel.

You may also be interested in the AlphaChannel. AlphaChannel answers always atNone if HasAlpha = false, and always acTest or acBlending if HasAlpha = true. But AlphaChannel may perform longer analysis of pixels (to differ between acTest and acBlending), while this function always executes ultra-fast (as it's constant for each TCastleImage descendant).

Descendants implementors notes: in this class, TCastleImage, this returns False. Override to return True for images with alpha channel.

Public function AlphaChannel( const AlphaTolerance: Byte): TAlphaChannel; override;

This item has no description. Showing description inherited from TEncodedImage.AlphaChannel.

Check does an image have an alpha channel, and if yes analyze alpha channel: is it a single yes-no (only full or none values), or does it have alpha values in between?

This is quite useful for automatic detection how alpha textures should be displayed: for simple yes/no alpha, OpenGL alpha_test is a simple solution. For full range alpha, OpenGL blending should be used. Blending is a little problematic, since it requires special rendering order, since it doesn't cooperate nicely with Z-buffer. That's why we try to detect simple yes/no alpha textures, so that we're able to use simpler alpha test for them.

We return "simple yes/no alpha channel" is all the alpha values (for every pixel) are 0, or 255, or (when AlphaTolerance <> 0) are close to them by AlphaTolerance. So, to be precise, alpha value must be <= AlphaTolerance, or >= 255 - AlphaTolerance. If any alpha value is between [AlphaTolerance + 1, 255 - AlphaTolerance - 1] then we return "full range alpha channel". Note that for AlphaTolerance >= 128, all images are treated as "simple yes/no alpha". Usually, you want to keep AlphaTolerance small.

Descendants implementors notes: in this class, this simply always returns atNone. For descendants that have alpha channel, implement it, honouring AlphaTolerance as described.

Public procedure FlipVertical; override;

Flip compressed image vertically, losslessly.

This works only for S3TC images, and only when their height is 1, 2, 3 or a multiple of 4. Note that this is always satisfied if image height is a power of two (as common for textures). It uses the knowledge of how S3TC compression works to losslessly flip the image, without re-compressing it. The idea is described here [http://users.telenet.be/tfautre/softdev/ddsload/explanation.htm].

Public function Decompress: TCastleImage;

Decompress the image.

This uses DecompressTexture routine. By default, it is assigned only when OpenGL(ES) context is available and can decompress textures with the help of OpenGL(ES).

Exceptions raised
ECannotDecompressTexture
If we cannot decompress the texture, because decompressor is not set or there was some other error within decompressor.
Public function MakeCopy: TGPUCompressedImage;

Create a new image object that has exactly the same class and the same data (size, pixels) as this image.

Public function CreateCopy: TEncodedImage; override;

Create a new image object that has exactly the same class and the same data (size, pixels) as this image.

Equivalent to MakeCopy, but virtual and declared as returning TEncodedImage class.

Properties

Public property Compression: TTextureCompression read FCompression;

This item has no description.


Generated by PasDoc 0.16.0-snapshot.