1
0
Fork 0

remove internal_format and redundant error arguments

Texture allocation is now consistently handled lazily such that the
internal format can now be controlled using
cogl_texture_set_components() and cogl_texture_set_premultiplied()
before allocating the texture with cogl_texture_allocate(). This means
that the internal_format arguments to texture constructors are now
redundant and since most of the texture constructors now can't ever fail
the error arguments are also redundant. This now means we no longer
use CoglPixelFormat in the public api for describing the internal format
of textures which had been bad solution originally due to how specific
CoglPixelFormat is which is missleading when we don't support such
explicit control over the internal format.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 99a53c82e9ab0a1e5ee35941bf83dc334b1fbe87)

Note: there are numerous API changes for functions currently marked
as 'unstable' which we don't think are in use by anyone depending on
a stable 1.x api. Compared to the original patch though this avoids
changing the cogl_texture_rectangle_new_with_size() api which we know
is used by Mutter.
This commit is contained in:
Robert Bragg 2013-07-02 01:48:54 +01:00
parent cbd6951134
commit af7398788a
62 changed files with 412 additions and 584 deletions

View file

@ -470,10 +470,8 @@ video_texture_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data, const uint8_t *data)
CoglError **error)
{ {
CoglBitmap *bitmap; CoglBitmap *bitmap;
CoglTexture *tex; CoglTexture *tex;
@ -489,9 +487,7 @@ video_texture_new_from_data (CoglContext *ctx,
is_pot (cogl_bitmap_get_height (bitmap))) || is_pot (cogl_bitmap_get_height (bitmap))) ||
cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC)) cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC))
{ {
tex = cogl_texture_2d_new_from_bitmap (bitmap, tex = cogl_texture_2d_new_from_bitmap (bitmap);
internal_format,
&internal_error);
if (!tex) if (!tex)
{ {
cogl_error_free (internal_error); cogl_error_free (internal_error);
@ -504,12 +500,8 @@ video_texture_new_from_data (CoglContext *ctx,
if (!tex) if (!tex)
{ {
/* Otherwise create a sliced texture */ /* Otherwise create a sliced texture */
CoglTexture2DSliced *tex_2ds = tex = cogl_texture_2d_sliced_new_from_bitmap (bitmap,
cogl_texture_2d_sliced_new_from_bitmap (bitmap, -1); /* no maximum waste */
-1, /* no maximum waste */
internal_format,
error);
tex = tex_2ds;
} }
cogl_object_unref (bitmap); cogl_object_unref (bitmap);
@ -537,9 +529,9 @@ cogl_gst_rgb24_upload (CoglGstVideoSink *sink,
priv->frame[0] = video_texture_new_from_data (priv->ctx, priv->info.width, priv->frame[0] = video_texture_new_from_data (priv->ctx, priv->info.width,
priv->info.height, priv->info.height,
format, format, format,
priv->info.stride[0], priv->info.stride[0],
frame.data[0], NULL); frame.data[0]);
gst_video_frame_unmap (&frame); gst_video_frame_unmap (&frame);
@ -583,9 +575,9 @@ cogl_gst_rgb32_upload (CoglGstVideoSink *sink,
priv->frame[0] = video_texture_new_from_data (priv->ctx, priv->info.width, priv->frame[0] = video_texture_new_from_data (priv->ctx, priv->info.width,
priv->info.height, priv->info.height,
format, format, format,
priv->info.stride[0], priv->info.stride[0],
frame.data[0], NULL); frame.data[0]);
gst_video_frame_unmap (&frame); gst_video_frame_unmap (&frame);
@ -626,22 +618,22 @@ cogl_gst_yv12_upload (CoglGstVideoSink *sink,
video_texture_new_from_data (priv->ctx, video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 0), GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 0),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 0), GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 0),
format, format, format,
priv->info.stride[0], frame.data[0], NULL); priv->info.stride[0], frame.data[0]);
priv->frame[2] = priv->frame[2] =
video_texture_new_from_data (priv->ctx, video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 1), GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 1),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 1), GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 1),
format, format, format,
priv->info.stride[1], frame.data[1], NULL); priv->info.stride[1], frame.data[1]);
priv->frame[1] = priv->frame[1] =
video_texture_new_from_data (priv->ctx, video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 2), GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 2),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 2), GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 2),
format, format, format,
priv->info.stride[2], frame.data[2], NULL); priv->info.stride[2], frame.data[2]);
gst_video_frame_unmap (&frame); gst_video_frame_unmap (&frame);
@ -671,22 +663,22 @@ cogl_gst_i420_upload (CoglGstVideoSink *sink,
video_texture_new_from_data (priv->ctx, video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 0), GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 0),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 0), GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 0),
format, format, format,
priv->info.stride[0], frame.data[0], NULL); priv->info.stride[0], frame.data[0]);
priv->frame[1] = priv->frame[1] =
video_texture_new_from_data (priv->ctx, video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 1), GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 1),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 1), GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 1),
format, format, format,
priv->info.stride[1], frame.data[1], NULL); priv->info.stride[1], frame.data[1]);
priv->frame[2] = priv->frame[2] =
video_texture_new_from_data (priv->ctx, video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 2), GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 2),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 2), GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 2),
format, format, format,
priv->info.stride[2], frame.data[2], NULL); priv->info.stride[2], frame.data[2]);
gst_video_frame_unmap (&frame); gst_video_frame_unmap (&frame);
@ -814,9 +806,9 @@ cogl_gst_ayuv_upload (CoglGstVideoSink *sink,
priv->frame[0] = video_texture_new_from_data (priv->ctx, priv->info.width, priv->frame[0] = video_texture_new_from_data (priv->ctx, priv->info.width,
priv->info.height, priv->info.height,
format, format, format,
priv->info.stride[0], priv->info.stride[0],
frame.data[0], NULL); frame.data[0]);
gst_video_frame_unmap (&frame); gst_video_frame_unmap (&frame);

View file

@ -226,11 +226,8 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
texture = cogl_atlas_texture_new_with_size (cache->ctx, texture = cogl_atlas_texture_new_with_size (cache->ctx,
value->draw_width, value->draw_width,
value->draw_height, value->draw_height);
COGL_PIXEL_FORMAT_RGBA_8888_PRE, if (!cogl_texture_allocate (COGL_TEXTURE (texture), &ignore_error))
&ignore_error);
if (texture == NULL)
{ {
cogl_error_free (ignore_error); cogl_error_free (ignore_error);
return FALSE; return FALSE;

View file

@ -56,9 +56,7 @@ struct _CoglAtlasTexture
CoglAtlasTexture * CoglAtlasTexture *
_cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp, _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format, CoglBool can_convert_in_place);
CoglBool can_convert_in_place,
CoglError **error);
void void
_cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx, _cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx,

View file

@ -681,9 +681,7 @@ _cogl_atlas_texture_create_base (CoglContext *ctx,
CoglAtlasTexture * CoglAtlasTexture *
cogl_atlas_texture_new_with_size (CoglContext *ctx, cogl_atlas_texture_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height)
CoglPixelFormat internal_format,
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
@ -697,7 +695,8 @@ cogl_atlas_texture_new_with_size (CoglContext *ctx,
loader->src.sized.height = height; loader->src.sized.height = height;
return _cogl_atlas_texture_create_base (ctx, width, height, return _cogl_atlas_texture_create_base (ctx, width, height,
internal_format, loader); COGL_PIXEL_FORMAT_RGBA_8888_PRE,
loader);
} }
static CoglBool static CoglBool
@ -886,9 +885,7 @@ _cogl_atlas_texture_allocate (CoglTexture *tex,
CoglAtlasTexture * CoglAtlasTexture *
_cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp, _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format, CoglBool can_convert_in_place)
CoglBool can_convert_in_place,
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
@ -902,17 +899,14 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
return _cogl_atlas_texture_create_base (_cogl_bitmap_get_context (bmp), return _cogl_atlas_texture_create_base (_cogl_bitmap_get_context (bmp),
cogl_bitmap_get_width (bmp), cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp), cogl_bitmap_get_height (bmp),
internal_format, cogl_bitmap_get_format (bmp),
loader); loader);
} }
CoglAtlasTexture * CoglAtlasTexture *
cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp, cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp)
CoglPixelFormat internal_format,
CoglError **error)
{ {
return _cogl_atlas_texture_new_from_bitmap (bmp, internal_format, return _cogl_atlas_texture_new_from_bitmap (bmp, FALSE);
FALSE, error);
} }
CoglAtlasTexture * CoglAtlasTexture *
@ -920,7 +914,6 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data, const uint8_t *data,
CoglError **error) CoglError **error)
@ -942,7 +935,7 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
rowstride, rowstride,
(uint8_t *) data); (uint8_t *) data);
atlas_tex = cogl_atlas_texture_new_from_bitmap (bmp, internal_format, error); atlas_tex = cogl_atlas_texture_new_from_bitmap (bmp);
cogl_object_unref (bmp); cogl_object_unref (bmp);
@ -959,7 +952,6 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
CoglAtlasTexture * CoglAtlasTexture *
cogl_atlas_texture_new_from_file (CoglContext *ctx, cogl_atlas_texture_new_from_file (CoglContext *ctx,
const char *filename, const char *filename,
CoglPixelFormat internal_format,
CoglError **error) CoglError **error)
{ {
CoglBitmap *bmp; CoglBitmap *bmp;
@ -972,9 +964,7 @@ cogl_atlas_texture_new_from_file (CoglContext *ctx,
return NULL; return NULL;
atlas_tex = _cogl_atlas_texture_new_from_bitmap (bmp, atlas_tex = _cogl_atlas_texture_new_from_bitmap (bmp,
internal_format, TRUE); /* convert in-place */
TRUE, /* convert in-place */
error);
cogl_object_unref (bmp); cogl_object_unref (bmp);

View file

@ -67,7 +67,6 @@ typedef struct _CoglAtlasTexture CoglAtlasTexture;
* @ctx: A #CoglContext * @ctx: A #CoglContext
* @width: The width of your atlased texture. * @width: The width of your atlased texture.
* @height: The height of your atlased texture. * @height: The height of your atlased texture.
* @internal_format: The format of the texture
* *
* Creates a #CoglAtlasTexture with a given @width and @height. A * Creates a #CoglAtlasTexture with a given @width and @height. A
* #CoglAtlasTexture represents a sub-region within one of Cogl's * #CoglAtlasTexture represents a sub-region within one of Cogl's
@ -83,32 +82,28 @@ typedef struct _CoglAtlasTexture CoglAtlasTexture;
* using cogl_texture_set_components() and * using cogl_texture_set_components() and
* cogl_texture_set_premultiplied(). * cogl_texture_set_premultiplied().
* *
* <note>This call can fail if Cogl considers the given * <note>Allocate call can fail if Cogl considers the internal
* @internal_format incompatible with the format of its internal * format to be incompatible with the format of its internal
* atlases.</note> * atlases.</note>
* *
* <note>The returned #CoglAtlasTexture is a high-level meta-texture * <note>The returned #CoglAtlasTexture is a high-level meta-texture
* with some limitations. See the documentation for #CoglMetaTexture * with some limitations. See the documentation for #CoglMetaTexture
* for more details.</note> * for more details.</note>
* *
* Return value: (transfer full): A new #CoglAtlasTexture object with * Returns: (transfer full): A new #CoglAtlasTexture object.
* no storage allocated yet or %NULL on failure and @error
* will be updated.
* Since: 1.16 * Since: 1.16
* Stability: unstable * Stability: unstable
*/ */
CoglAtlasTexture * CoglAtlasTexture *
cogl_atlas_texture_new_with_size (CoglContext *ctx, cogl_atlas_texture_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height);
CoglPixelFormat internal_format,
CoglError **error);
/** /**
* cogl_atlas_texture_new_from_file: * cogl_atlas_texture_new_from_file:
* @ctx: A #CoglContext * @ctx: A #CoglContext
* @filename: the file to load * @filename: the file to load
* @internal_format: The format of the texture * @error: A #CoglError to catch exceptional errors or %NULL
* *
* Creates a #CoglAtlasTexture from an image file. A #CoglAtlasTexture * Creates a #CoglAtlasTexture from an image file. A #CoglAtlasTexture
* represents a sub-region within one of Cogl's shared texture * represents a sub-region within one of Cogl's shared texture
@ -124,8 +119,8 @@ cogl_atlas_texture_new_with_size (CoglContext *ctx,
* using cogl_texture_set_components() and * using cogl_texture_set_components() and
* cogl_texture_set_premultiplied(). * cogl_texture_set_premultiplied().
* *
* <note>Allocation can fail later if Cogl considers the given * <note>Allocate call can fail if Cogl considers the internal
* @internal_format incompatible with the format of its internal * format to be incompatible with the format of its internal
* atlases.</note> * atlases.</note>
* *
* <note>The returned #CoglAtlasTexture is a high-level meta-texture * <note>The returned #CoglAtlasTexture is a high-level meta-texture
@ -140,7 +135,6 @@ cogl_atlas_texture_new_with_size (CoglContext *ctx,
CoglAtlasTexture * CoglAtlasTexture *
cogl_atlas_texture_new_from_file (CoglContext *ctx, cogl_atlas_texture_new_from_file (CoglContext *ctx,
const char *filename, const char *filename,
CoglPixelFormat internal_format,
CoglError **error); CoglError **error);
/** /**
@ -149,14 +143,6 @@ cogl_atlas_texture_new_from_file (CoglContext *ctx,
* @width: width of texture in pixels * @width: width of texture in pixels
* @height: height of texture in pixels * @height: height of texture in pixels
* @format: the #CoglPixelFormat the buffer is stored in in RAM * @format: the #CoglPixelFormat the buffer is stored in in RAM
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. If %COGL_PIXEL_FORMAT_ANY is given then a premultiplied
* format similar to the format of the source data will be used. The
* default blending equations of Cogl expect premultiplied color data;
* the main use of passing a non-premultiplied format here is if you
* have non-premultiplied source data and are going to adjust the blend
* mode (see cogl_material_set_blend()) or use the data for something
* other than straight blending.
* @rowstride: the memory offset in bytes between the start of each * @rowstride: the memory offset in bytes between the start of each
* row in @data. A value of 0 will make Cogl automatically * row in @data. A value of 0 will make Cogl automatically
* calculate @rowstride from @width and @format. * calculate @rowstride from @width and @format.
@ -178,8 +164,8 @@ cogl_atlas_texture_new_from_file (CoglContext *ctx,
* cogl_atlas_texture_new_with_size() and then upload data using * cogl_atlas_texture_new_with_size() and then upload data using
* cogl_texture_set_data()</note> * cogl_texture_set_data()</note>
* *
* <note>Allocation can fail if Cogl considers the given * <note>Allocate call can fail if Cogl considers the internal
* @internal_format incompatible with the format of its internal * format to be incompatible with the format of its internal
* atlases.</note> * atlases.</note>
* *
* <note>The returned #CoglAtlasTexture is a high-level * <note>The returned #CoglAtlasTexture is a high-level
@ -196,23 +182,13 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data, const uint8_t *data,
CoglError **error); CoglError **error);
/** /**
* cogl_atlas_texture_new_from_bitmap: * cogl_atlas_texture_new_from_bitmap:
* @bmp: A #CoglBitmap * @bitmap: A #CoglBitmap
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. If %COGL_PIXEL_FORMAT_ANY is given then a premultiplied
* format similar to the format of the source data will be used. The
* default blending equations of Cogl expect premultiplied color data;
* the main use of passing a non-premultiplied format here is if you
* have non-premultiplied source data and are going to adjust the blend
* mode (see cogl_material_set_blend()) or use the data for something
* other than straight blending.
* @error: A #CoglError to catch exceptional errors or %NULL
* *
* Creates a new #CoglAtlasTexture texture based on data residing in a * Creates a new #CoglAtlasTexture texture based on data residing in a
* @bitmap. A #CoglAtlasTexture represents a sub-region within one of * @bitmap. A #CoglAtlasTexture represents a sub-region within one of
@ -229,23 +205,20 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
* using cogl_texture_set_components() and * using cogl_texture_set_components() and
* cogl_texture_set_premultiplied(). * cogl_texture_set_premultiplied().
* *
* <note>Allocation can fail if Cogl considers the given * <note>Allocate call can fail if Cogl considers the internal
* @internal_format incompatible with the format of its internal * format to be incompatible with the format of its internal
* atlases.</note> * atlases.</note>
* *
* <note>The returned #CoglAtlasTexture is a high-level meta-texture * <note>The returned #CoglAtlasTexture is a high-level meta-texture
* with some limitations. See the documentation for #CoglMetaTexture * with some limitations. See the documentation for #CoglMetaTexture
* for more details.</note> * for more details.</note>
* *
* Return value: (transfer full): A new #CoglAtlasTexture object or * Returns: (transfer full): A new #CoglAtlasTexture object.
* %NULL on failure and @error will be updated.
* Since: 1.16 * Since: 1.16
* Stability: unstable * Stability: unstable
*/ */
CoglAtlasTexture * CoglAtlasTexture *
cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp, cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp);
CoglPixelFormat internal_format,
CoglError **error);
/** /**
* cogl_is_atlas_texture: * cogl_is_atlas_texture:

View file

@ -299,11 +299,17 @@ _cogl_atlas_create_texture (CoglAtlas *atlas,
width * bpp, width * bpp,
clear_data); clear_data);
tex = cogl_texture_2d_new_from_bitmap (clear_bmp, tex = cogl_texture_2d_new_from_bitmap (clear_bmp);
atlas->texture_format,
&ignore_error); _cogl_texture_set_internal_format (COGL_TEXTURE (tex),
if (!tex) atlas->texture_format);
cogl_error_free (ignore_error);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), &ignore_error))
{
cogl_error_free (ignore_error);
cogl_object_unref (tex);
tex = NULL;
}
cogl_object_unref (clear_bmp); cogl_object_unref (clear_bmp);
@ -311,9 +317,11 @@ _cogl_atlas_create_texture (CoglAtlas *atlas,
} }
else else
{ {
tex = cogl_texture_2d_new_with_size (ctx, tex = cogl_texture_2d_new_with_size (ctx, width, height);
width, height,
atlas->texture_format); _cogl_texture_set_internal_format (COGL_TEXTURE (tex),
atlas->texture_format);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), &ignore_error)) if (!cogl_texture_allocate (COGL_TEXTURE (tex), &ignore_error))
{ {
cogl_error_free (ignore_error); cogl_error_free (ignore_error);
@ -557,8 +565,9 @@ create_migration_texture (CoglContext *ctx,
{ {
/* First try creating a fast-path non-sliced texture */ /* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
width, height, width, height));
internal_format));
_cogl_texture_set_internal_format (tex, internal_format);
/* TODO: instead of allocating storage here it would be better /* TODO: instead of allocating storage here it would be better
* if we had some api that let us just check that the size is * if we had some api that let us just check that the size is
@ -580,8 +589,11 @@ create_migration_texture (CoglContext *ctx,
cogl_texture_2d_sliced_new_with_size (ctx, cogl_texture_2d_sliced_new_with_size (ctx,
width, width,
height, height,
COGL_TEXTURE_MAX_WASTE, COGL_TEXTURE_MAX_WASTE);
internal_format);
_cogl_texture_set_internal_format (COGL_TEXTURE (tex_2ds),
internal_format);
tex = COGL_TEXTURE (tex_2ds); tex = COGL_TEXTURE (tex_2ds);
} }
@ -594,7 +606,7 @@ _cogl_atlas_copy_rectangle (CoglAtlas *atlas,
int y, int y,
int width, int width,
int height, int height,
CoglPixelFormat format) CoglPixelFormat internal_format)
{ {
CoglTexture *tex; CoglTexture *tex;
CoglBlitData blit_data; CoglBlitData blit_data;
@ -603,7 +615,7 @@ _cogl_atlas_copy_rectangle (CoglAtlas *atlas,
_COGL_GET_CONTEXT (ctx, NULL); _COGL_GET_CONTEXT (ctx, NULL);
/* Create a new texture at the right size */ /* Create a new texture at the right size */
tex = create_migration_texture (ctx, width, height, format); tex = create_migration_texture (ctx, width, height, internal_format);
if (!cogl_texture_allocate (tex, &ignore_error)) if (!cogl_texture_allocate (tex, &ignore_error))
{ {
cogl_error_free (ignore_error); cogl_error_free (ignore_error);

View file

@ -434,7 +434,6 @@ cogl_context_new (CoglDisplay *display,
cogl_texture_2d_new_from_data (context, cogl_texture_2d_new_from_data (context,
1, 1, 1, 1,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
0, /* rowstride */ 0, /* rowstride */
white_pixel, white_pixel,
NULL); /* abort on error */ NULL); /* abort on error */
@ -446,7 +445,6 @@ cogl_context_new (CoglDisplay *display,
cogl_texture_3d_new_from_data (context, cogl_texture_3d_new_from_data (context,
1, 1, 1, /* width, height, depth */ 1, 1, 1, /* width, height, depth */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
0, /* rowstride */ 0, /* rowstride */
0, /* image stride */ 0, /* image stride */
white_pixel, white_pixel,
@ -464,9 +462,7 @@ cogl_context_new (CoglDisplay *display,
internal_error = NULL; internal_error = NULL;
context->default_gl_texture_rect_tex = context->default_gl_texture_rect_tex =
cogl_texture_rectangle_new_from_bitmap (white_pixel_bitmap, cogl_texture_rectangle_new_from_bitmap (white_pixel_bitmap);
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
NULL); /* legacy error argument */
/* XXX: we need to allocate the texture now because the white_pixel /* XXX: we need to allocate the texture now because the white_pixel
* data is on the stack */ * data is on the stack */

View file

@ -320,8 +320,7 @@ copy_flipped_texture (CoglGLES2Context *gles2_ctx,
tex_id, tex_id,
tex_object_data->width, tex_object_data->width,
tex_object_data->height, tex_object_data->height,
internal_format, internal_format);
NULL /* error */);
if (dst_texture) if (dst_texture)
{ {
@ -1941,15 +1940,13 @@ cogl_gles2_texture_2d_new_from_handle (CoglContext *ctx,
unsigned int handle, unsigned int handle,
int width, int width,
int height, int height,
CoglPixelFormat internal_format, CoglPixelFormat format)
CoglError **error)
{ {
return cogl_texture_2d_new_from_foreign (ctx, return cogl_texture_2d_gl_new_from_foreign (ctx,
handle, handle,
width, width,
height, height,
internal_format, format);
error);
} }
CoglBool CoglBool

View file

@ -301,8 +301,7 @@ cogl_gles2_get_current_vtable (void);
* glGenTextures() * glGenTextures()
* @width: Width of the texture to allocate * @width: Width of the texture to allocate
* @height: Height of the texture to allocate * @height: Height of the texture to allocate
* @internal_format: The format of the texture * @format: The format of the texture
* @error: A #CoglError for exceptions
* *
* Creates a #CoglTexture2D from an OpenGL ES 2.0 texture handle that * Creates a #CoglTexture2D from an OpenGL ES 2.0 texture handle that
* was created within the given @gles2_ctx via glGenTextures(). The * was created within the given @gles2_ctx via glGenTextures(). The
@ -326,8 +325,7 @@ cogl_gles2_texture_2d_new_from_handle (CoglContext *ctx,
unsigned int handle, unsigned int handle,
int width, int width,
int height, int height,
CoglPixelFormat internal_format, CoglPixelFormat format);
CoglError **error);
/** /**
* cogl_gles2_texture_get_handle: * cogl_gles2_texture_get_handle:

View file

@ -37,13 +37,12 @@
COGL_BEGIN_DECLS COGL_BEGIN_DECLS
/** /**
* cogl_texture_2d_new_from_foreign: * cogl_texture_2d_gl_new_from_foreign:
* @ctx: A #CoglContext * @ctx: A #CoglContext
* @gl_handle: A GL handle for a GL_TEXTURE_2D texture object * @gl_handle: A GL handle for a GL_TEXTURE_2D texture object
* @width: Width of the foreign GL texture * @width: Width of the foreign GL texture
* @height: Height of the foreign GL texture * @height: Height of the foreign GL texture
* @format: The format of the texture * @format: The format of the texture
* @error: A #CoglError for exceptions
* *
* Wraps an existing GL_TEXTURE_2D texture object as a #CoglTexture2D. * Wraps an existing GL_TEXTURE_2D texture object as a #CoglTexture2D.
* This can be used for integrating Cogl with software using OpenGL * This can be used for integrating Cogl with software using OpenGL
@ -57,20 +56,16 @@ COGL_BEGIN_DECLS
* or if @width or @height don't have the correct texture * or if @width or @height don't have the correct texture
* geometry.</note> * geometry.</note>
* *
* Return value: (transfer full): A newly allocated #CoglTexture2D, or * Returns: (transfer full): A newly allocated #CoglTexture2D
* if Cogl could not validate the @gl_handle in some way
* (perhaps because of an unsupported format) it will return
* %NULL and set @error.
* *
* Since: 2.0 * Since: 2.0
*/ */
CoglTexture2D * CoglTexture2D *
cogl_texture_2d_new_from_foreign (CoglContext *ctx, cogl_texture_2d_gl_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle, unsigned int gl_handle,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format);
CoglError **error);
COGL_END_DECLS COGL_END_DECLS

View file

@ -61,9 +61,7 @@ struct _CoglTexture2D
CoglTexture2D * CoglTexture2D *
_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp, _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format, CoglBool can_convert_in_place);
CoglBool can_convert_in_place,
CoglError **error);
#if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base) #if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
/* NB: The reason we require the width, height and format to be passed /* NB: The reason we require the width, height and format to be passed

View file

@ -50,14 +50,11 @@ _cogl_texture_2d_sliced_new_from_foreign (CoglContext *context,
int height, int height,
int x_pot_waste, int x_pot_waste,
int y_pot_waste, int y_pot_waste,
CoglPixelFormat format, CoglPixelFormat format);
CoglError **error);
CoglTexture2DSliced * CoglTexture2DSliced *
_cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, _cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste, int max_waste,
CoglPixelFormat internal_format, CoglBool can_convert_in_place);
CoglBool can_convert_in_place,
CoglError **error);
#endif /* __COGL_TEXTURE_2D_SLICED_PRIVATE_H */ #endif /* __COGL_TEXTURE_2D_SLICED_PRIVATE_H */

View file

@ -881,8 +881,10 @@ allocate_slices (CoglTexture2DSliced *tex_2ds,
slice = COGL_TEXTURE ( slice = COGL_TEXTURE (
cogl_texture_2d_new_with_size (ctx, cogl_texture_2d_new_with_size (ctx,
x_span->size, y_span->size, x_span->size, y_span->size));
internal_format));
_cogl_texture_copy_internal_format (tex, slice);
g_array_append_val (tex_2ds->slice_textures, slice); g_array_append_val (tex_2ds->slice_textures, slice);
if (!cogl_texture_allocate (slice, error)) if (!cogl_texture_allocate (slice, error))
{ {
@ -927,16 +929,9 @@ CoglTexture2DSliced *
cogl_texture_2d_sliced_new_with_size (CoglContext *ctx, cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height,
int max_waste, int max_waste)
CoglPixelFormat internal_format)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader = _cogl_texture_create_loader ();
/* Since no data, we need some internal format */
if (internal_format == COGL_PIXEL_FORMAT_ANY)
internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED; loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
loader->src.sized.width = width; loader->src.sized.width = width;
loader->src.sized.height = height; loader->src.sized.height = height;
@ -945,16 +940,14 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
width, width,
height, height,
max_waste, max_waste,
internal_format, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
loader); loader);
} }
CoglTexture2DSliced * CoglTexture2DSliced *
_cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, _cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste, int max_waste,
CoglPixelFormat internal_format, CoglBool can_convert_in_place)
CoglBool can_convert_in_place,
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
@ -969,21 +962,17 @@ _cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
cogl_bitmap_get_width (bmp), cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp), cogl_bitmap_get_height (bmp),
max_waste, max_waste,
internal_format, cogl_bitmap_get_format (bmp),
loader); loader);
} }
CoglTexture2DSliced * CoglTexture2DSliced *
cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste, int max_waste)
CoglPixelFormat internal_format,
CoglError **error)
{ {
return _cogl_texture_2d_sliced_new_from_bitmap (bmp, return _cogl_texture_2d_sliced_new_from_bitmap (bmp,
max_waste, max_waste,
internal_format, FALSE);
FALSE,
error);
} }
CoglTexture2DSliced * CoglTexture2DSliced *
@ -994,8 +983,7 @@ _cogl_texture_2d_sliced_new_from_foreign (CoglContext *ctx,
int height, int height,
int x_pot_waste, int x_pot_waste,
int y_pot_waste, int y_pot_waste,
CoglPixelFormat format, CoglPixelFormat format)
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
@ -1039,7 +1027,6 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
int height, int height,
int max_waste, int max_waste,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data, const uint8_t *data,
CoglError **error) CoglError **error)
@ -1061,9 +1048,7 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
rowstride, rowstride,
(uint8_t *) data); (uint8_t *) data);
tex_2ds = cogl_texture_2d_sliced_new_from_bitmap (bmp, max_waste, tex_2ds = cogl_texture_2d_sliced_new_from_bitmap (bmp, max_waste);
internal_format,
error);
cogl_object_unref (bmp); cogl_object_unref (bmp);
@ -1081,7 +1066,6 @@ CoglTexture2DSliced *
cogl_texture_2d_sliced_new_from_file (CoglContext *ctx, cogl_texture_2d_sliced_new_from_file (CoglContext *ctx,
const char *filename, const char *filename,
int max_waste, int max_waste,
CoglPixelFormat internal_format,
CoglError **error) CoglError **error)
{ {
CoglBitmap *bmp; CoglBitmap *bmp;
@ -1095,9 +1079,7 @@ cogl_texture_2d_sliced_new_from_file (CoglContext *ctx,
tex_2ds = _cogl_texture_2d_sliced_new_from_bitmap (bmp, tex_2ds = _cogl_texture_2d_sliced_new_from_bitmap (bmp,
max_waste, max_waste,
internal_format, TRUE); /* can convert in-place */
TRUE, /* can convert in-place */
error);
cogl_object_unref (bmp); cogl_object_unref (bmp);
@ -1198,18 +1180,17 @@ allocate_from_gl_foreign (CoglTexture2DSliced *tex_2ds,
CoglSpan x_span; CoglSpan x_span;
CoglSpan y_span; CoglSpan y_span;
CoglTexture2D *tex_2d = CoglTexture2D *tex_2d =
cogl_texture_2d_new_from_foreign (ctx, cogl_texture_2d_gl_new_from_foreign (ctx,
loader->src.gl_foreign.gl_handle, loader->src.gl_foreign.gl_handle,
gl_width, gl_width,
gl_height, gl_height,
format, format);
error);
if (!tex_2d)
return FALSE;
if (!cogl_texture_allocate (COGL_TEXTURE (tex_2d), error)) if (!cogl_texture_allocate (COGL_TEXTURE (tex_2d), error))
return FALSE; {
cogl_object_unref (tex_2d);
return FALSE;
}
/* The texture 2d backend may use a different pixel format if it /* The texture 2d backend may use a different pixel format if it
queries the actual texture so we'll refetch the format it queries the actual texture so we'll refetch the format it

View file

@ -73,7 +73,6 @@ typedef struct _CoglTexture2DSliced CoglTexture2DSliced;
* are allowed along the right and bottom textures before * are allowed along the right and bottom textures before
* they must be sliced to reduce the amount of waste. A * they must be sliced to reduce the amount of waste. A
* negative can be passed to disable slicing. * negative can be passed to disable slicing.
* @internal_format: The format of the texture
* *
* Creates a #CoglTexture2DSliced that may internally be comprised of * Creates a #CoglTexture2DSliced that may internally be comprised of
* 1 or more #CoglTexture2D textures depending on GPU limitations. * 1 or more #CoglTexture2D textures depending on GPU limitations.
@ -110,8 +109,7 @@ CoglTexture2DSliced *
cogl_texture_2d_sliced_new_with_size (CoglContext *ctx, cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height,
int max_waste, int max_waste);
CoglPixelFormat internal_format);
/** /**
* cogl_texture_2d_sliced_new_from_file: * cogl_texture_2d_sliced_new_from_file:
@ -121,14 +119,6 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
* are allowed along the right and bottom textures before * are allowed along the right and bottom textures before
* they must be sliced to reduce the amount of waste. A * they must be sliced to reduce the amount of waste. A
* negative can be passed to disable slicing. * negative can be passed to disable slicing.
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. If %COGL_PIXEL_FORMAT_ANY is given then a premultiplied
* format similar to the format of the source data will be used. The
* default blending equations of Cogl expect premultiplied color data;
* the main use of passing a non-premultiplied format here is if you
* have non-premultiplied source data and are going to adjust the blend
* mode (see cogl_material_set_blend()) or use the data for something
* other than straight blending.
* @error: A #CoglError to catch exceptional errors or %NULL * @error: A #CoglError to catch exceptional errors or %NULL
* *
* Creates a #CoglTexture2DSliced from an image file. * Creates a #CoglTexture2DSliced from an image file.
@ -167,7 +157,6 @@ CoglTexture2DSliced *
cogl_texture_2d_sliced_new_from_file (CoglContext *ctx, cogl_texture_2d_sliced_new_from_file (CoglContext *ctx,
const char *filename, const char *filename,
int max_waste, int max_waste,
CoglPixelFormat internal_format,
CoglError **error); CoglError **error);
/** /**
@ -180,14 +169,6 @@ cogl_texture_2d_sliced_new_from_file (CoglContext *ctx,
* are allowed along the right and bottom textures before * are allowed along the right and bottom textures before
* they must be sliced to reduce the amount of waste. A * they must be sliced to reduce the amount of waste. A
* negative can be passed to disable slicing. * negative can be passed to disable slicing.
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. If %COGL_PIXEL_FORMAT_ANY is given then a premultiplied
* format similar to the format of the source data will be used. The
* default blending equations of Cogl expect premultiplied color data;
* the main use of passing a non-premultiplied format here is if you
* have non-premultiplied source data and are going to adjust the blend
* mode (see cogl_material_set_blend()) or use the data for something
* other than straight blending.
* @rowstride: the memory offset in bytes between the start of each * @rowstride: the memory offset in bytes between the start of each
* row in @data. A value of 0 will make Cogl automatically * row in @data. A value of 0 will make Cogl automatically
* calculate @rowstride from @width and @format. * calculate @rowstride from @width and @format.
@ -239,7 +220,6 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
int height, int height,
int max_waste, int max_waste,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data, const uint8_t *data,
CoglError **error); CoglError **error);
@ -251,15 +231,6 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
* are allowed along the right and bottom textures before * are allowed along the right and bottom textures before
* they must be sliced to reduce the amount of waste. A * they must be sliced to reduce the amount of waste. A
* negative can be passed to disable slicing. * negative can be passed to disable slicing.
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. If %COGL_PIXEL_FORMAT_ANY is given then a premultiplied
* format similar to the format of the source data will be used. The
* default blending equations of Cogl expect premultiplied color data;
* the main use of passing a non-premultiplied format here is if you
* have non-premultiplied source data and are going to adjust the blend
* mode (see cogl_material_set_blend()) or use the data for something
* other than straight blending.
* @error: A #CoglError to catch exceptional errors or %NULL
* *
* Creates a new #CoglTexture2DSliced texture based on data residing * Creates a new #CoglTexture2DSliced texture based on data residing
* in a bitmap. * in a bitmap.
@ -296,9 +267,7 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
*/ */
CoglTexture2DSliced * CoglTexture2DSliced *
cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste, int max_waste);
CoglPixelFormat internal_format,
CoglError **error);
/** /**
* cogl_is_texture_2d_sliced: * cogl_is_texture_2d_sliced:

View file

@ -110,22 +110,17 @@ _cogl_texture_2d_create_base (CoglContext *ctx,
CoglTexture2D * CoglTexture2D *
cogl_texture_2d_new_with_size (CoglContext *ctx, cogl_texture_2d_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height)
CoglPixelFormat internal_format)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
/* Since no data, we need some internal format */
if (internal_format == COGL_PIXEL_FORMAT_ANY)
internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
loader = _cogl_texture_create_loader (); loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED; loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
loader->src.sized.width = width; loader->src.sized.width = width;
loader->src.sized.height = height; loader->src.sized.height = height;
return _cogl_texture_2d_create_base (ctx, width, height, return _cogl_texture_2d_create_base (ctx, width, height,
internal_format, loader); COGL_PIXEL_FORMAT_RGBA_8888_PRE, loader);
} }
static CoglBool static CoglBool
@ -139,9 +134,7 @@ _cogl_texture_2d_allocate (CoglTexture *tex,
CoglTexture2D * CoglTexture2D *
_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp, _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format, CoglBool can_convert_in_place)
CoglBool can_convert_in_place,
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
@ -155,22 +148,20 @@ _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
return _cogl_texture_2d_create_base (_cogl_bitmap_get_context (bmp), return _cogl_texture_2d_create_base (_cogl_bitmap_get_context (bmp),
cogl_bitmap_get_width (bmp), cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp), cogl_bitmap_get_height (bmp),
internal_format, cogl_bitmap_get_format (bmp),
loader); loader);
} }
CoglTexture2D * CoglTexture2D *
cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp, cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp)
CoglPixelFormat internal_format,
CoglError **error)
{ {
return _cogl_texture_2d_new_from_bitmap (bmp, internal_format, FALSE, error); return _cogl_texture_2d_new_from_bitmap (bmp,
FALSE); /* can't convert in place */
} }
CoglTexture2D * CoglTexture2D *
cogl_texture_2d_new_from_file (CoglContext *ctx, cogl_texture_2d_new_from_file (CoglContext *ctx,
const char *filename, const char *filename,
CoglPixelFormat internal_format,
CoglError **error) CoglError **error)
{ {
CoglBitmap *bmp; CoglBitmap *bmp;
@ -183,9 +174,7 @@ cogl_texture_2d_new_from_file (CoglContext *ctx,
return NULL; return NULL;
tex_2d = _cogl_texture_2d_new_from_bitmap (bmp, tex_2d = _cogl_texture_2d_new_from_bitmap (bmp,
internal_format, TRUE); /* can convert in-place */
TRUE, /* can convert in-place */
error);
cogl_object_unref (bmp); cogl_object_unref (bmp);
@ -197,7 +186,6 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data, const uint8_t *data,
CoglError **error) CoglError **error)
@ -219,9 +207,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
rowstride, rowstride,
(uint8_t *) data); (uint8_t *) data);
tex_2d = cogl_texture_2d_new_from_bitmap (bmp, tex_2d = cogl_texture_2d_new_from_bitmap (bmp);
internal_format,
error);
cogl_object_unref (bmp); cogl_object_unref (bmp);
@ -273,10 +259,10 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
static void static void
shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer, shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
CoglPixelFormat *format_out, CoglPixelFormat *format_out,
CoglPixelFormat *internal_format_out) CoglTextureComponents *components_out)
{ {
CoglPixelFormat format; CoglPixelFormat format;
CoglPixelFormat internal_format = COGL_PIXEL_FORMAT_ANY; CoglTextureComponents components = COGL_TEXTURE_COMPONENTS_RGBA;
switch (wl_shm_buffer_get_format (shm_buffer)) switch (wl_shm_buffer_get_format (shm_buffer))
{ {
@ -286,7 +272,7 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
break; break;
case WL_SHM_FORMAT_XRGB8888: case WL_SHM_FORMAT_XRGB8888:
format = COGL_PIXEL_FORMAT_ARGB_8888; format = COGL_PIXEL_FORMAT_ARGB_8888;
internal_format = COGL_PIXEL_FORMAT_RGB_888; components = COGL_TEXTURE_COMPONENTS_RGB;
break; break;
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN #elif G_BYTE_ORDER == G_LITTLE_ENDIAN
case WL_SHM_FORMAT_ARGB8888: case WL_SHM_FORMAT_ARGB8888:
@ -294,7 +280,7 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
break; break;
case WL_SHM_FORMAT_XRGB8888: case WL_SHM_FORMAT_XRGB8888:
format = COGL_PIXEL_FORMAT_BGRA_8888; format = COGL_PIXEL_FORMAT_BGRA_8888;
internal_format = COGL_PIXEL_FORMAT_BGR_888; components = COGL_TEXTURE_COMPONENTS_RGB;
break; break;
#endif #endif
default: default:
@ -304,8 +290,8 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
if (format_out) if (format_out)
*format_out = format; *format_out = format;
if (internal_format_out) if (components_out)
*internal_format_out = internal_format; *components_out = components;
} }
CoglBool CoglBool
@ -345,6 +331,7 @@ cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
CoglError **error) CoglError **error)
{ {
struct wl_shm_buffer *shm_buffer; struct wl_shm_buffer *shm_buffer;
CoglTexture2D *tex = NULL;
shm_buffer = wl_shm_buffer_get (buffer); shm_buffer = wl_shm_buffer_get (buffer);
@ -353,17 +340,31 @@ cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
int stride = wl_shm_buffer_get_stride (shm_buffer); int stride = wl_shm_buffer_get_stride (shm_buffer);
int width = wl_shm_buffer_get_width (shm_buffer); int width = wl_shm_buffer_get_width (shm_buffer);
int height = wl_shm_buffer_get_height (shm_buffer); int height = wl_shm_buffer_get_height (shm_buffer);
CoglPixelFormat format, internal_format; CoglPixelFormat format;
CoglTextureComponents components;
CoglBitmap *bmp;
shm_buffer_get_cogl_pixel_format (shm_buffer, &format, &internal_format); shm_buffer_get_cogl_pixel_format (shm_buffer, &format, &components);
return cogl_texture_2d_new_from_data (ctx, bmp = cogl_bitmap_new_for_data (ctx,
width, height, width, height,
format, format,
internal_format, stride,
stride, wl_shm_buffer_get_data (shm_buffer));
wl_shm_buffer_get_data (shm_buffer),
error); tex = cogl_texture_2d_new_from_bitmap (bmp);
cogl_texture_set_components (COGL_TEXTURE (tex), components);
cogl_object_unref (bmp);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), error))
{
cogl_object_unref (tex);
return NULL;
}
else
return tex;
} }
else else
{ {
@ -383,7 +384,6 @@ cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
&height)) &height))
{ {
EGLImageKHR image; EGLImageKHR image;
CoglTexture2D *tex = NULL;
CoglPixelFormat internal_format; CoglPixelFormat internal_format;
_COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->constraints & _COGL_RETURN_VAL_IF_FAIL (_cogl_context_get_winsys (ctx)->constraints &

View file

@ -73,7 +73,6 @@ cogl_is_texture_2d (void *object);
* @ctx: A #CoglContext * @ctx: A #CoglContext
* @width: Width of the texture to allocate * @width: Width of the texture to allocate
* @height: Height of the texture to allocate * @height: Height of the texture to allocate
* @internal_format: The format of the texture
* *
* Creates a low-level #CoglTexture2D texture with a given @width and * Creates a low-level #CoglTexture2D texture with a given @width and
* @height that your GPU can texture from directly. * @height that your GPU can texture from directly.
@ -101,21 +100,12 @@ cogl_is_texture_2d (void *object);
CoglTexture2D * CoglTexture2D *
cogl_texture_2d_new_with_size (CoglContext *ctx, cogl_texture_2d_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height);
CoglPixelFormat internal_format);
/** /**
* cogl_texture_2d_new_from_file: * cogl_texture_2d_new_from_file:
* @ctx: A #CoglContext * @ctx: A #CoglContext
* @filename: the file to load * @filename: the file to load
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture. If %COGL_PIXEL_FORMAT_ANY is given then a premultiplied
* format similar to the format of the source data will be used. The
* default blending equations of Cogl expect premultiplied color data;
* the main use of passing a non-premultiplied format here is if you
* have non-premultiplied source data and are going to adjust the blend
* mode (see cogl_material_set_blend()) or use the data for something
* other than straight blending.
* @error: A #CoglError to catch exceptional errors or %NULL * @error: A #CoglError to catch exceptional errors or %NULL
* *
* Creates a low-level #CoglTexture2D texture from an image file. * Creates a low-level #CoglTexture2D texture from an image file.
@ -144,7 +134,6 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
CoglTexture2D * CoglTexture2D *
cogl_texture_2d_new_from_file (CoglContext *ctx, cogl_texture_2d_new_from_file (CoglContext *ctx,
const char *filename, const char *filename,
CoglPixelFormat internal_format,
CoglError **error); CoglError **error);
/** /**
@ -153,14 +142,6 @@ cogl_texture_2d_new_from_file (CoglContext *ctx,
* @width: width of texture in pixels * @width: width of texture in pixels
* @height: height of texture in pixels * @height: height of texture in pixels
* @format: the #CoglPixelFormat the buffer is stored in in RAM * @format: the #CoglPixelFormat the buffer is stored in in RAM
* @internal_format: the #CoglPixelFormat that will be used for storing
* the buffer on the GPU. If %COGL_PIXEL_FORMAT_ANY is given then a
* premultiplied format similar to the format of the source data will
* be used. The default blending equations of Cogl expect premultiplied
* color data; the main use of passing a non-premultiplied format here
* is if you have non-premultiplied source data and are going to adjust
* the blend mode (see cogl_pipeline_set_blend()) or use the data for
* something other than straight blending.
* @rowstride: the memory offset in bytes between the starts of * @rowstride: the memory offset in bytes between the starts of
* scanlines in @data. A value of 0 will make Cogl automatically * scanlines in @data. A value of 0 will make Cogl automatically
* calculate @rowstride from @width and @format. * calculate @rowstride from @width and @format.
@ -198,7 +179,6 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data, const uint8_t *data,
CoglError **error); CoglError **error);
@ -206,15 +186,6 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
/** /**
* cogl_texture_2d_new_from_bitmap: * cogl_texture_2d_new_from_bitmap:
* @bitmap: A #CoglBitmap * @bitmap: A #CoglBitmap
* @internal_format: the #CoglPixelFormat that will be used for storing
* the buffer on the GPU. If %COGL_PIXEL_FORMAT_ANY is given then a
* premultiplied format similar to the format of the source data will
* be used. The default blending equations of Cogl expect premultiplied
* color data; the main use of passing a non-premultiplied format here
* is if you have non-premultiplied source data and are going to adjust
* the blend mode (see cogl_pipeline_set_blend()) or use the data for
* something other than straight blending.
* @error: A #CoglError for exceptions
* *
* Creates a low-level #CoglTexture2D texture based on data residing * Creates a low-level #CoglTexture2D texture based on data residing
* in a #CoglBitmap. * in a #CoglBitmap.
@ -235,18 +206,13 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
* checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via * checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via
* cogl_has_feature().</note> * cogl_has_feature().</note>
* *
* Returns: (transfer full): A newly allocated #CoglTexture2D, or if * Returns: (transfer full): A newly allocated #CoglTexture2D
* the size is not supported (because it is too large or a
* non-power-of-two size that the hardware doesn't support)
* it will return %NULL and set @error.
* *
* Since: 2.0 * Since: 2.0
* Stability: unstable * Stability: unstable
*/ */
CoglTexture2D * CoglTexture2D *
cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap, cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap);
CoglPixelFormat internal_format,
CoglError **error);
COGL_END_DECLS COGL_END_DECLS

