Sliced Textures

Sliced Textures — Functions for creating and manipulating 2D meta textures that may internally be comprised of multiple 2D textures with power-of-two sizes.

Synopsis

                    CoglTexture2DSliced;
CoglTexture2DSliced * cogl_texture_2d_sliced_new_with_size
                                                        (CoglContext *ctx,
                                                         int width,
                                                         int height,
                                                         int max_waste,
                                                         CoglPixelFormat internal_format);
CoglBool            cogl_is_texture_2d_sliced           (void *object);

Description

These functions allow high-level meta textures (See the CoglMetaTexture interface) to be allocated that may internally be comprised of multiple 2D texture "slices" with power-of-two sizes.

This API can be useful when working with GPUs that don't have native support for non-power-of-two textures or if you want to load a texture that is larger than the GPUs maximum texture size limits.

The algorithm for slicing works by first trying to map a virtual size to the next larger power-of-two size and then seeing how many wasted pixels that would result in. For example if you have a virtual texture that's 259 texels wide, the next pot size = 512 and the amount of waste would be 253 texels. If the amount of waste is above a max-waste threshold then we would next slice that texture into one that's 256 texels and then looking at how many more texels remain unallocated after that we choose the next power-of-two size. For the example of a 259 texel image that would mean having a 256 texel wide texture, leaving 3 texels unallocated so we'd then create a 4 texel wide texture - now there is only one texel of waste. The algorithm continues to slice the right most textures until the amount of waste is less than or equal to a specfied max-waste threshold. The same logic for slicing from left to right is also applied from top to bottom.

Details

CoglTexture2DSliced

typedef struct _CoglTexture2DSliced CoglTexture2DSliced;

cogl_texture_2d_sliced_new_with_size ()

CoglTexture2DSliced * cogl_texture_2d_sliced_new_with_size
                                                        (CoglContext *ctx,
                                                         int width,
                                                         int height,
                                                         int max_waste,
                                                         CoglPixelFormat internal_format);

Creates a CoglTexture2DSliced that may internally be comprised of 1 or more CoglTexture2D textures depending on GPU limitations. For example if the GPU only supports power-of-two sized textures then a sliced texture will turn a non-power-of-two size into a combination of smaller power-of-two sized textures. If the requested texture size is larger than is supported by the hardware then the texture will be sliced into smaller textures that can be accessed by the hardware.

max_waste is used as a threshold for recursively slicing the right-most or bottom-most slices into smaller sizes until the wasted padding at the bottom and right of the textures is less than specified. A negative max_waste will disable slicing.

The storage for the texture is not allocated before this function returns. You can call cogl_texture_allocate() to explicitly allocate the underlying storage or let Cogl automatically allocate storage lazily.

Note

It's possible for the allocation of a sliced texture to fail later due to impossible slicing constraints if a negative max_waste value is given. If the given virtual texture size size is larger than is supported by the hardware but slicing is disabled the texture size would be too large to handle.

ctx :

A CoglContext

width :

The virtual width of your sliced texture.

height :

The virtual height of your sliced texture.

max_waste :

The threshold of how wide a strip of wasted texels are allowed along the right and bottom textures before they must be sliced to reduce the amount of waste. A negative can be passed to disable slicing.

internal_format :

The format of the texture

Returns :

A new CoglTexture2DSliced object with no storage allocated yet.

Since 1.10

Stability Level: Unstable


cogl_is_texture_2d_sliced ()

CoglBool            cogl_is_texture_2d_sliced           (void *object);

Gets whether the given object references a CoglTexture2DSliced.

object :

A CoglObject pointer

Returns :

TRUE if the object references a CoglTexture2DSliced and FALSE otherwise.

Since 1.10

Stability Level: Unstable