Cogl 2.0 Reference Manual | ||||
---|---|---|---|---|
Top | Description |
typedef CoglTexture; CoglBool cogl_is_texture (void *object
); #define COGL_TEXTURE_ERROR enum CoglTextureError; CoglBool cogl_texture_allocate (CoglTexture *texture
,CoglError **error
); unsigned int cogl_texture_get_width (CoglTexture *texture
); unsigned int cogl_texture_get_height (CoglTexture *texture
); CoglBool cogl_texture_is_sliced (CoglTexture *texture
); int cogl_texture_get_data (CoglTexture *texture
,CoglPixelFormat format
,unsigned int rowstride
,uint8_t *data
); CoglBool cogl_texture_set_data (CoglTexture *texture
,CoglPixelFormat format
,int rowstride
,const uint8_t *data
,int level
,CoglError **error
); CoglBool cogl_texture_set_region (CoglTexture *texture
,int src_x
,int src_y
,int dst_x
,int dst_y
,unsigned int dst_width
,unsigned int dst_height
,int width
,int height
,CoglPixelFormat format
,unsigned int rowstride
,const uint8_t *data
); enum CoglTextureType; enum CoglTextureComponents; void cogl_texture_set_components (CoglTexture *texture
,CoglTextureComponents components
); CoglTextureComponents cogl_texture_get_components (CoglTexture *texture
); void cogl_texture_set_premultiplied (CoglTexture *texture
,CoglBool premultiplied
); CoglBool cogl_texture_get_premultiplied (CoglTexture *texture
);
Cogl allows creating and manipulating textures using a uniform API that tries to hide all the various complexities of creating, loading and manipulating textures.
CoglBool cogl_is_texture (void *object
);
Gets whether the given object references a texture object.
|
A CoglObject pointer |
Returns : |
TRUE if the object references a texture, and
FALSE otherwise |
#define COGL_TEXTURE_ERROR (cogl_texture_error_quark ())
CoglError domain for texture errors.
Since 1.8
Stability Level: Unstable
typedef enum { COGL_TEXTURE_ERROR_SIZE, COGL_TEXTURE_ERROR_FORMAT, COGL_TEXTURE_ERROR_BAD_PARAMETER, COGL_TEXTURE_ERROR_TYPE } CoglTextureError;
Error codes that can be thrown when allocating textures.
Unsupported size | |
Unsupported format | |
A primitive texture type that is unsupported by the driver was used |
Since 1.8
Stability Level: Unstable
CoglBool cogl_texture_allocate (CoglTexture *texture
,CoglError **error
);
Explicitly allocates the storage for the given texture
which
allows you to be sure that there is enough memory for the
texture and if not then the error can be handled gracefully.
|
A CoglTexture |
|
A CoglError to return exceptional errors or NULL
|
Returns : |
TRUE if the texture was successfully allocated,
otherwise FALSE and error will be updated if it
wasn't NULL . |
unsigned int cogl_texture_get_width (CoglTexture *texture
);
Queries the width of a cogl texture.
|
a CoglTexture pointer. |
Returns : |
the width of the GPU side texture in pixels |
unsigned int cogl_texture_get_height (CoglTexture *texture
);
Queries the height of a cogl texture.
|
a CoglTexture pointer. |
Returns : |
the height of the GPU side texture in pixels |
CoglBool cogl_texture_is_sliced (CoglTexture *texture
);
Queries if a texture is sliced (stored as multiple GPU side tecture objects).
|
a CoglTexture pointer. |
Returns : |
TRUE if the texture is sliced, FALSE if the texture
is stored as a single GPU texture |
int cogl_texture_get_data (CoglTexture *texture
,CoglPixelFormat format
,unsigned int rowstride
,uint8_t *data
);
Copies the pixel data from a cogl texture to system memory.
cogl_texture_get_rowstride()
as the
rowstride
argument, the rowstride should be the rowstride you
want for the destination data
buffer not the rowstride of the
source texture
|
a CoglTexture pointer. |
|
the CoglPixelFormat to store the texture as. |
|
the rowstride of data in bytes or pass 0 to calculate
from the bytes-per-pixel of format multiplied by the
texture width. |
|
memory location to write the texture 's contents, or NULL
to only query the data size through the return value. |
Returns : |
the size of the texture data in bytes |
CoglBool cogl_texture_set_data (CoglTexture *texture
,CoglPixelFormat format
,int rowstride
,const uint8_t *data
,int level
,CoglError **error
);
Sets all the pixels for a given mipmap level
by copying the pixel
data pointed to by the data
argument into the given texture
.
data
should point to the first pixel to copy corresponding
to the top left of the mipmap level
being set.
If rowstride
equals 0 then it will be automatically calculated
from the width of the mipmap level and the bytes-per-pixel for the
given format
.
A mipmap level
of 0 corresponds to the largest, base image of a
texture and level
1 is half the width and height of level 0. If
dividing any dimension of the previous level by two results in a
fraction then round the number down (floor()
), but clamp to 1
something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
You can determine the number of mipmap levels for a given texture like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Where max_dimension
is the larger of cogl_texture_get_width()
and
cogl_texture_get_height()
.
It is an error to pass a level
number >= the number of levels that
texture
can have according to the above calculation.
texture
has not previously been allocated then this
api can return FALSE
and throw an exceptional error
if there is
not enough memory to allocate storage for texture
.
|
the CoglPixelFormat used in the source data buffer. |
|
rowstride of the source data buffer (computed from
the texture width and format if it equals 0) |
|
the source data, pointing to the first top-left pixel to set |
|
The mipmap level to update (Normally 0 for the largest, base texture) |
|
A CoglError to return exceptional errors |
Returns : |
TRUE if the data upload was successful, and
FALSE otherwise |
CoglBool cogl_texture_set_region (CoglTexture *texture
,int src_x
,int src_y
,int dst_x
,int dst_y
,unsigned int dst_width
,unsigned int dst_height
,int width
,int height
,CoglPixelFormat format
,unsigned int rowstride
,const uint8_t *data
);
Sets the pixels in a rectangular subregion of texture
from an in-memory
buffer containing pixel data.
data
|
a CoglTexture. |
|
upper left coordinate to use from source data. |
|
upper left coordinate to use from source data. |
|
upper left destination horizontal coordinate. |
|
upper left destination vertical coordinate. |
|
width of destination region to write. (Must be less
than or equal to width ) |
|
height of destination region to write. (Must be less
than or equal to height ) |
|
width of source data buffer. |
|
height of source data buffer. |
|
the CoglPixelFormat used in the source buffer. |
|
rowstride of source buffer (computed from width if none specified) |
|
the actual pixel data. |
Returns : |
TRUE if the subregion upload was successful, and
FALSE otherwise |
typedef enum { COGL_TEXTURE_TYPE_2D, COGL_TEXTURE_TYPE_3D, COGL_TEXTURE_TYPE_RECTANGLE } CoglTextureType;
Constants representing the underlying hardware texture type of a CoglTexture.
Since 1.10
Stability Level: Unstable
typedef enum { COGL_TEXTURE_COMPONENTS_A = 1, COGL_TEXTURE_COMPONENTS_RG, COGL_TEXTURE_COMPONENTS_RGB, COGL_TEXTURE_COMPONENTS_RGBA, COGL_TEXTURE_COMPONENTS_DEPTH } CoglTextureComponents;
See cogl_texture_set_components()
.
Only the alpha component | |
Red and green components. Note that
this can only be used if the COGL_FEATURE_ID_TEXTURE_RG feature
is advertised.
|
|
Red, green and blue components | |
Red, green, blue and alpha components | |
Only a depth component |
Since 1.18
void cogl_texture_set_components (CoglTexture *texture
,CoglTextureComponents components
);
Affects the internal storage format for this texture by specifying what components will be required for sampling later.
This api affects how data is uploaded to the GPU since unused components can potentially be discarded from source data.
For textures created by the ‘_with_size’ constructors the default
is COGL_TEXTURE_COMPONENTS_RGBA
. The other constructors which take
a CoglBitmap
or a data pointer default to the same components as
the pixel format of the data.
Note that the COGL_TEXTURE_COMPONENTS_RG
format is not available
on all drivers. The availability can be determined by checking for
the COGL_FEATURE_ID_TEXTURE_RG
feature. If this format is used on
a driver where it is not available then COGL_TEXTURE_ERROR_FORMAT
will be raised when the texture is allocated. Even if the feature
is not available then COGL_PIXEL_FORMAT_RG_88
can still be used as
an image format as long as COGL_TEXTURE_COMPONENTS_RG
isn't used
as the texture's components.
|
a CoglTexture pointer. |
Since 1.18
CoglTextureComponents cogl_texture_get_components (CoglTexture *texture
);
Queries what components the given texture
stores internally as set
via cogl_texture_set_components()
.
For textures created by the ‘_with_size’ constructors the default
is COGL_TEXTURE_COMPONENTS_RGBA
. The other constructors which take
a CoglBitmap
or a data pointer default to the same components as
the pixel format of the data.
|
a CoglTexture pointer. |
Since 1.18
void cogl_texture_set_premultiplied (CoglTexture *texture
,CoglBool premultiplied
);
Affects the internal storage format for this texture by specifying whether red, green and blue color components should be stored as pre-multiplied alpha values.
This api affects how data is uploaded to the GPU since Cogl will convert source data to have premultiplied or unpremultiplied components according to this state.
For example if you create a texture via
cogl_texture_2d_new_with_size()
and then upload data via
cogl_texture_set_data()
passing a source format of
COGL_PIXEL_FORMAT_RGBA_8888
then Cogl will internally multiply the
red, green and blue components of the source data by the alpha
component, for each pixel so that the internally stored data has
pre-multiplied alpha components. If you instead upload data that
already has pre-multiplied components by passing
COGL_PIXEL_FORMAT_RGBA_8888_PRE
as the source format to
cogl_texture_set_data()
then the data can be uploaded without being
converted.
By default the premultipled
state is TRUE
.
|
a CoglTexture pointer. |
|
Whether any internally stored red, green or blue components are pre-multiplied by an alpha component. |
Since 1.18
CoglBool cogl_texture_get_premultiplied (CoglTexture *texture
);
Queries the pre-multiplied alpha status for internally stored red,
green and blue components for the given texture
as set by
cogl_texture_set_premultiplied()
.
By default the pre-multipled state is TRUE
.
|
a CoglTexture pointer. |
Returns : |
TRUE if red, green and blue components are
internally stored pre-multiplied by the alpha
value or FALSE if not. |
Since 1.18