View file

@ -147,31 +147,23 @@ CoglTexture3D *
cogl_texture_3d_new_with_size (CoglContext *ctx, cogl_texture_3d_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height,
int depth, int depth)
CoglPixelFormat internal_format)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader = _cogl_texture_create_loader ();
/* Since no data, we need some internal format */
if (internal_format == COGL_PIXEL_FORMAT_ANY)
internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED; loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
loader->src.sized.width = width; loader->src.sized.width = width;
loader->src.sized.height = height; loader->src.sized.height = height;
loader->src.sized.depth = depth; loader->src.sized.depth = depth;
return _cogl_texture_3d_create_base (ctx, width, height, depth, return _cogl_texture_3d_create_base (ctx, width, height, depth,
internal_format, loader); COGL_PIXEL_FORMAT_RGBA_8888_PRE,
loader);
} }
CoglTexture3D * CoglTexture3D *
cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp, cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
int height, int height,
int depth, int depth)
CoglPixelFormat internal_format,
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
@ -188,7 +180,7 @@ cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
cogl_bitmap_get_width (bmp), cogl_bitmap_get_width (bmp),
height, height,
depth, depth,
internal_format, cogl_bitmap_get_format (bmp),
loader); loader);
} }
@ -198,7 +190,6 @@ cogl_texture_3d_new_from_data (CoglContext *context,
int height, int height,
int depth, int depth,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
int image_stride, int image_stride,
const uint8_t *data, const uint8_t *data,
@ -271,9 +262,7 @@ cogl_texture_3d_new_from_data (CoglContext *context,
ret = cogl_texture_3d_new_from_bitmap (bitmap, ret = cogl_texture_3d_new_from_bitmap (bitmap,
height, height,
depth, depth);
internal_format,
error);
cogl_object_unref (bitmap); cogl_object_unref (bitmap);

View file

@ -53,8 +53,6 @@ typedef struct _CoglTexture3D CoglTexture3D;
* @width: width of the texture in pixels. * @width: width of the texture in pixels.
* @height: height of the texture in pixels. * @height: height of the texture in pixels.
* @depth: depth of the texture in pixels. * @depth: depth of the texture in pixels.
* @internal_format: the #CoglPixelFormat to use for the GPU
* storage of the texture.
* *
* Creates a low-level #CoglTexture3D texture with the specified * Creates a low-level #CoglTexture3D texture with the specified
* dimensions and pixel format. * dimensions and pixel format.
@ -84,8 +82,7 @@ CoglTexture3D *
cogl_texture_3d_new_with_size (CoglContext *context, cogl_texture_3d_new_with_size (CoglContext *context,
int width, int width,
int height, int height,
int depth, int depth);
CoglPixelFormat internal_format);
/** /**
* cogl_texture_3d_new_from_data: * cogl_texture_3d_new_from_data:
@ -94,14 +91,6 @@ cogl_texture_3d_new_with_size (CoglContext *context,
* @height: height of the texture in pixels. * @height: height of the texture in pixels.
* @depth: depth of the texture in pixels. * @depth: depth of the texture in pixels.
* @format: the #CoglPixelFormat the buffer is stored in in RAM * @format: the #CoglPixelFormat the buffer is stored in in RAM
* @internal_format: the #CoglPixelFormat that will be used for storing
* the buffer on the GPU. If %COGL_PIXEL_FORMAT_ANY is given then a
* premultiplied format similar to the format of the source data will
* be used. The default blending equations of Cogl expect premultiplied
* color data; the main use of passing a non-premultiplied format here
* is if you have non-premultiplied source data and are going to adjust
* the blend mode (see cogl_pipeline_set_blend()) or use the data for
* something other than straight blending.
* @rowstride: the memory offset in bytes between the starts of * @rowstride: the memory offset in bytes between the starts of
* scanlines in @data or 0 to infer it from the width and format * scanlines in @data or 0 to infer it from the width and format
* @image_stride: the number of bytes from one image to the next. This * @image_stride: the number of bytes from one image to the next. This
@ -137,7 +126,6 @@ cogl_texture_3d_new_from_data (CoglContext *context,
int height, int height,
int depth, int depth,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
int image_stride, int image_stride,
const uint8_t *data, const uint8_t *data,
@ -148,15 +136,6 @@ cogl_texture_3d_new_from_data (CoglContext *context,
* @bitmap: A #CoglBitmap object. * @bitmap: A #CoglBitmap object.
* @height: height of the texture in pixels. * @height: height of the texture in pixels.
* @depth: depth of the texture in pixels. * @depth: depth of the texture in pixels.
* @internal_format: the #CoglPixelFormat that will be used for storing
* the buffer on the GPU. If %COGL_PIXEL_FORMAT_ANY is given then a
* premultiplied format similar to the format of the source data will
* be used. The default blending equations of Cogl expect premultiplied
* color data; the main use of passing a non-premultiplied format here
* is if you have non-premultiplied source data and are going to adjust
* the blend mode (see cogl_pipeline_set_blend()) or use the data for
* something other than straight blending.
* @error: A CoglError return location.
* *
* Creates a low-level 3D texture and initializes it with the images * Creates a low-level 3D texture and initializes it with the images
* in @bitmap. The images are assumed to be packed together after one * in @bitmap. The images are assumed to be packed together after one
@ -182,17 +161,14 @@ cogl_texture_3d_new_from_data (CoglContext *context,
* fail if the requested dimensions are not supported by the * fail if the requested dimensions are not supported by the
* GPU.</note> * GPU.</note>
* *
* Return value: (transfer full): the newly created texture or %NULL * Return value: (transfer full): a newly created #CoglTexture3D
* if there was an error.
* Since: 2.0 * Since: 2.0
* Stability: unstable * Stability: unstable
*/ */
CoglTexture3D * CoglTexture3D *
cogl_texture_3d_new_from_bitmap (CoglBitmap *bitmap, cogl_texture_3d_new_from_bitmap (CoglBitmap *bitmap,
int height, int height,
int depth, int depth);
CoglPixelFormat internal_format,
CoglError **error);
/** /**
* cogl_is_texture_3d: * cogl_is_texture_3d:

View file

@ -234,7 +234,7 @@ _cogl_texture_init (CoglTexture *texture,
CoglContext *ctx, CoglContext *ctx,
int width, int width,
int height, int height,
CoglPixelFormat internal_format, CoglPixelFormat src_format,
CoglTextureLoader *loader, CoglTextureLoader *loader,
const CoglTextureVtable *vtable); const CoglTextureVtable *vtable);
@ -395,4 +395,8 @@ _cogl_texture_get_format (CoglTexture *texture);
CoglTextureLoader * CoglTextureLoader *
_cogl_texture_create_loader (void); _cogl_texture_create_loader (void);
void
_cogl_texture_copy_internal_format (CoglTexture *src,
CoglTexture *dest);
#endif /* __COGL_TEXTURE_PRIVATE_H */ #endif /* __COGL_TEXTURE_PRIVATE_H */

View file

@ -211,11 +211,21 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
tex_rect = _cogl_texture_rectangle_create_base (ctx, width, height, tex_rect = _cogl_texture_rectangle_create_base (ctx, width, height,
internal_format, loader); internal_format, loader);
/* XXX: This api has been changed for Cogl 2.0 on the master branch /* XXX: This api has been changed for Cogl 2.0 on the master branch
* to not take a CoglError to allow the storage to be allocated * to not take a CoglError to allow the storage to be allocated
* lazily but since Mutter uses this api we are currently * lazily but since Mutter uses this api we are currently
* maintaining the semantics of immediately allocating the storage * maintaining the semantics of immediately allocating the storage
*/ */
/* By default tex->premultiplied is set to TRUE and tex->components
* get initialized according to a given source-format in
* _cogl_texture_init(). Since this api has an internal-format
* argument for compatibility we need to make sure the
* ->premultiplied and ->components state are initialized according
* to the users given @internal_format. */
_cogl_texture_set_internal_format (COGL_TEXTURE (tex_rect), internal_format);
if (!cogl_texture_allocate (COGL_TEXTURE (tex_rect), error)) if (!cogl_texture_allocate (COGL_TEXTURE (tex_rect), error))
{ {
cogl_object_unref (tex_rect); cogl_object_unref (tex_rect);
@ -499,9 +509,7 @@ _cogl_texture_rectangle_allocate (CoglTexture *tex,
} }
CoglTextureRectangle * CoglTextureRectangle *
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp, cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp)
CoglPixelFormat internal_format,
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
@ -515,7 +523,7 @@ cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
return _cogl_texture_rectangle_create_base (_cogl_bitmap_get_context (bmp), return _cogl_texture_rectangle_create_base (_cogl_bitmap_get_context (bmp),
cogl_bitmap_get_width (bmp), cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp), cogl_bitmap_get_height (bmp),
internal_format, cogl_bitmap_get_format (bmp),
loader); loader);
} }
@ -524,8 +532,7 @@ cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle, unsigned int gl_handle,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format)
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;

View file

@ -84,10 +84,10 @@ cogl_is_texture_rectangle (void *object);
* @internal_format: The desired internal texture format * @internal_format: The desired internal texture format
* @error: An optional CoglError pointer for reporting exceptions * @error: An optional CoglError pointer for reporting exceptions
* *
* Allocates a new #CoglTextureRectangle texture with a given @width, @height * Allocates a new #CoglTextureRectangle texture with a given @width,
* and @internal_format. This texture is a low-level texture that * @height and @internal_format. This texture is a low-level texture
* the GPU can sample from directly unlike high-level textures such * that the GPU can sample from directly unlike high-level textures
* as #CoglTexture2DSliced and #CoglAtlasTexture. * such as #CoglTexture2DSliced and #CoglAtlasTexture.
* *
* <note>Unlike for #CoglTexture2D textures, coordinates for * <note>Unlike for #CoglTexture2D textures, coordinates for
* #CoglTextureRectangle textures should not be normalized. So instead * #CoglTextureRectangle textures should not be normalized. So instead
@ -125,16 +125,12 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
/** /**
* cogl_texture_rectangle_new_from_bitmap: * cogl_texture_rectangle_new_from_bitmap:
* @bitmap: A #CoglBitmap * @bitmap: A #CoglBitmap
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture
* @error: A return location for a CoglError or %NULL
* *
* Allocates a new #CoglTextureRectangle texture which will be * Allocates a new #CoglTextureRectangle texture which will be
* initialized with the pixel data from @bitmap. Internally the data * initialized with the pixel data from @bitmap. This texture is a
* will be stored in the format given by @internal_format. This * low-level texture that the GPU can sample from directly unlike
* texture is a low-level texture that the GPU can sample from * high-level textures such as #CoglTexture2DSliced and
* directly unlike high-level textures such as #CoglTexture2DSliced * #CoglAtlasTexture.
* and #CoglAtlasTexture.
* *
* <note>Unlike for #CoglTexture2D textures, coordinates for * <note>Unlike for #CoglTexture2D textures, coordinates for
* #CoglTextureRectangle textures should not be normalized. So instead * #CoglTextureRectangle textures should not be normalized. So instead
@ -156,18 +152,13 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
* how the texture is going to be used and can optimize how it is * how the texture is going to be used and can optimize how it is
* allocated. * allocated.
* *
* Return value: (transfer full): A pointer to a newly allocated * Return value: (transfer full): A pointer to a new
* #CoglTextureRectangle texture or if the size was too large * #CoglTextureRectangle texture.
* or there wasn't enough memory %NULL is returned and @error
* set.
*
* Since: 2.0 * Since: 2.0
* Stability: unstable * Stability: unstable
*/ */
CoglTextureRectangle * CoglTextureRectangle *
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap, cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap);
CoglPixelFormat internal_format,
CoglError **error);
/** /**
* cogl_texture_rectangle_new_from_foreign: * cogl_texture_rectangle_new_from_foreign:
@ -176,7 +167,6 @@ cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap,
* @width: Width of the foreign GL texture * @width: Width of the foreign GL texture
* @height: Height of the foreign GL texture * @height: Height of the foreign GL texture
* @format: The format of the texture * @format: The format of the texture
* @error: A #CoglError for exceptions
* *
* Wraps an existing GL_TEXTURE_RECTANGLE texture object as a * Wraps an existing GL_TEXTURE_RECTANGLE texture object as a
* #CoglTextureRectangle. This can be used for integrating Cogl with * #CoglTextureRectangle. This can be used for integrating Cogl with
@ -203,18 +193,14 @@ cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap,
* for example you can declare whether the texture is premultiplied * for example you can declare whether the texture is premultiplied
* with cogl_texture_set_premultiplied(). * with cogl_texture_set_premultiplied().
* *
* Return value: (transfer full): A newly allocated * Return value: (transfer full): A new #CoglTextureRectangle texture
* #CoglTextureRectangle, or if Cogl could not validate the
* @gl_handle in some way (perhaps because of an unsupported
* format) it will return %NULL and set @error.
*/ */
CoglTextureRectangle * CoglTextureRectangle *
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx, cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle, unsigned int gl_handle,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format);
CoglError **error);
COGL_END_DECLS COGL_END_DECLS

View file

@ -107,7 +107,7 @@ _cogl_texture_init (CoglTexture *texture,
CoglContext *context, CoglContext *context,
int width, int width,
int height, int height,
CoglPixelFormat internal_format, CoglPixelFormat src_format,
CoglTextureLoader *loader, CoglTextureLoader *loader,
const CoglTextureVtable *vtable) const CoglTextureVtable *vtable)
{ {
@ -121,7 +121,22 @@ _cogl_texture_init (CoglTexture *texture,
texture->loader = loader; texture->loader = loader;
_cogl_texture_set_internal_format (texture, internal_format); _cogl_texture_set_internal_format (texture, src_format);
/* Although we want to initialize texture::components according
* to the source format, we always want the internal layout to
* be considered premultiplied by default.
*
* NB: this ->premultiplied state is user configurable so to avoid
* awkward documentation, setting this to 'true' does not depend on
* ->components having an alpha component (we will simply ignore the
* premultiplied status later if there is no alpha component).
* This way we don't have to worry about updating the
* ->premultiplied state in _set_components(). Similarly we don't
* have to worry about updating the ->components state in
* _set_premultiplied().
*/
texture->premultiplied = TRUE;
} }
static void static void
@ -1503,3 +1518,11 @@ cogl_texture_get_premultiplied (CoglTexture *texture)
{ {
return texture->premultiplied; return texture->premultiplied;
} }
void
_cogl_texture_copy_internal_format (CoglTexture *src,
CoglTexture *dest)
{
cogl_texture_set_components (dest, src->components);
cogl_texture_set_premultiplied (dest, src->premultiplied);
}

View file

@ -80,14 +80,10 @@ cogl_texture_new_with_size (unsigned int width,
cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP))) cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP)))
{ {
/* First try creating a fast-path non-sliced texture */ /* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height));
width, height,
internal_format)); _cogl_texture_set_internal_format (tex, internal_format);
/* TODO: instead of allocating storage here it would be better
* if we had some api that let us just check that the size is
* supported by the hardware so storage could be allocated
* lazily when uploading data. */
if (!cogl_texture_allocate (tex, &skip_error)) if (!cogl_texture_allocate (tex, &skip_error))
{ {
cogl_error_free (skip_error); cogl_error_free (skip_error);
@ -105,8 +101,9 @@ cogl_texture_new_with_size (unsigned int width,
tex = COGL_TEXTURE (cogl_texture_2d_sliced_new_with_size (ctx, tex = COGL_TEXTURE (cogl_texture_2d_sliced_new_with_size (ctx,
width, width,
height, height,
max_waste, max_waste));
internal_format));
_cogl_texture_set_internal_format (tex, internal_format);
} }
/* NB: This api existed before Cogl introduced lazy allocation of /* NB: This api existed before Cogl introduced lazy allocation of
@ -206,7 +203,6 @@ _cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
CoglError **error) CoglError **error)
{ {
CoglContext *ctx = _cogl_bitmap_get_context (bitmap); CoglContext *ctx = _cogl_bitmap_get_context (bitmap);
CoglAtlasTexture *atlas_tex;
CoglTexture *tex; CoglTexture *tex;
CoglError *internal_error = NULL; CoglError *internal_error = NULL;
@ -214,14 +210,19 @@ _cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
!COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_ATLAS)) !COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_ATLAS))
{ {
/* First try putting the texture in the atlas */ /* First try putting the texture in the atlas */
if ((atlas_tex = _cogl_atlas_texture_new_from_bitmap (bitmap, CoglAtlasTexture *atlas_tex =
internal_format, _cogl_atlas_texture_new_from_bitmap (bitmap,
can_convert_in_place, can_convert_in_place);
&internal_error)))
_cogl_texture_set_internal_format (COGL_TEXTURE (atlas_tex),
internal_format);
if (cogl_texture_allocate (COGL_TEXTURE (atlas_tex), &internal_error))
return COGL_TEXTURE (atlas_tex); return COGL_TEXTURE (atlas_tex);
cogl_error_free (internal_error); cogl_error_free (internal_error);
internal_error = NULL; internal_error = NULL;
cogl_object_unref (atlas_tex);
} }
/* If that doesn't work try a fast path 2D texture */ /* If that doesn't work try a fast path 2D texture */
@ -231,14 +232,16 @@ _cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP))) cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP)))
{ {
tex = COGL_TEXTURE (_cogl_texture_2d_new_from_bitmap (bitmap, tex = COGL_TEXTURE (_cogl_texture_2d_new_from_bitmap (bitmap,
internal_format, can_convert_in_place));
can_convert_in_place,
&internal_error));
if (!tex) _cogl_texture_set_internal_format (tex, internal_format);
if (!cogl_texture_allocate (tex, &internal_error))
{ {
cogl_error_free (internal_error); cogl_error_free (internal_error);
internal_error = NULL; internal_error = NULL;
cogl_object_unref (tex);
tex = NULL;
} }
} }
else else
@ -250,9 +253,15 @@ _cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
int max_waste = flags & COGL_TEXTURE_NO_SLICING ? -1 : COGL_TEXTURE_MAX_WASTE; int max_waste = flags & COGL_TEXTURE_NO_SLICING ? -1 : COGL_TEXTURE_MAX_WASTE;
tex = COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_bitmap (bitmap, tex = COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_bitmap (bitmap,
max_waste, max_waste,
internal_format, can_convert_in_place));
can_convert_in_place,
error)); _cogl_texture_set_internal_format (tex, internal_format);
if (!cogl_texture_allocate (tex, error))
{
cogl_object_unref (tex);
tex = NULL;
}
} }
if (tex && if (tex &&
@ -343,8 +352,9 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
gl_handle, gl_handle,
width, width,
height, height,
format, format);
NULL); _cogl_texture_set_internal_format (COGL_TEXTURE (texture_rectangle),
format);
/* CoglTextureRectangle textures work with non-normalized /* CoglTextureRectangle textures work with non-normalized
* coordinates, but the semantics for this function that people * coordinates, but the semantics for this function that people
@ -358,20 +368,32 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
#endif #endif
if (x_pot_waste != 0 || y_pot_waste != 0) if (x_pot_waste != 0 || y_pot_waste != 0)
return COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_foreign (ctx, {
gl_handle, CoglTexture *tex =
gl_target, COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_foreign (ctx,
width, gl_handle,
height, gl_target,
x_pot_waste, width,
y_pot_waste, height,
format, x_pot_waste,
NULL)); y_pot_waste,
format));
_cogl_texture_set_internal_format (tex, format);
cogl_texture_allocate (tex, NULL);
return tex;
}
else else
return COGL_TEXTURE (cogl_texture_2d_new_from_foreign (ctx, {
CoglTexture *tex =
COGL_TEXTURE (cogl_texture_2d_gl_new_from_foreign (ctx,
gl_handle, gl_handle,
width, width,
height, height,
format, format));
NULL)); _cogl_texture_set_internal_format (tex, format);
cogl_texture_allocate (tex, NULL);
return tex;
}
} }

View file

@ -386,20 +386,11 @@ create_depth_texture (CoglContext *ctx,
int width, int width,
int height) int height)
{ {
CoglPixelFormat format; CoglTexture2D *depth_texture =
CoglTexture2D *depth_texture; cogl_texture_2d_new_with_size (ctx, width, height);
if (_cogl_has_private_feature cogl_texture_set_components (COGL_TEXTURE (depth_texture),
(ctx, COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL) || COGL_TEXTURE_COMPONENTS_DEPTH);
_cogl_has_private_feature
(ctx, COGL_PRIVATE_FEATURE_OES_PACKED_DEPTH_STENCIL))
format = COGL_PIXEL_FORMAT_DEPTH_24_STENCIL_8;
else
format = COGL_PIXEL_FORMAT_DEPTH_16;
depth_texture = cogl_texture_2d_new_with_size (ctx,
width, height,
format);
return COGL_TEXTURE (depth_texture); return COGL_TEXTURE (depth_texture);
} }

View file

@ -409,7 +409,7 @@ allocate_from_gl_foreign (CoglTexture2D *tex_2d,
whether it has GL_GENERATE_MIPMAP enabled to determine whether to whether it has GL_GENERATE_MIPMAP enabled to determine whether to
auto-generate the mipmap. This doesn't make much sense any more auto-generate the mipmap. This doesn't make much sense any more
since Cogl switch to using glGenerateMipmap. Ideally I think since Cogl switch to using glGenerateMipmap. Ideally I think
cogl_texture_2d_new_from_foreign should take a flags parameter so cogl_texture_2d_gl_new_from_foreign should take a flags parameter so
that the application can decide whether it wants that the application can decide whether it wants
auto-mipmapping. To be compatible with existing code, Cogl now auto-mipmapping. To be compatible with existing code, Cogl now
disables its own auto-mipmapping but leaves the value of disables its own auto-mipmapping but leaves the value of
@ -521,12 +521,11 @@ _cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
} }
CoglTexture2D * CoglTexture2D *
cogl_texture_2d_new_from_foreign (CoglContext *ctx, cogl_texture_2d_gl_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle, unsigned int gl_handle,
int width, int width,
int height, int height,
CoglPixelFormat format, CoglPixelFormat format)
CoglError **error)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;

View file

@ -516,8 +516,9 @@ create_fallback_texture (CoglContext *ctx,
{ {
/* First try creating a fast-path non-sliced texture */ /* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
width, height, width, height));
internal_format));
_cogl_texture_set_internal_format (tex, internal_format);
/* TODO: instead of allocating storage here it would be better /* TODO: instead of allocating storage here it would be better
* if we had some api that let us just check that the size is * if we had some api that let us just check that the size is
@ -539,9 +540,10 @@ create_fallback_texture (CoglContext *ctx,
cogl_texture_2d_sliced_new_with_size (ctx, cogl_texture_2d_sliced_new_with_size (ctx,
width, width,
height, height,
COGL_TEXTURE_MAX_WASTE, COGL_TEXTURE_MAX_WASTE);
internal_format);
tex = COGL_TEXTURE (tex_2ds); tex = COGL_TEXTURE (tex_2ds);
_cogl_texture_set_internal_format (tex, internal_format);
} }
return tex; return tex;

View file

@ -2508,6 +2508,8 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
texture_format, texture_format,
&error)); &error));
_cogl_texture_set_internal_format (tex, texture_format);
if (glx_tex_pixmap->glx_tex) if (glx_tex_pixmap->glx_tex)
COGL_NOTE (TEXTURE_PIXMAP, "Created a texture rectangle for %p", COGL_NOTE (TEXTURE_PIXMAP, "Created a texture rectangle for %p",
tex_pixmap); tex_pixmap);
@ -2526,8 +2528,9 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
glx_tex_pixmap->glx_tex = COGL_TEXTURE ( glx_tex_pixmap->glx_tex = COGL_TEXTURE (
cogl_texture_2d_new_with_size (ctx, cogl_texture_2d_new_with_size (ctx,
tex->width, tex->width,
tex->height, tex->height));
texture_format));
_cogl_texture_set_internal_format (tex, texture_format);
if (cogl_texture_allocate (glx_tex_pixmap->glx_tex, &error)) if (cogl_texture_allocate (glx_tex_pixmap->glx_tex, &error))
COGL_NOTE (TEXTURE_PIXMAP, "Created a texture 2d for %p", COGL_NOTE (TEXTURE_PIXMAP, "Created a texture 2d for %p",

View file

@ -420,7 +420,7 @@ cogl_texture_2d_new_with_size
cogl_texture_2d_new_from_file cogl_texture_2d_new_from_file
cogl_texture_2d_new_from_bitmap cogl_texture_2d_new_from_bitmap
cogl_texture_2d_new_from_data cogl_texture_2d_new_from_data
cogl_texture_2d_new_from_foreign cogl_texture_2d_gl_new_from_foreign
cogl_is_texture_rectangle cogl_is_texture_rectangle
</SECTION> </SECTION>

View file

@ -228,7 +228,7 @@ CoglTexture2D
cogl_is_texture_2d cogl_is_texture_2d
cogl_texture_2d_new_with_size cogl_texture_2d_new_with_size
cogl_texture_2d_new_from_data cogl_texture_2d_new_from_data
cogl_texture_2d_new_from_foreign cogl_texture_2d_gl_new_from_foreign
</SECTION> </SECTION>
<SECTION> <SECTION>

View file

@ -223,7 +223,6 @@ main (int argc, char **argv)
data.texture = data.texture =
cogl_texture_2d_new_from_file (ctx, cogl_texture_2d_new_from_file (ctx,
COGL_EXAMPLES_DATA "crate.jpg", COGL_EXAMPLES_DATA "crate.jpg",
COGL_PIXEL_FORMAT_ANY,
&error); &error);
if (!data.texture) if (!data.texture)
g_error ("Failed to load texture: %s", error->message); g_error ("Failed to load texture: %s", error->message);

View file

@ -98,8 +98,7 @@ main (int argc, char **argv)
data.offscreen_texture = data.offscreen_texture =
cogl_texture_2d_new_with_size (data.ctx, cogl_texture_2d_new_with_size (data.ctx,
OFFSCREEN_WIDTH, OFFSCREEN_WIDTH,
OFFSCREEN_HEIGHT, OFFSCREEN_HEIGHT);
COGL_PIXEL_FORMAT_ANY);
data.offscreen = cogl_offscreen_new_with_texture (data.offscreen_texture); data.offscreen = cogl_offscreen_new_with_texture (data.offscreen_texture);
data.gles2_ctx = cogl_gles2_context_new (data.ctx, &error); data.gles2_ctx = cogl_gles2_context_new (data.ctx, &error);

View file

@ -62,9 +62,7 @@ main (int argc, char **argv)
cogl_onscreen_show (onscreen); cogl_onscreen_show (onscreen);
tex = cogl_texture_2d_new_with_size (ctx, tex = cogl_texture_2d_new_with_size (ctx, 320, 480);
320, 480,
COGL_PIXEL_FORMAT_ANY);
offscreen = cogl_offscreen_new_with_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
offscreen_fb = offscreen; offscreen_fb = offscreen;
cogl_framebuffer_set_samples_per_pixel (offscreen_fb, 4); cogl_framebuffer_set_samples_per_pixel (offscreen_fb, 4);

View file

@ -82,7 +82,6 @@ generate_round_texture (CoglContext *context)
tex = cogl_texture_2d_new_from_data (context, tex = cogl_texture_2d_new_from_data (context,
TEXTURE_SIZE, TEXTURE_SIZE, TEXTURE_SIZE, TEXTURE_SIZE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
TEXTURE_SIZE * 4, TEXTURE_SIZE * 4,
data, data,
NULL /* error */); NULL /* error */);

View file

@ -177,8 +177,7 @@ test_utils_init (TestFlags requirement_flags,
{ {
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglTexture2D *tex = cogl_texture_2d_new_with_size (test_ctx, CoglTexture2D *tex = cogl_texture_2d_new_with_size (test_ctx,
FB_WIDTH, FB_HEIGHT, FB_WIDTH, FB_HEIGHT);
COGL_PIXEL_FORMAT_ANY);
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex)); offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex));
test_fb = COGL_FRAMEBUFFER (offscreen); test_fb = COGL_FRAMEBUFFER (offscreen);
} }
@ -335,7 +334,6 @@ test_utils_create_color_texture (CoglContext *context,
tex_2d = cogl_texture_2d_new_from_data (context, tex_2d = cogl_texture_2d_new_from_data (context,
1, 1, /* width/height */ 1, 1, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */ 4, /* rowstride */
(uint8_t *) &color, (uint8_t *) &color,
NULL); NULL);
@ -364,7 +362,7 @@ test_utils_texture_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height,
TestUtilsTextureFlags flags, TestUtilsTextureFlags flags,
CoglPixelFormat internal_format) CoglTextureComponents components)
{ {
CoglTexture *tex; CoglTexture *tex;
CoglError *skip_error = NULL; CoglError *skip_error = NULL;
@ -375,8 +373,9 @@ test_utils_texture_new_with_size (CoglContext *ctx,
{ {
/* First try creating a fast-path non-sliced texture */ /* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
width, height, width, height));
internal_format));
cogl_texture_set_components (tex, components);
if (!cogl_texture_allocate (tex, &skip_error)) if (!cogl_texture_allocate (tex, &skip_error))
{ {
@ -397,9 +396,10 @@ test_utils_texture_new_with_size (CoglContext *ctx,
cogl_texture_2d_sliced_new_with_size (ctx, cogl_texture_2d_sliced_new_with_size (ctx,
width, width,
height, height,
max_waste, max_waste);
internal_format);
tex = COGL_TEXTURE (tex_2ds); tex = COGL_TEXTURE (tex_2ds);
cogl_texture_set_components (tex, components);
} }
if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP) if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
@ -424,7 +424,7 @@ test_utils_texture_new_with_size (CoglContext *ctx,
CoglTexture * CoglTexture *
test_utils_texture_new_from_bitmap (CoglBitmap *bitmap, test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
TestUtilsTextureFlags flags, TestUtilsTextureFlags flags,
CoglPixelFormat internal_format) CoglBool premultiplied)
{ {
CoglAtlasTexture *atlas_tex; CoglAtlasTexture *atlas_tex;
CoglTexture *tex; CoglTexture *tex;
@ -433,15 +433,15 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
if (!flags) if (!flags)
{ {
/* First try putting the texture in the atlas */ /* First try putting the texture in the atlas */
if ((atlas_tex = cogl_atlas_texture_new_from_bitmap (bitmap, atlas_tex = cogl_atlas_texture_new_from_bitmap (bitmap);
internal_format,
&internal_error)) && cogl_texture_set_premultiplied (COGL_TEXTURE (atlas_tex), premultiplied);
cogl_texture_allocate (COGL_TEXTURE (atlas_tex), &internal_error))
{ if (cogl_texture_allocate (COGL_TEXTURE (atlas_tex), &internal_error))
return COGL_TEXTURE (atlas_tex); return COGL_TEXTURE (atlas_tex);
}
cogl_error_free (internal_error); cogl_error_free (internal_error);
cogl_object_unref (atlas_tex);
internal_error = NULL; internal_error = NULL;
} }
@ -451,9 +451,9 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
(cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) && (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP))) cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP)))
{ {
tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap, tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap));
internal_format,
&internal_error)); cogl_texture_set_premultiplied (tex, premultiplied);
if (cogl_error_matches (internal_error, if (cogl_error_matches (internal_error,
COGL_SYSTEM_ERROR, COGL_SYSTEM_ERROR,
@ -478,12 +478,10 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ? int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ?
-1 : COGL_TEXTURE_MAX_WASTE; -1 : COGL_TEXTURE_MAX_WASTE;
CoglTexture2DSliced *tex_2ds = CoglTexture2DSliced *tex_2ds =
cogl_texture_2d_sliced_new_from_bitmap (bitmap, cogl_texture_2d_sliced_new_from_bitmap (bitmap, max_waste);
max_waste,
internal_format,
NULL); /* don't catch
exceptions */
tex = COGL_TEXTURE (tex_2ds); tex = COGL_TEXTURE (tex_2ds);
cogl_texture_set_premultiplied (tex, premultiplied);
} }
if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP) if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
@ -507,7 +505,6 @@ test_utils_texture_new_from_data (CoglContext *ctx,
int height, int height,
TestUtilsTextureFlags flags, TestUtilsTextureFlags flags,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data) const uint8_t *data)
{ {
@ -524,7 +521,7 @@ test_utils_texture_new_from_data (CoglContext *ctx,
rowstride, rowstride,
(uint8_t *) data); (uint8_t *) data);
tex = test_utils_texture_new_from_bitmap (bmp, flags, internal_format); tex = test_utils_texture_new_from_bitmap (bmp, flags, TRUE);
cogl_object_unref (bmp); cogl_object_unref (bmp);

View file

@ -81,8 +81,7 @@ test_utils_fini (void);
* @width: width of texture in pixels. * @width: width of texture in pixels.
* @height: height of texture in pixels. * @height: height of texture in pixels.
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE * @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the * @components: What texture components are required
* texture.
* *
* Creates a new #CoglTexture with the specified dimensions and pixel format. * Creates a new #CoglTexture with the specified dimensions and pixel format.
* *
@ -100,7 +99,7 @@ test_utils_texture_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height,
TestUtilsTextureFlags flags, TestUtilsTextureFlags flags,
CoglPixelFormat internal_format); CoglTextureComponents components);
/* /*
* test_utils_texture_new_from_data: * test_utils_texture_new_from_data:
@ -109,14 +108,6 @@ test_utils_texture_new_with_size (CoglContext *ctx,
* @height: height of texture in pixels * @height: height of texture in pixels
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE * @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @format: the #CoglPixelFormat the buffer is stored in in RAM * @format: the #CoglPixelFormat the buffer is stored in in RAM
* @internal_format: the #CoglPixelFormat that will be used for storing
* the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a
* premultiplied format similar to the format of the source data will
* be used. The default blending equations of Cogl expect premultiplied
* color data; the main use of passing a non-premultiplied format here
* is if you have non-premultiplied source data and are going to adjust
* the blend mode (see cogl_material_set_blend()) or use the data for
* something other than straight blending.
* @rowstride: the memory offset in bytes between the starts of * @rowstride: the memory offset in bytes between the starts of
* scanlines in @data * scanlines in @data
* @data: pointer the memory region where the source buffer resides * @data: pointer the memory region where the source buffer resides
@ -124,6 +115,13 @@ test_utils_texture_new_with_size (CoglContext *ctx,
* *
* Creates a new #CoglTexture based on data residing in memory. * Creates a new #CoglTexture based on data residing in memory.
* *
* Note: If the given @format has an alpha channel then the data
* will be loaded into a premultiplied internal format. If you want
* to avoid having the source data be premultiplied then you can
* either specify that the data is already premultiplied or use
* test_utils_texture_new_from_bitmap which lets you explicitly
* request whether the data should internally be premultipled or not.
*
* Return value: A newly created #CoglTexture or %NULL on failure * Return value: A newly created #CoglTexture or %NULL on failure
*/ */
CoglTexture * CoglTexture *
@ -132,7 +130,6 @@ test_utils_texture_new_from_data (CoglContext *ctx,
int height, int height,
TestUtilsTextureFlags flags, TestUtilsTextureFlags flags,
CoglPixelFormat format, CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride, int rowstride,
const uint8_t *data); const uint8_t *data);
@ -140,9 +137,12 @@ test_utils_texture_new_from_data (CoglContext *ctx,
* test_utils_texture_new_from_bitmap: * test_utils_texture_new_from_bitmap:
* @bitmap: A #CoglBitmap pointer * @bitmap: A #CoglBitmap pointer
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE * @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the * @premultiplied: Whether the texture should hold premultipled data.
* texture * (if the bitmap already holds premultiplied data
* @error: A #CoglError to catch exceptional errors or %NULL * and %TRUE is given then no premultiplication will
* be done. The data will be premultipled while
* uploading if the bitmap has an alpha channel but
* does not already have a premultiplied format.)
* *
* Creates a #CoglTexture from a #CoglBitmap. * Creates a #CoglTexture from a #CoglBitmap.
* *
@ -151,7 +151,7 @@ test_utils_texture_new_from_data (CoglContext *ctx,
CoglTexture * CoglTexture *
test_utils_texture_new_from_bitmap (CoglBitmap *bitmap, test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
TestUtilsTextureFlags flags, TestUtilsTextureFlags flags,
CoglPixelFormat internal_format); CoglBool premultiplied);
/* /*
* test_utils_check_pixel: * test_utils_check_pixel:

View file

@ -15,7 +15,6 @@ create_texture (CoglContext *context)
return cogl_texture_2d_new_from_data (context, return cogl_texture_2d_new_from_data (context,
2, 1, /* width/height */ 2, 1, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
4, /* rowstride */ 4, /* rowstride */
data, data,
NULL /* error */); NULL /* error */);

View file

@ -16,7 +16,6 @@ create_pipeline (CoglTexture **tex_out,
tex = cogl_texture_2d_new_from_data (test_ctx, tex = cogl_texture_2d_new_from_data (test_ctx,
2, 2, /* width/height */ 2, 2, /* width/height */
COGL_PIXEL_FORMAT_A_8, /* format */ COGL_PIXEL_FORMAT_A_8, /* format */
COGL_PIXEL_FORMAT_ANY, /* int. format */
2, /* rowstride */ 2, /* rowstride */
tex_data, tex_data,
NULL); NULL);

View file

@ -58,9 +58,7 @@ create_texture (int size)
size, /* height */ size, /* height */
TEST_UTILS_TEXTURE_NONE, /* flags */ TEST_UTILS_TEXTURE_NONE, /* flags */
/* format */ /* format */
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
/* internal format */
COGL_PIXEL_FORMAT_RGBA_8888,
/* rowstride */ /* rowstride */
size * 4, size * 4,
data); data);
@ -82,7 +80,7 @@ verify_texture (CoglTexture *texture, int size)
p = data = g_malloc (size * size * 4); p = data = g_malloc (size * size * 4);
cogl_texture_get_data (texture, cogl_texture_get_data (texture,
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
size * 4, size * 4,
data); data);

View file

@ -271,7 +271,6 @@ make_texture (void)
TEXTURE_SIZE, TEXTURE_SIZE,
TEST_UTILS_TEXTURE_NO_ATLAS, TEST_UTILS_TEXTURE_NO_ATLAS,
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY,
TEXTURE_SIZE * 4, TEXTURE_SIZE * 4,
tex_data); tex_data);
@ -296,8 +295,7 @@ test_backface_culling (void)
tex = test_utils_texture_new_with_size (test_ctx, tex = test_utils_texture_new_with_size (test_ctx,
state.width, state.height, state.width, state.height,
TEST_UTILS_TEXTURE_NO_SLICING, TEST_UTILS_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY); /* internal COGL_TEXTURE_COMPONENTS_RGBA);
format */
state.offscreen = cogl_offscreen_new_with_texture (tex); state.offscreen = cogl_offscreen_new_with_texture (tex);
state.offscreen_tex = tex; state.offscreen_tex = tex;

View file

@ -194,14 +194,13 @@ make_texture (uint32_t color)
*(--p) = r; *(--p) = r;
} }
/* Note: we don't use COGL_PIXEL_FORMAT_ANY for the internal format here /* Note: we claim that the data is premultiplied so that Cogl won't
* since we don't want to allow Cogl to premultiply our data. */ * premultiply the data on upload */
tex = test_utils_texture_new_from_data (test_ctx, tex = test_utils_texture_new_from_data (test_ctx,
QUAD_WIDTH, QUAD_WIDTH,
QUAD_WIDTH, QUAD_WIDTH,
TEST_UTILS_TEXTURE_NONE, TEST_UTILS_TEXTURE_NONE,
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888,
QUAD_WIDTH * 4, QUAD_WIDTH * 4,
tex_data); tex_data);

View file

@ -83,7 +83,7 @@ test_color_mask (void)
{ {
state.tex[i] = test_utils_texture_new_with_size (test_ctx, 128, 128, state.tex[i] = test_utils_texture_new_with_size (test_ctx, 128, 128,
TEST_UTILS_TEXTURE_NO_ATLAS, TEST_UTILS_TEXTURE_NO_ATLAS,
COGL_PIXEL_FORMAT_RGB_888); COGL_TEXTURE_COMPONENTS_RGB);
state.fbo[i] = cogl_offscreen_new_with_texture (state.tex[i]); state.fbo[i] = cogl_offscreen_new_with_texture (state.tex[i]);

View file

@ -37,7 +37,6 @@ create_texture (void)
tex_2d = cogl_texture_2d_new_from_data (test_ctx, tex_2d = cogl_texture_2d_new_from_data (test_ctx,
1, 1, /* width / height */ 1, 1, /* width / height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
4, /* rowstride */ 4, /* rowstride */
data, data,
NULL); NULL);

View file

@ -7,19 +7,19 @@ test_framebuffer_get_bits (void)
{ {
CoglTexture2D *tex_a = CoglTexture2D *tex_a =
cogl_texture_2d_new_with_size (test_ctx, cogl_texture_2d_new_with_size (test_ctx,
16, 16, /* width/height */ 16, 16); /* width/height */
COGL_PIXEL_FORMAT_A_8);
CoglOffscreen *offscreen_a = CoglOffscreen *offscreen_a =
cogl_offscreen_new_with_texture (tex_a); cogl_offscreen_new_with_texture (tex_a);
CoglFramebuffer *fb_a = offscreen_a; CoglFramebuffer *fb_a = offscreen_a;
CoglTexture2D *tex_rgba = CoglTexture2D *tex_rgba =
cogl_texture_2d_new_with_size (test_ctx, cogl_texture_2d_new_with_size (test_ctx,
16, 16, /* width/height */ 16, 16); /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888);
CoglOffscreen *offscreen_rgba = CoglOffscreen *offscreen_rgba =
cogl_offscreen_new_with_texture (tex_rgba); cogl_offscreen_new_with_texture (tex_rgba);
CoglFramebuffer *fb_rgba = offscreen_rgba; CoglFramebuffer *fb_rgba = offscreen_rgba;
cogl_texture_set_components (tex_a,
COGL_TEXTURE_COMPONENTS_A);
cogl_framebuffer_allocate (fb_a, NULL); cogl_framebuffer_allocate (fb_a, NULL);
cogl_framebuffer_allocate (fb_rgba, NULL); cogl_framebuffer_allocate (fb_rgba, NULL);

View file

@ -26,8 +26,7 @@ test_push_pop_single_context (void)
offscreen_texture = offscreen_texture =
cogl_texture_2d_new_with_size (test_ctx, cogl_texture_2d_new_with_size (test_ctx,
cogl_framebuffer_get_width (test_fb), cogl_framebuffer_get_width (test_fb),
cogl_framebuffer_get_height (test_fb), cogl_framebuffer_get_height (test_fb));
COGL_PIXEL_FORMAT_ANY);
offscreen = cogl_offscreen_new_with_texture (offscreen_texture); offscreen = cogl_offscreen_new_with_texture (offscreen_texture);
pipeline = cogl_pipeline_new (test_ctx); pipeline = cogl_pipeline_new (test_ctx);
@ -150,8 +149,7 @@ create_gles2_context (CoglTexture **offscreen_texture,
*offscreen_texture = *offscreen_texture =
cogl_texture_2d_new_with_size (test_ctx, cogl_texture_2d_new_with_size (test_ctx,
cogl_framebuffer_get_width (test_fb), cogl_framebuffer_get_width (test_fb),
cogl_framebuffer_get_height (test_fb), cogl_framebuffer_get_height (test_fb));
COGL_PIXEL_FORMAT_ANY);
*offscreen = cogl_offscreen_new_with_texture (*offscreen_texture); *offscreen = cogl_offscreen_new_with_texture (*offscreen_texture);
*pipeline = cogl_pipeline_new (test_ctx); *pipeline = cogl_pipeline_new (test_ctx);

View file

@ -22,7 +22,6 @@ create_dummy_texture (void)
1, 1, /* size */ 1, 1, /* size */
TEST_UTILS_TEXTURE_NONE, TEST_UTILS_TEXTURE_NONE,
COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_RGB_888,
COGL_PIXEL_FORMAT_ANY,
4, /* rowstride */ 4, /* rowstride */
data); data);
} }

View file

@ -37,7 +37,6 @@ test_map_buffer_range (void)
tex = cogl_texture_2d_new_from_data (test_ctx, tex = cogl_texture_2d_new_from_data (test_ctx,
2, 2, /* width/height */ 2, 2, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
2 * 4, /* rowstride */ 2 * 4, /* rowstride */
tex_data, tex_data,
NULL /* error */); NULL /* error */);

View file

@ -92,7 +92,6 @@ make_texture (void)
TEXTURE_SIZE, TEXTURE_SIZE,
TEST_UTILS_TEXTURE_NO_ATLAS, TEST_UTILS_TEXTURE_NO_ATLAS,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
TEXTURE_SIZE * 4, TEXTURE_SIZE * 4,
tex_data); tex_data);

View file

@ -46,8 +46,7 @@ test_paint (TestState *state)
tex_2d = cogl_texture_2d_new_with_size (test_ctx, tex_2d = cogl_texture_2d_new_with_size (test_ctx,
state->fb_width, state->fb_width,
state->fb_height, state->fb_height);
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
tex = tex_2d; tex = tex_2d;
offscreen = cogl_offscreen_new_with_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
@ -127,8 +126,7 @@ test_flush (TestState *state)
journal */ journal */
tex_2d = cogl_texture_2d_new_with_size (test_ctx, tex_2d = cogl_texture_2d_new_with_size (test_ctx,
16, 16, /* width/height */ 16, 16); /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
tex = tex_2d; tex = tex_2d;
offscreen = cogl_offscreen_new_with_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);

View file

@ -25,7 +25,6 @@ create_texture (void)
tex_2d = cogl_texture_2d_new_from_data (test_ctx, tex_2d = cogl_texture_2d_new_from_data (test_ctx,
1, 1, /* width / height */ 1, 1, /* width / height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
4, /* rowstride */ 4, /* rowstride */
data, data,
NULL); NULL);

View file

@ -22,8 +22,7 @@ test_pipeline_shader_state (void)
-1, -1,
100); 100);
tex = cogl_texture_2d_new_with_size (test_ctx, tex = cogl_texture_2d_new_with_size (test_ctx, 128, 128);
128, 128, COGL_PIXEL_FORMAT_ANY);
offscreen = cogl_offscreen_new_with_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
fb = offscreen; fb = offscreen;
cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1); cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);

View file

@ -79,9 +79,7 @@ create_texture_from_bitmap (CoglBitmap *bitmap)
{ {
CoglTexture2D *texture; CoglTexture2D *texture;
texture = cogl_texture_2d_new_from_bitmap (bitmap, texture = cogl_texture_2d_new_from_bitmap (bitmap);
COGL_PIXEL_FORMAT_RGBA_8888,
NULL); /* don't catch errors */
g_assert (texture != NULL); g_assert (texture != NULL);
@ -221,7 +219,6 @@ create_white_texture (void)
BITMAP_SIZE, BITMAP_SIZE,
BITMAP_SIZE, BITMAP_SIZE,
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY,
BITMAP_SIZE * 4, /* rowstride */ BITMAP_SIZE * 4, /* rowstride */
data, data,
NULL); /* don't catch errors */ NULL); /* don't catch errors */

View file

@ -51,7 +51,6 @@ do_test (CoglBool check_orientation,
tex_2d = cogl_texture_2d_new_from_data (test_ctx, tex_2d = cogl_texture_2d_new_from_data (test_ctx,
2, tex_height, /* width/height */ 2, tex_height, /* width/height */
COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_RGB_888,
COGL_PIXEL_FORMAT_ANY,
6, /* row stride */ 6, /* row stride */
tex_data, tex_data,
&error); &error);

View file

@ -16,6 +16,12 @@
#define MASK_BLUE(COLOR) ((COLOR & 0xff00) >> 8) #define MASK_BLUE(COLOR) ((COLOR & 0xff00) >> 8)
#define MASK_ALPHA(COLOR) (COLOR & 0xff) #define MASK_ALPHA(COLOR) (COLOR & 0xff)
typedef enum _MakeTextureFlags
{
TEXTURE_FLAG_SET_PREMULTIPLIED = 1,
TEXTURE_FLAG_SET_UNPREMULTIPLIED = 1<<1,
} MakeTextureFlags;
static guchar * static guchar *
gen_tex_data (uint32_t color) gen_tex_data (uint32_t color)
{ {
@ -41,20 +47,25 @@ gen_tex_data (uint32_t color)
static CoglTexture * static CoglTexture *
make_texture (uint32_t color, make_texture (uint32_t color,
CoglPixelFormat src_format, CoglPixelFormat src_format,
CoglPixelFormat internal_format) MakeTextureFlags flags)
{ {
CoglTexture2D *tex_2d; CoglTexture2D *tex_2d;
guchar *tex_data = gen_tex_data (color); guchar *tex_data = gen_tex_data (color);
CoglBitmap *bmp = cogl_bitmap_new_for_data (test_ctx,
QUAD_WIDTH,
QUAD_WIDTH,
src_format,
QUAD_WIDTH * 4,
tex_data);
tex_2d = cogl_texture_2d_new_from_data (test_ctx, tex_2d = cogl_texture_2d_new_from_bitmap (bmp);
QUAD_WIDTH,
QUAD_WIDTH,
src_format,
internal_format,
QUAD_WIDTH * 4,
tex_data,
NULL);
if (flags & TEXTURE_FLAG_SET_PREMULTIPLIED)
cogl_texture_set_premultiplied (tex_2d, TRUE);
else if (flags & TEXTURE_FLAG_SET_UNPREMULTIPLIED)
cogl_texture_set_premultiplied (tex_2d, FALSE);
cogl_object_unref (bmp);
g_free (tex_data); g_free (tex_data);
return tex_2d; return tex_2d;
@ -144,7 +155,7 @@ test_premult (void)
"src = RGBA_8888, internal = RGBA_8888)\n"); "src = RGBA_8888, internal = RGBA_8888)\n");
tex = make_texture (0xff00ff80, tex = make_texture (0xff00ff80,
COGL_PIXEL_FORMAT_RGBA_8888, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888, /* src format */
COGL_PIXEL_FORMAT_RGBA_8888); /* internal format */ TEXTURE_FLAG_SET_UNPREMULTIPLIED);
check_texture (pipeline, material, 0, 0, /* position */ check_texture (pipeline, material, 0, 0, /* position */
tex, tex,
0xff00ff80); /* expected */ 0xff00ff80); /* expected */
@ -157,21 +168,21 @@ test_premult (void)
"src = RGBA_8888, internal = RGBA_8888_PRE)\n"); "src = RGBA_8888, internal = RGBA_8888_PRE)\n");
tex = make_texture (0xff00ff80, tex = make_texture (0xff00ff80,
COGL_PIXEL_FORMAT_RGBA_8888, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888, /* src format */
COGL_PIXEL_FORMAT_RGBA_8888_PRE); /* internal format */ TEXTURE_FLAG_SET_PREMULTIPLIED);
check_texture (pipeline, material, 1, 0, /* position */ check_texture (pipeline, material, 1, 0, /* position */
tex, tex,
0x80008080); /* expected */ 0x80008080); /* expected */
/* If the user gives COGL_PIXEL_FORMAT_ANY for the internal format then /* If the user doesn't explicitly declare that the texture is premultiplied
* by default Cogl should premultiply the given texture data... * then Cogl should assume it is by default should premultiply
* (In the future there will be additional Cogl API to control this * unpremultiplied texture data...
* behaviour) */ */
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("make_texture (0xff00ff80, " g_print ("make_texture (0xff00ff80, "
"src = RGBA_8888, internal = ANY)\n"); "src = RGBA_8888, internal = ANY)\n");
tex = make_texture (0xff00ff80, tex = make_texture (0xff00ff80,
COGL_PIXEL_FORMAT_RGBA_8888, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888, /* src format */
COGL_PIXEL_FORMAT_ANY); /* internal format */ 0); /* default premultiplied status */
check_texture (pipeline, material, 2, 0, /* position */ check_texture (pipeline, material, 2, 0, /* position */
tex, tex,
0x80008080); /* expected */ 0x80008080); /* expected */
@ -185,7 +196,7 @@ test_premult (void)
"internal = RGBA_8888_PRE)\n"); "internal = RGBA_8888_PRE)\n");
tex = make_texture (0x80008080, tex = make_texture (0x80008080,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */
COGL_PIXEL_FORMAT_RGBA_8888_PRE); /* internal format */ TEXTURE_FLAG_SET_PREMULTIPLIED);
check_texture (pipeline, material, 3, 0, /* position */ check_texture (pipeline, material, 3, 0, /* position */
tex, tex,
0x80008080); /* expected */ 0x80008080); /* expected */
@ -198,7 +209,7 @@ test_premult (void)
"src = RGBA_8888_PRE, internal = RGBA_8888)\n"); "src = RGBA_8888_PRE, internal = RGBA_8888)\n");
tex = make_texture (0x80008080, tex = make_texture (0x80008080,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */
COGL_PIXEL_FORMAT_RGBA_8888); /* internal format */ TEXTURE_FLAG_SET_UNPREMULTIPLIED);
check_texture (pipeline, material, 4, 0, /* position */ check_texture (pipeline, material, 4, 0, /* position */
tex, tex,
0xff00ff80); /* expected */ 0xff00ff80); /* expected */
@ -212,7 +223,7 @@ test_premult (void)
"src = RGBA_8888_PRE, internal = ANY)\n"); "src = RGBA_8888_PRE, internal = ANY)\n");
tex = make_texture (0x80008080, tex = make_texture (0x80008080,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */
COGL_PIXEL_FORMAT_ANY); /* internal format */ 0); /* default premultiplied status */
check_texture (pipeline, material, 5, 0, /* position */ check_texture (pipeline, material, 5, 0, /* position */
tex, tex,
0x80008080); /* expected */ 0x80008080); /* expected */
@ -226,7 +237,7 @@ test_premult (void)
"src = RGBA_8888, internal = RGBA_8888)\n"); "src = RGBA_8888, internal = RGBA_8888)\n");
tex = make_texture (0xDEADBEEF, tex = make_texture (0xDEADBEEF,
COGL_PIXEL_FORMAT_RGBA_8888, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888, /* src format */
COGL_PIXEL_FORMAT_RGBA_8888); /* internal format */ TEXTURE_FLAG_SET_UNPREMULTIPLIED);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("set_region (0xff00ff80, RGBA_8888)\n"); g_print ("set_region (0xff00ff80, RGBA_8888)\n");
set_region (tex, 0xff00ff80, COGL_PIXEL_FORMAT_RGBA_8888); set_region (tex, 0xff00ff80, COGL_PIXEL_FORMAT_RGBA_8888);
@ -242,7 +253,7 @@ test_premult (void)
"src = RGBA_8888, internal = RGBA_8888)\n"); "src = RGBA_8888, internal = RGBA_8888)\n");
tex = make_texture (0xDEADBEEF, tex = make_texture (0xDEADBEEF,
COGL_PIXEL_FORMAT_RGBA_8888, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888, /* src format */
COGL_PIXEL_FORMAT_RGBA_8888); /* internal format */ TEXTURE_FLAG_SET_UNPREMULTIPLIED);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("set_region (0x80008080, RGBA_8888_PRE)\n"); g_print ("set_region (0x80008080, RGBA_8888_PRE)\n");
set_region (tex, 0x80008080, COGL_PIXEL_FORMAT_RGBA_8888_PRE); set_region (tex, 0x80008080, COGL_PIXEL_FORMAT_RGBA_8888_PRE);
@ -257,7 +268,7 @@ test_premult (void)
"internal = RGBA_8888_PRE)\n"); "internal = RGBA_8888_PRE)\n");
tex = make_texture (0xDEADBEEF, tex = make_texture (0xDEADBEEF,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */
COGL_PIXEL_FORMAT_RGBA_8888_PRE); /* internal format */ TEXTURE_FLAG_SET_PREMULTIPLIED);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("set_region (0x80008080, RGBA_8888_PRE)\n"); g_print ("set_region (0x80008080, RGBA_8888_PRE)\n");
set_region (tex, 0x80008080, COGL_PIXEL_FORMAT_RGBA_8888_PRE); set_region (tex, 0x80008080, COGL_PIXEL_FORMAT_RGBA_8888_PRE);
@ -275,7 +286,7 @@ test_premult (void)
"internal = RGBA_8888_PRE)\n"); "internal = RGBA_8888_PRE)\n");
tex = make_texture (0xDEADBEEF, tex = make_texture (0xDEADBEEF,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, /* src format */
COGL_PIXEL_FORMAT_RGBA_8888_PRE); /* internal format */ TEXTURE_FLAG_SET_PREMULTIPLIED);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("set_region (0xff00ff80, RGBA_8888)\n"); g_print ("set_region (0xff00ff80, RGBA_8888)\n");
set_region (tex, 0xff00ff80, COGL_PIXEL_FORMAT_RGBA_8888); set_region (tex, 0xff00ff80, COGL_PIXEL_FORMAT_RGBA_8888);

View file

@ -174,7 +174,6 @@ test_paint (TestState *state)
2, 1, /* size */ 2, 1, /* size */
TEST_UTILS_TEXTURE_NO_ATLAS, TEST_UTILS_TEXTURE_NO_ATLAS,
COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_RGB_888,
COGL_PIXEL_FORMAT_ANY,
6, /* rowstride */ 6, /* rowstride */
tex_data); tex_data);
pipeline = cogl_pipeline_new (test_ctx); pipeline = cogl_pipeline_new (test_ctx);

View file

@ -149,7 +149,6 @@ test_read_texture_formats (void)
tex_2d = cogl_texture_2d_new_from_data (test_ctx, tex_2d = cogl_texture_2d_new_from_data (test_ctx,
1, 1, /* width / height */ 1, 1, /* width / height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */ 4, /* rowstride */
tex_data, tex_data,
NULL); NULL);

View file

@ -26,7 +26,6 @@ create_texture_pipeline (TestState *state)
2, 2, /* width/height */ 2, 2, /* width/height */
TEST_UTILS_TEXTURE_NO_ATLAS, TEST_UTILS_TEXTURE_NO_ATLAS,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
8, /* rowstride */ 8, /* rowstride */
tex_data); tex_data);

View file

@ -57,7 +57,6 @@ create_source (TestState *state)
tex = cogl_texture_2d_new_from_data (test_ctx, tex = cogl_texture_2d_new_from_data (test_ctx,
SOURCE_SIZE, SOURCE_SIZE, SOURCE_SIZE, SOURCE_SIZE,
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY,
SOURCE_SIZE * 4, SOURCE_SIZE * 4,
data, data,
NULL); NULL);
@ -87,7 +86,6 @@ create_test_texture (TestState *state)
tex = cogl_texture_2d_new_from_data (test_ctx, tex = cogl_texture_2d_new_from_data (test_ctx,
256, 256, 256, 256,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
256 * 4, 256 * 4,
data, data,
NULL); NULL);

View file

@ -52,7 +52,6 @@ create_texture_3d (CoglContext *context)
tex = cogl_texture_3d_new_from_data (context, tex = cogl_texture_3d_new_from_data (context,
TEX_WIDTH, TEX_HEIGHT, TEX_DEPTH, TEX_WIDTH, TEX_HEIGHT, TEX_DEPTH,
COGL_PIXEL_FORMAT_RGBA_8888, COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY,
TEX_ROWSTRIDE, TEX_ROWSTRIDE,
TEX_IMAGE_STRIDE, TEX_IMAGE_STRIDE,
data, data,
@ -217,7 +216,6 @@ test_multi_texture (TestState *state)
tex_2d = cogl_texture_2d_new_from_data (test_ctx, tex_2d = cogl_texture_2d_new_from_data (test_ctx,
1, 1, /* width/height */ 1, 1, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */ 4, /* rowstride */
tex_data, tex_data,
NULL); NULL);
@ -230,7 +228,6 @@ test_multi_texture (TestState *state)
tex_3d = cogl_texture_3d_new_from_data (test_ctx, tex_3d = cogl_texture_3d_new_from_data (test_ctx,
1, 1, 1, /* width/height/depth */ 1, 1, 1, /* width/height/depth */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */ 4, /* rowstride */
4, /* image_stride */ 4, /* image_stride */
tex_data, tex_data,

View file

@ -11,6 +11,7 @@ check_texture (int width, int height, TestUtilsTextureFlags flags)
uint8_t *data, *p; uint8_t *data, *p;
int y, x; int y, x;
int rowstride; int rowstride;
CoglBitmap *bmp;
p = data = g_malloc (width * height * 4); p = data = g_malloc (width * height * 4);
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
@ -22,13 +23,14 @@ check_texture (int width, int height, TestUtilsTextureFlags flags)
*(p++) = (x ^ y); *(p++) = (x ^ y);
} }
tex = test_utils_texture_new_from_data (test_ctx, bmp = cogl_bitmap_new_for_data (test_ctx,
width, height, width, height,
flags, COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_RGBA_8888, width * 4,
COGL_PIXEL_FORMAT_RGBA_8888, data);
width * 4,
data); tex = test_utils_texture_new_from_bitmap (bmp, flags,
FALSE);
/* Replace the bottom right quarter of the data with negated data to /* Replace the bottom right quarter of the data with negated data to
test set_region */ test set_region */

View file

@ -32,8 +32,6 @@ test_texture_no_allocate (void)
BIG_TEX_HEIGHT, BIG_TEX_HEIGHT,
/* format */ /* format */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
/* internal format */
COGL_PIXEL_FORMAT_ANY,
/* rowstride */ /* rowstride */
BIG_TEX_WIDTH * 4, BIG_TEX_WIDTH * 4,
tex_data, tex_data,
@ -54,14 +52,12 @@ test_texture_no_allocate (void)
cogl_texture_2d_sliced_new_with_size (test_ctx, cogl_texture_2d_sliced_new_with_size (test_ctx,
BIG_TEX_WIDTH, BIG_TEX_WIDTH,
BIG_TEX_HEIGHT, BIG_TEX_HEIGHT,
COGL_TEXTURE_MAX_WASTE, COGL_TEXTURE_MAX_WASTE);
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
cogl_object_unref (texture); cogl_object_unref (texture);
/* 2D texture */ /* 2D texture */
texture_2d = cogl_texture_2d_new_with_size (test_ctx, texture_2d = cogl_texture_2d_new_with_size (test_ctx,
64, 64, 64, 64);
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
cogl_object_unref (texture_2d); cogl_object_unref (texture_2d);
/* 3D texture */ /* 3D texture */
@ -69,8 +65,7 @@ test_texture_no_allocate (void)
{ {
CoglTexture3D *texture_3d = CoglTexture3D *texture_3d =
cogl_texture_3d_new_with_size (test_ctx, cogl_texture_3d_new_with_size (test_ctx,
64, 64, 64, 64, 64, 64);
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
cogl_object_unref (texture_3d); cogl_object_unref (texture_3d);
} }

View file

@ -33,7 +33,6 @@ create_texture (TestUtilsTextureFlags flags)
tex = test_utils_texture_new_from_data (test_ctx, tex = test_utils_texture_new_from_data (test_ctx,
TEX_SIZE, TEX_SIZE, flags, TEX_SIZE, TEX_SIZE, flags,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
TEX_SIZE * 4, TEX_SIZE * 4,
data); data);
g_free (data); g_free (data);

View file

@ -24,10 +24,7 @@ create_base_pipeline (void)
2 * 3, /* rowstride */ 2 * 3, /* rowstride */
tex_data); tex_data);
tex = cogl_texture_rectangle_new_from_bitmap (bmp, tex = cogl_texture_rectangle_new_from_bitmap (bmp);
/* internal format */
COGL_PIXEL_FORMAT_ANY,
NULL);
cogl_object_unref (bmp); cogl_object_unref (bmp);