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 height,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data,
CoglError **error)
const uint8_t *data)
{
CoglBitmap *bitmap;
CoglTexture *tex;
@ -489,9 +487,7 @@ video_texture_new_from_data (CoglContext *ctx,
is_pot (cogl_bitmap_get_height (bitmap))) ||
cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC))
{
tex = cogl_texture_2d_new_from_bitmap (bitmap,
internal_format,
&internal_error);
tex = cogl_texture_2d_new_from_bitmap (bitmap);
if (!tex)
{
cogl_error_free (internal_error);
@ -504,12 +500,8 @@ video_texture_new_from_data (CoglContext *ctx,
if (!tex)
{
/* Otherwise create a sliced texture */
CoglTexture2DSliced *tex_2ds =
cogl_texture_2d_sliced_new_from_bitmap (bitmap,
-1, /* no maximum waste */
internal_format,
error);
tex = tex_2ds;
tex = cogl_texture_2d_sliced_new_from_bitmap (bitmap,
-1); /* no maximum waste */
}
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->info.height,
format, format,
format,
priv->info.stride[0],
frame.data[0], NULL);
frame.data[0]);
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->info.height,
format, format,
format,
priv->info.stride[0],
frame.data[0], NULL);
frame.data[0]);
gst_video_frame_unmap (&frame);
@ -626,22 +618,22 @@ cogl_gst_yv12_upload (CoglGstVideoSink *sink,
video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 0),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 0),
format, format,
priv->info.stride[0], frame.data[0], NULL);
format,
priv->info.stride[0], frame.data[0]);
priv->frame[2] =
video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 1),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 1),
format, format,
priv->info.stride[1], frame.data[1], NULL);
format,
priv->info.stride[1], frame.data[1]);
priv->frame[1] =
video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 2),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 2),
format, format,
priv->info.stride[2], frame.data[2], NULL);
format,
priv->info.stride[2], frame.data[2]);
gst_video_frame_unmap (&frame);
@ -671,22 +663,22 @@ cogl_gst_i420_upload (CoglGstVideoSink *sink,
video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 0),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 0),
format, format,
priv->info.stride[0], frame.data[0], NULL);
format,
priv->info.stride[0], frame.data[0]);
priv->frame[1] =
video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 1),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 1),
format, format,
priv->info.stride[1], frame.data[1], NULL);
format,
priv->info.stride[1], frame.data[1]);
priv->frame[2] =
video_texture_new_from_data (priv->ctx,
GST_VIDEO_INFO_COMP_WIDTH (&priv->info, 2),
GST_VIDEO_INFO_COMP_HEIGHT (&priv->info, 2),
format, format,
priv->info.stride[2], frame.data[2], NULL);
format,
priv->info.stride[2], frame.data[2]);
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->info.height,
format, format,
format,
priv->info.stride[0],
frame.data[0], NULL);
frame.data[0]);
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,
value->draw_width,
value->draw_height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
&ignore_error);
if (texture == NULL)
value->draw_height);
if (!cogl_texture_allocate (COGL_TEXTURE (texture), &ignore_error))
{
cogl_error_free (ignore_error);
return FALSE;

View file

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

View file

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

View file

@ -67,7 +67,6 @@ typedef struct _CoglAtlasTexture CoglAtlasTexture;
* @ctx: A #CoglContext
* @width: The width 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
* #CoglAtlasTexture represents a sub-region within one of Cogl's
@ -83,32 +82,28 @@ typedef struct _CoglAtlasTexture CoglAtlasTexture;
* using cogl_texture_set_components() and
* cogl_texture_set_premultiplied().
*
* <note>This call can fail if Cogl considers the given
* @internal_format incompatible with the format of its internal
* <note>Allocate call can fail if Cogl considers the internal
* format to be incompatible with the format of its internal
* atlases.</note>
*
* <note>The returned #CoglAtlasTexture is a high-level meta-texture
* with some limitations. See the documentation for #CoglMetaTexture
* for more details.</note>
*
* Return value: (transfer full): A new #CoglAtlasTexture object with
* no storage allocated yet or %NULL on failure and @error
* will be updated.
* Returns: (transfer full): A new #CoglAtlasTexture object.
* Since: 1.16
* Stability: unstable
*/
CoglAtlasTexture *
cogl_atlas_texture_new_with_size (CoglContext *ctx,
int width,
int height,
CoglPixelFormat internal_format,
CoglError **error);
int height);
/**
* cogl_atlas_texture_new_from_file:
* @ctx: A #CoglContext
* @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
* 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
* cogl_texture_set_premultiplied().
*
* <note>Allocation can fail later if Cogl considers the given
* @internal_format incompatible with the format of its internal
* <note>Allocate call can fail if Cogl considers the internal
* format to be incompatible with the format of its internal
* atlases.</note>
*
* <note>The returned #CoglAtlasTexture is a high-level meta-texture
@ -140,7 +135,6 @@ cogl_atlas_texture_new_with_size (CoglContext *ctx,
CoglAtlasTexture *
cogl_atlas_texture_new_from_file (CoglContext *ctx,
const char *filename,
CoglPixelFormat internal_format,
CoglError **error);
/**
@ -149,14 +143,6 @@ cogl_atlas_texture_new_from_file (CoglContext *ctx,
* @width: width of texture in pixels
* @height: height of texture in pixels
* @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
* row in @data. A value of 0 will make Cogl automatically
* 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_texture_set_data()</note>
*
* <note>Allocation can fail if Cogl considers the given
* @internal_format incompatible with the format of its internal
* <note>Allocate call can fail if Cogl considers the internal
* format to be incompatible with the format of its internal
* atlases.</note>
*
* <note>The returned #CoglAtlasTexture is a high-level
@ -196,23 +182,13 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
int width,
int height,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data,
CoglError **error);
/**
* cogl_atlas_texture_new_from_bitmap:
* @bmp: 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
* @bitmap: A #CoglBitmap
*
* Creates a new #CoglAtlasTexture texture based on data residing in a
* @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
* cogl_texture_set_premultiplied().
*
* <note>Allocation can fail if Cogl considers the given
* @internal_format incompatible with the format of its internal
* <note>Allocate call can fail if Cogl considers the internal
* format to be incompatible with the format of its internal
* atlases.</note>
*
* <note>The returned #CoglAtlasTexture is a high-level meta-texture
* with some limitations. See the documentation for #CoglMetaTexture
* for more details.</note>
*
* Return value: (transfer full): A new #CoglAtlasTexture object or
* %NULL on failure and @error will be updated.
* Returns: (transfer full): A new #CoglAtlasTexture object.
* Since: 1.16
* Stability: unstable
*/
CoglAtlasTexture *
cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format,
CoglError **error);
cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp);
/**
* cogl_is_atlas_texture:

View file

@ -299,11 +299,17 @@ _cogl_atlas_create_texture (CoglAtlas *atlas,
width * bpp,
clear_data);
tex = cogl_texture_2d_new_from_bitmap (clear_bmp,
atlas->texture_format,
&ignore_error);
if (!tex)
cogl_error_free (ignore_error);
tex = cogl_texture_2d_new_from_bitmap (clear_bmp);
_cogl_texture_set_internal_format (COGL_TEXTURE (tex),
atlas->texture_format);
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);
@ -311,9 +317,11 @@ _cogl_atlas_create_texture (CoglAtlas *atlas,
}
else
{
tex = cogl_texture_2d_new_with_size (ctx,
width, height,
atlas->texture_format);
tex = cogl_texture_2d_new_with_size (ctx, width, height);
_cogl_texture_set_internal_format (COGL_TEXTURE (tex),
atlas->texture_format);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), &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 */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
width, height,
internal_format));
width, height));
_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
@ -580,8 +589,11 @@ create_migration_texture (CoglContext *ctx,
cogl_texture_2d_sliced_new_with_size (ctx,
width,
height,
COGL_TEXTURE_MAX_WASTE,
internal_format);
COGL_TEXTURE_MAX_WASTE);
_cogl_texture_set_internal_format (COGL_TEXTURE (tex_2ds),
internal_format);
tex = COGL_TEXTURE (tex_2ds);
}
@ -594,7 +606,7 @@ _cogl_atlas_copy_rectangle (CoglAtlas *atlas,
int y,
int width,
int height,
CoglPixelFormat format)
CoglPixelFormat internal_format)
{
CoglTexture *tex;
CoglBlitData blit_data;
@ -603,7 +615,7 @@ _cogl_atlas_copy_rectangle (CoglAtlas *atlas,
_COGL_GET_CONTEXT (ctx, NULL);
/* 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))
{
cogl_error_free (ignore_error);

View file

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

View file

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

View file

@ -301,8 +301,7 @@ cogl_gles2_get_current_vtable (void);
* glGenTextures()
* @width: Width of the texture to allocate
* @height: Height of the texture to allocate
* @internal_format: The format of the texture
* @error: A #CoglError for exceptions
* @format: The format of the texture
*
* Creates a #CoglTexture2D from an OpenGL ES 2.0 texture handle that
* 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,
int width,
int height,
CoglPixelFormat internal_format,
CoglError **error);
CoglPixelFormat format);
/**
* cogl_gles2_texture_get_handle:

View file

@ -37,13 +37,12 @@
COGL_BEGIN_DECLS
/**
* cogl_texture_2d_new_from_foreign:
* cogl_texture_2d_gl_new_from_foreign:
* @ctx: A #CoglContext
* @gl_handle: A GL handle for a GL_TEXTURE_2D texture object
* @width: Width of the foreign GL texture
* @height: Height of the foreign GL texture
* @format: The format of the texture
* @error: A #CoglError for exceptions
*
* Wraps an existing GL_TEXTURE_2D texture object as a #CoglTexture2D.
* 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
* geometry.</note>
*
* Return value: (transfer full): A newly allocated #CoglTexture2D, 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.
* Returns: (transfer full): A newly allocated #CoglTexture2D
*
* Since: 2.0
*/
CoglTexture2D *
cogl_texture_2d_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle,
int width,
int height,
CoglPixelFormat format,
CoglError **error);
cogl_texture_2d_gl_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle,
int width,
int height,
CoglPixelFormat format);
COGL_END_DECLS

View file

@ -61,9 +61,7 @@ struct _CoglTexture2D
CoglTexture2D *
_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format,
CoglBool can_convert_in_place,
CoglError **error);
CoglBool can_convert_in_place);
#if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
/* 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 x_pot_waste,
int y_pot_waste,
CoglPixelFormat format,
CoglError **error);
CoglPixelFormat format);
CoglTexture2DSliced *
_cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste,
CoglPixelFormat internal_format,
CoglBool can_convert_in_place,
CoglError **error);
CoglBool can_convert_in_place);
#endif /* __COGL_TEXTURE_2D_SLICED_PRIVATE_H */

View file

@ -881,8 +881,10 @@ allocate_slices (CoglTexture2DSliced *tex_2ds,
slice = COGL_TEXTURE (
cogl_texture_2d_new_with_size (ctx,
x_span->size, y_span->size,
internal_format));
x_span->size, y_span->size));
_cogl_texture_copy_internal_format (tex, slice);
g_array_append_val (tex_2ds->slice_textures, slice);
if (!cogl_texture_allocate (slice, error))
{
@ -927,16 +929,9 @@ CoglTexture2DSliced *
cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
int width,
int height,
int max_waste,
CoglPixelFormat internal_format)
int max_waste)
{
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 ();
CoglTextureLoader *loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
loader->src.sized.width = width;
loader->src.sized.height = height;
@ -945,16 +940,14 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
width,
height,
max_waste,
internal_format,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
loader);
}
CoglTexture2DSliced *
_cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste,
CoglPixelFormat internal_format,
CoglBool can_convert_in_place,
CoglError **error)
CoglBool can_convert_in_place)
{
CoglTextureLoader *loader;
@ -969,21 +962,17 @@ _cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp),
max_waste,
internal_format,
cogl_bitmap_get_format (bmp),
loader);
}
CoglTexture2DSliced *
cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste,
CoglPixelFormat internal_format,
CoglError **error)
int max_waste)
{
return _cogl_texture_2d_sliced_new_from_bitmap (bmp,
max_waste,
internal_format,
FALSE,
error);
FALSE);
}
CoglTexture2DSliced *
@ -994,8 +983,7 @@ _cogl_texture_2d_sliced_new_from_foreign (CoglContext *ctx,
int height,
int x_pot_waste,
int y_pot_waste,
CoglPixelFormat format,
CoglError **error)
CoglPixelFormat format)
{
CoglTextureLoader *loader;
@ -1039,7 +1027,6 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
int height,
int max_waste,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data,
CoglError **error)
@ -1061,9 +1048,7 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
rowstride,
(uint8_t *) data);
tex_2ds = cogl_texture_2d_sliced_new_from_bitmap (bmp, max_waste,
internal_format,
error);
tex_2ds = cogl_texture_2d_sliced_new_from_bitmap (bmp, max_waste);
cogl_object_unref (bmp);
@ -1081,7 +1066,6 @@ CoglTexture2DSliced *
cogl_texture_2d_sliced_new_from_file (CoglContext *ctx,
const char *filename,
int max_waste,
CoglPixelFormat internal_format,
CoglError **error)
{
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,
max_waste,
internal_format,
TRUE, /* can convert in-place */
error);
TRUE); /* can convert in-place */
cogl_object_unref (bmp);
@ -1198,18 +1180,17 @@ allocate_from_gl_foreign (CoglTexture2DSliced *tex_2ds,
CoglSpan x_span;
CoglSpan y_span;
CoglTexture2D *tex_2d =
cogl_texture_2d_new_from_foreign (ctx,
loader->src.gl_foreign.gl_handle,
gl_width,
gl_height,
format,
error);
if (!tex_2d)
return FALSE;
cogl_texture_2d_gl_new_from_foreign (ctx,
loader->src.gl_foreign.gl_handle,
gl_width,
gl_height,
format);
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
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
* they must be sliced to reduce the amount of waste. A
* negative can be passed to disable slicing.
* @internal_format: The format of the texture
*
* Creates a #CoglTexture2DSliced that may internally be comprised of
* 1 or more #CoglTexture2D textures depending on GPU limitations.
@ -110,8 +109,7 @@ CoglTexture2DSliced *
cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
int width,
int height,
int max_waste,
CoglPixelFormat internal_format);
int max_waste);
/**
* 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
* they must be sliced to reduce the amount of waste. A
* 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 #CoglTexture2DSliced from an image file.
@ -167,7 +157,6 @@ CoglTexture2DSliced *
cogl_texture_2d_sliced_new_from_file (CoglContext *ctx,
const char *filename,
int max_waste,
CoglPixelFormat internal_format,
CoglError **error);
/**
@ -180,14 +169,6 @@ cogl_texture_2d_sliced_new_from_file (CoglContext *ctx,
* are allowed along the right and bottom textures before
* they must be sliced to reduce the amount of waste. A
* negative can be passed to disable slicing.
* @internal_format: the #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
* row in @data. A value of 0 will make Cogl automatically
* calculate @rowstride from @width and @format.
@ -239,7 +220,6 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
int height,
int max_waste,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data,
CoglError **error);
@ -251,15 +231,6 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
* are allowed along the right and bottom textures before
* they must be sliced to reduce the amount of waste. A
* negative can be passed to disable slicing.
* @internal_format: the #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
* in a bitmap.
@ -296,9 +267,7 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
*/
CoglTexture2DSliced *
cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste,
CoglPixelFormat internal_format,
CoglError **error);
int max_waste);
/**
* cogl_is_texture_2d_sliced:

View file

@ -110,22 +110,17 @@ _cogl_texture_2d_create_base (CoglContext *ctx,
CoglTexture2D *
cogl_texture_2d_new_with_size (CoglContext *ctx,
int width,
int height,
CoglPixelFormat internal_format)
int height)
{
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->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
loader->src.sized.width = width;
loader->src.sized.height = height;
return _cogl_texture_2d_create_base (ctx, width, height,
internal_format, loader);
COGL_PIXEL_FORMAT_RGBA_8888_PRE, loader);
}
static CoglBool
@ -139,9 +134,7 @@ _cogl_texture_2d_allocate (CoglTexture *tex,
CoglTexture2D *
_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format,
CoglBool can_convert_in_place,
CoglError **error)
CoglBool can_convert_in_place)
{
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),
cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp),
internal_format,
cogl_bitmap_get_format (bmp),
loader);
}
CoglTexture2D *
cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format,
CoglError **error)
cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp)
{
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 *
cogl_texture_2d_new_from_file (CoglContext *ctx,
const char *filename,
CoglPixelFormat internal_format,
CoglError **error)
{
CoglBitmap *bmp;
@ -183,9 +174,7 @@ cogl_texture_2d_new_from_file (CoglContext *ctx,
return NULL;
tex_2d = _cogl_texture_2d_new_from_bitmap (bmp,
internal_format,
TRUE, /* can convert in-place */
error);
TRUE); /* can convert in-place */
cogl_object_unref (bmp);
@ -197,7 +186,6 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
int width,
int height,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data,
CoglError **error)
@ -219,9 +207,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
rowstride,
(uint8_t *) data);
tex_2d = cogl_texture_2d_new_from_bitmap (bmp,
internal_format,
error);
tex_2d = cogl_texture_2d_new_from_bitmap (bmp);
cogl_object_unref (bmp);
@ -273,10 +259,10 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
static void
shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
CoglPixelFormat *format_out,
CoglPixelFormat *internal_format_out)
CoglTextureComponents *components_out)
{
CoglPixelFormat format;
CoglPixelFormat internal_format = COGL_PIXEL_FORMAT_ANY;
CoglTextureComponents components = COGL_TEXTURE_COMPONENTS_RGBA;
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;
case WL_SHM_FORMAT_XRGB8888:
format = COGL_PIXEL_FORMAT_ARGB_8888;
internal_format = COGL_PIXEL_FORMAT_RGB_888;
components = COGL_TEXTURE_COMPONENTS_RGB;
break;
#elif G_BYTE_ORDER == G_LITTLE_ENDIAN
case WL_SHM_FORMAT_ARGB8888:
@ -294,7 +280,7 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
break;
case WL_SHM_FORMAT_XRGB8888:
format = COGL_PIXEL_FORMAT_BGRA_8888;
internal_format = COGL_PIXEL_FORMAT_BGR_888;
components = COGL_TEXTURE_COMPONENTS_RGB;
break;
#endif
default:
@ -304,8 +290,8 @@ shm_buffer_get_cogl_pixel_format (struct wl_shm_buffer *shm_buffer,
if (format_out)
*format_out = format;
if (internal_format_out)
*internal_format_out = internal_format;
if (components_out)
*components_out = components;
}
CoglBool
@ -345,6 +331,7 @@ cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
CoglError **error)
{
struct wl_shm_buffer *shm_buffer;
CoglTexture2D *tex = NULL;
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 width = wl_shm_buffer_get_width (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,
width, height,
format,
internal_format,
stride,
wl_shm_buffer_get_data (shm_buffer),
error);
bmp = cogl_bitmap_new_for_data (ctx,
width, height,
format,
stride,
wl_shm_buffer_get_data (shm_buffer));
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
{
@ -383,7 +384,6 @@ cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
&height))
{
EGLImageKHR image;
CoglTexture2D *tex = NULL;
CoglPixelFormat internal_format;
_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
* @width: Width 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
* @height that your GPU can texture from directly.
@ -101,21 +100,12 @@ cogl_is_texture_2d (void *object);
CoglTexture2D *
cogl_texture_2d_new_with_size (CoglContext *ctx,
int width,
int height,
CoglPixelFormat internal_format);
int height);
/**
* cogl_texture_2d_new_from_file:
* @ctx: A #CoglContext
* @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
*
* Creates a low-level #CoglTexture2D texture from an image file.
@ -144,7 +134,6 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
CoglTexture2D *
cogl_texture_2d_new_from_file (CoglContext *ctx,
const char *filename,
CoglPixelFormat internal_format,
CoglError **error);
/**
@ -153,14 +142,6 @@ cogl_texture_2d_new_from_file (CoglContext *ctx,
* @width: width of texture in pixels
* @height: height of texture in pixels
* @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
* scanlines in @data. A value of 0 will make Cogl automatically
* calculate @rowstride from @width and @format.
@ -198,7 +179,6 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
int width,
int height,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data,
CoglError **error);
@ -206,15 +186,6 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
/**
* cogl_texture_2d_new_from_bitmap:
* @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
* 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
* cogl_has_feature().</note>
*
* Returns: (transfer full): A newly allocated #CoglTexture2D, or if
* 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.
* Returns: (transfer full): A newly allocated #CoglTexture2D
*
* Since: 2.0
* Stability: unstable
*/
CoglTexture2D *
cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap,
CoglPixelFormat internal_format,
CoglError **error);
cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap);
COGL_END_DECLS

View file

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

View file

@ -53,8 +53,6 @@ typedef struct _CoglTexture3D CoglTexture3D;
* @width: width of the texture in pixels.
* @height: height 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
* dimensions and pixel format.
@ -84,8 +82,7 @@ CoglTexture3D *
cogl_texture_3d_new_with_size (CoglContext *context,
int width,
int height,
int depth,
CoglPixelFormat internal_format);
int depth);
/**
* 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.
* @depth: depth of the texture in pixels.
* @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
* 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
@ -137,7 +126,6 @@ cogl_texture_3d_new_from_data (CoglContext *context,
int height,
int depth,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
int image_stride,
const uint8_t *data,
@ -148,15 +136,6 @@ cogl_texture_3d_new_from_data (CoglContext *context,
* @bitmap: A #CoglBitmap object.
* @height: height 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
* 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
* GPU.</note>
*
* Return value: (transfer full): the newly created texture or %NULL
* if there was an error.
* Return value: (transfer full): a newly created #CoglTexture3D
* Since: 2.0
* Stability: unstable
*/
CoglTexture3D *
cogl_texture_3d_new_from_bitmap (CoglBitmap *bitmap,
int height,
int depth,
CoglPixelFormat internal_format,
CoglError **error);
int depth);
/**
* cogl_is_texture_3d:

View file

@ -234,7 +234,7 @@ _cogl_texture_init (CoglTexture *texture,
CoglContext *ctx,
int width,
int height,
CoglPixelFormat internal_format,
CoglPixelFormat src_format,
CoglTextureLoader *loader,
const CoglTextureVtable *vtable);
@ -395,4 +395,8 @@ _cogl_texture_get_format (CoglTexture *texture);
CoglTextureLoader *
_cogl_texture_create_loader (void);
void
_cogl_texture_copy_internal_format (CoglTexture *src,
CoglTexture *dest);
#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,
internal_format, loader);
/* 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
* lazily but since Mutter uses this api we are currently
* 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))
{
cogl_object_unref (tex_rect);
@ -499,9 +509,7 @@ _cogl_texture_rectangle_allocate (CoglTexture *tex,
}
CoglTextureRectangle *
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
CoglPixelFormat internal_format,
CoglError **error)
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp)
{
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),
cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp),
internal_format,
cogl_bitmap_get_format (bmp),
loader);
}
@ -524,8 +532,7 @@ cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle,
int width,
int height,
CoglPixelFormat format,
CoglError **error)
CoglPixelFormat format)
{
CoglTextureLoader *loader;

View file

@ -84,10 +84,10 @@ cogl_is_texture_rectangle (void *object);
* @internal_format: The desired internal texture format
* @error: An optional CoglError pointer for reporting exceptions
*
* Allocates a new #CoglTextureRectangle texture with a given @width, @height
* and @internal_format. This texture is a low-level texture that
* the GPU can sample from directly unlike high-level textures such
* as #CoglTexture2DSliced and #CoglAtlasTexture.
* Allocates a new #CoglTextureRectangle texture with a given @width,
* @height and @internal_format. This texture is a low-level texture
* that the GPU can sample from directly unlike high-level textures
* such as #CoglTexture2DSliced and #CoglAtlasTexture.
*
* <note>Unlike for #CoglTexture2D textures, coordinates for
* #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:
* @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
* initialized with the pixel data from @bitmap. Internally the data
* will be stored in the format given by @internal_format. This
* texture is a low-level texture that the GPU can sample from
* directly unlike high-level textures such as #CoglTexture2DSliced
* and #CoglAtlasTexture.
* initialized with the pixel data from @bitmap. This texture is a
* low-level texture that the GPU can sample from directly unlike
* high-level textures such as #CoglTexture2DSliced and
* #CoglAtlasTexture.
*
* <note>Unlike for #CoglTexture2D textures, coordinates for
* #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
* allocated.
*
* Return value: (transfer full): A pointer to a newly allocated
* #CoglTextureRectangle texture or if the size was too large
* or there wasn't enough memory %NULL is returned and @error
* set.
*
* Return value: (transfer full): A pointer to a new
* #CoglTextureRectangle texture.
* Since: 2.0
* Stability: unstable
*/
CoglTextureRectangle *
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap,
CoglPixelFormat internal_format,
CoglError **error);
cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap);
/**
* 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
* @height: Height of the foreign GL texture
* @format: The format of the texture
* @error: A #CoglError for exceptions
*
* Wraps an existing GL_TEXTURE_RECTANGLE texture object as a
* #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
* with cogl_texture_set_premultiplied().
*
* Return value: (transfer full): A newly allocated
* #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.
* Return value: (transfer full): A new #CoglTextureRectangle texture
*/
CoglTextureRectangle *
cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle,
int width,
int height,
CoglPixelFormat format,
CoglError **error);
CoglPixelFormat format);
COGL_END_DECLS

View file

@ -107,7 +107,7 @@ _cogl_texture_init (CoglTexture *texture,
CoglContext *context,
int width,
int height,
CoglPixelFormat internal_format,
CoglPixelFormat src_format,
CoglTextureLoader *loader,
const CoglTextureVtable *vtable)
{
@ -121,7 +121,22 @@ _cogl_texture_init (CoglTexture *texture,
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
@ -1503,3 +1518,11 @@ cogl_texture_get_premultiplied (CoglTexture *texture)
{
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)))
{
/* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
width, height,
internal_format));
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height));
_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))
{
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,
width,
height,
max_waste,
internal_format));
max_waste));
_cogl_texture_set_internal_format (tex, internal_format);
}
/* NB: This api existed before Cogl introduced lazy allocation of
@ -206,7 +203,6 @@ _cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
CoglError **error)
{
CoglContext *ctx = _cogl_bitmap_get_context (bitmap);
CoglAtlasTexture *atlas_tex;
CoglTexture *tex;
CoglError *internal_error = NULL;
@ -214,14 +210,19 @@ _cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
!COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_ATLAS))
{
/* First try putting the texture in the atlas */
if ((atlas_tex = _cogl_atlas_texture_new_from_bitmap (bitmap,
internal_format,
can_convert_in_place,
&internal_error)))
CoglAtlasTexture *atlas_tex =
_cogl_atlas_texture_new_from_bitmap (bitmap,
can_convert_in_place);
_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);
cogl_error_free (internal_error);
internal_error = NULL;
cogl_object_unref (atlas_tex);
}
/* 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)))
{
tex = COGL_TEXTURE (_cogl_texture_2d_new_from_bitmap (bitmap,
internal_format,
can_convert_in_place,
&internal_error));
can_convert_in_place));
if (!tex)
_cogl_texture_set_internal_format (tex, internal_format);
if (!cogl_texture_allocate (tex, &internal_error))
{
cogl_error_free (internal_error);
internal_error = NULL;
cogl_object_unref (tex);
tex = NULL;
}
}
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;
tex = COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_bitmap (bitmap,
max_waste,
internal_format,
can_convert_in_place,
error));
can_convert_in_place));
_cogl_texture_set_internal_format (tex, internal_format);
if (!cogl_texture_allocate (tex, error))
{
cogl_object_unref (tex);
tex = NULL;
}
}
if (tex &&
@ -343,8 +352,9 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
gl_handle,
width,
height,
format,
NULL);
format);
_cogl_texture_set_internal_format (COGL_TEXTURE (texture_rectangle),
format);
/* CoglTextureRectangle textures work with non-normalized
* coordinates, but the semantics for this function that people
@ -358,20 +368,32 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
#endif
if (x_pot_waste != 0 || y_pot_waste != 0)
return COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_foreign (ctx,
gl_handle,
gl_target,
width,
height,
x_pot_waste,
y_pot_waste,
format,
NULL));
{
CoglTexture *tex =
COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_foreign (ctx,
gl_handle,
gl_target,
width,
height,
x_pot_waste,
y_pot_waste,
format));
_cogl_texture_set_internal_format (tex, format);
cogl_texture_allocate (tex, NULL);
return tex;
}
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,
width,
height,
format,
NULL));
format));
_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 height)
{
CoglPixelFormat format;
CoglTexture2D *depth_texture;
CoglTexture2D *depth_texture =
cogl_texture_2d_new_with_size (ctx, width, height);
if (_cogl_has_private_feature
(ctx, COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL) ||
_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);
cogl_texture_set_components (COGL_TEXTURE (depth_texture),
COGL_TEXTURE_COMPONENTS_DEPTH);
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
auto-generate the mipmap. This doesn't make much sense any more
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
auto-mipmapping. To be compatible with existing code, Cogl now
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 *
cogl_texture_2d_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle,
int width,
int height,
CoglPixelFormat format,
CoglError **error)
cogl_texture_2d_gl_new_from_foreign (CoglContext *ctx,
unsigned int gl_handle,
int width,
int height,
CoglPixelFormat format)
{
CoglTextureLoader *loader;

View file

@ -516,8 +516,9 @@ create_fallback_texture (CoglContext *ctx,
{
/* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
width, height,
internal_format));
width, height));
_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
@ -539,9 +540,10 @@ create_fallback_texture (CoglContext *ctx,
cogl_texture_2d_sliced_new_with_size (ctx,
width,
height,
COGL_TEXTURE_MAX_WASTE,
internal_format);
COGL_TEXTURE_MAX_WASTE);
tex = COGL_TEXTURE (tex_2ds);
_cogl_texture_set_internal_format (tex, internal_format);
}
return tex;

View file

@ -2508,6 +2508,8 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
texture_format,
&error));
_cogl_texture_set_internal_format (tex, texture_format);
if (glx_tex_pixmap->glx_tex)
COGL_NOTE (TEXTURE_PIXMAP, "Created a texture rectangle for %p",
tex_pixmap);
@ -2526,8 +2528,9 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
glx_tex_pixmap->glx_tex = COGL_TEXTURE (
cogl_texture_2d_new_with_size (ctx,
tex->width,
tex->height,
texture_format));
tex->height));
_cogl_texture_set_internal_format (tex, texture_format);
if (cogl_texture_allocate (glx_tex_pixmap->glx_tex, &error))
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_bitmap
cogl_texture_2d_new_from_data
cogl_texture_2d_new_from_foreign
cogl_texture_2d_gl_new_from_foreign
cogl_is_texture_rectangle
</SECTION>

View file

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

View file

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

View file

@ -98,8 +98,7 @@ main (int argc, char **argv)
data.offscreen_texture =
cogl_texture_2d_new_with_size (data.ctx,
OFFSCREEN_WIDTH,
OFFSCREEN_HEIGHT,
COGL_PIXEL_FORMAT_ANY);
OFFSCREEN_HEIGHT);
data.offscreen = cogl_offscreen_new_with_texture (data.offscreen_texture);
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);
tex = cogl_texture_2d_new_with_size (ctx,
320, 480,
COGL_PIXEL_FORMAT_ANY);
tex = cogl_texture_2d_new_with_size (ctx, 320, 480);
offscreen = cogl_offscreen_new_with_texture (tex);
offscreen_fb = offscreen;
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,
TEXTURE_SIZE, TEXTURE_SIZE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
TEXTURE_SIZE * 4,
data,
NULL /* error */);

View file

@ -177,8 +177,7 @@ test_utils_init (TestFlags requirement_flags,
{
CoglOffscreen *offscreen;
CoglTexture2D *tex = cogl_texture_2d_new_with_size (test_ctx,
FB_WIDTH, FB_HEIGHT,
COGL_PIXEL_FORMAT_ANY);
FB_WIDTH, FB_HEIGHT);
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex));
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,
1, 1, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */
(uint8_t *) &color,
NULL);
@ -364,7 +362,7 @@ test_utils_texture_new_with_size (CoglContext *ctx,
int width,
int height,
TestUtilsTextureFlags flags,
CoglPixelFormat internal_format)
CoglTextureComponents components)
{
CoglTexture *tex;
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 */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
width, height,
internal_format));
width, height));
cogl_texture_set_components (tex, components);
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,
width,
height,
max_waste,
internal_format);
max_waste);
tex = COGL_TEXTURE (tex_2ds);
cogl_texture_set_components (tex, components);
}
if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
@ -424,7 +424,7 @@ test_utils_texture_new_with_size (CoglContext *ctx,
CoglTexture *
test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
TestUtilsTextureFlags flags,
CoglPixelFormat internal_format)
CoglBool premultiplied)
{
CoglAtlasTexture *atlas_tex;
CoglTexture *tex;
@ -433,15 +433,15 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
if (!flags)
{
/* First try putting the texture in the atlas */
if ((atlas_tex = cogl_atlas_texture_new_from_bitmap (bitmap,
internal_format,
&internal_error)) &&
cogl_texture_allocate (COGL_TEXTURE (atlas_tex), &internal_error))
{
return COGL_TEXTURE (atlas_tex);
}
atlas_tex = cogl_atlas_texture_new_from_bitmap (bitmap);
cogl_texture_set_premultiplied (COGL_TEXTURE (atlas_tex), premultiplied);
if (cogl_texture_allocate (COGL_TEXTURE (atlas_tex), &internal_error))
return COGL_TEXTURE (atlas_tex);
cogl_error_free (internal_error);
cogl_object_unref (atlas_tex);
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_MIPMAP)))
{
tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap,
internal_format,
&internal_error));
tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap));
cogl_texture_set_premultiplied (tex, premultiplied);
if (cogl_error_matches (internal_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 ?
-1 : COGL_TEXTURE_MAX_WASTE;
CoglTexture2DSliced *tex_2ds =
cogl_texture_2d_sliced_new_from_bitmap (bitmap,
max_waste,
internal_format,
NULL); /* don't catch
exceptions */
cogl_texture_2d_sliced_new_from_bitmap (bitmap, max_waste);
tex = COGL_TEXTURE (tex_2ds);
cogl_texture_set_premultiplied (tex, premultiplied);
}
if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
@ -507,7 +505,6 @@ test_utils_texture_new_from_data (CoglContext *ctx,
int height,
TestUtilsTextureFlags flags,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data)
{
@ -524,7 +521,7 @@ test_utils_texture_new_from_data (CoglContext *ctx,
rowstride,
(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);

View file

@ -81,8 +81,7 @@ test_utils_fini (void);
* @width: width of texture in pixels.
* @height: height of texture in pixels.
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture.
* @components: What texture components are required
*
* 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 height,
TestUtilsTextureFlags flags,
CoglPixelFormat internal_format);
CoglTextureComponents components);
/*
* test_utils_texture_new_from_data:
@ -109,14 +108,6 @@ test_utils_texture_new_with_size (CoglContext *ctx,
* @height: height of texture in pixels
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @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
* scanlines in @data
* @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.
*
* 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
*/
CoglTexture *
@ -132,7 +130,6 @@ test_utils_texture_new_from_data (CoglContext *ctx,
int height,
TestUtilsTextureFlags flags,
CoglPixelFormat format,
CoglPixelFormat internal_format,
int rowstride,
const uint8_t *data);
@ -140,9 +137,12 @@ test_utils_texture_new_from_data (CoglContext *ctx,
* test_utils_texture_new_from_bitmap:
* @bitmap: A #CoglBitmap pointer
* @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture
* @error: A #CoglError to catch exceptional errors or %NULL
* @premultiplied: Whether the texture should hold premultipled data.
* (if the bitmap already holds premultiplied data
* 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.
*
@ -151,7 +151,7 @@ test_utils_texture_new_from_data (CoglContext *ctx,
CoglTexture *
test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
TestUtilsTextureFlags flags,
CoglPixelFormat internal_format);
CoglBool premultiplied);
/*
* test_utils_check_pixel:

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,19 +7,19 @@ test_framebuffer_get_bits (void)
{
CoglTexture2D *tex_a =
cogl_texture_2d_new_with_size (test_ctx,
16, 16, /* width/height */
COGL_PIXEL_FORMAT_A_8);
16, 16); /* width/height */
CoglOffscreen *offscreen_a =
cogl_offscreen_new_with_texture (tex_a);
CoglFramebuffer *fb_a = offscreen_a;
CoglTexture2D *tex_rgba =
cogl_texture_2d_new_with_size (test_ctx,
16, 16, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888);
16, 16); /* width/height */
CoglOffscreen *offscreen_rgba =
cogl_offscreen_new_with_texture (tex_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_rgba, NULL);

View file

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

View file

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

View file

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

View file

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

View file

@ -46,8 +46,7 @@ test_paint (TestState *state)
tex_2d = cogl_texture_2d_new_with_size (test_ctx,
state->fb_width,
state->fb_height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
state->fb_height);
tex = tex_2d;
offscreen = cogl_offscreen_new_with_texture (tex);
@ -127,8 +126,7 @@ test_flush (TestState *state)
journal */
tex_2d = cogl_texture_2d_new_with_size (test_ctx,
16, 16, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
16, 16); /* width/height */
tex = tex_2d;
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,
1, 1, /* width / height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
4, /* rowstride */
data,
NULL);

View file

@ -22,8 +22,7 @@ test_pipeline_shader_state (void)
-1,
100);
tex = cogl_texture_2d_new_with_size (test_ctx,
128, 128, COGL_PIXEL_FORMAT_ANY);
tex = cogl_texture_2d_new_with_size (test_ctx, 128, 128);
offscreen = cogl_offscreen_new_with_texture (tex);
fb = offscreen;
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;
texture = cogl_texture_2d_new_from_bitmap (bitmap,
COGL_PIXEL_FORMAT_RGBA_8888,
NULL); /* don't catch errors */
texture = cogl_texture_2d_new_from_bitmap (bitmap);
g_assert (texture != NULL);
@ -221,7 +219,6 @@ create_white_texture (void)
BITMAP_SIZE,
BITMAP_SIZE,
COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_ANY,
BITMAP_SIZE * 4, /* rowstride */
data,
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,
2, tex_height, /* width/height */
COGL_PIXEL_FORMAT_RGB_888,
COGL_PIXEL_FORMAT_ANY,
6, /* row stride */
tex_data,
&error);

View file

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

View file

@ -174,7 +174,6 @@ test_paint (TestState *state)
2, 1, /* size */
TEST_UTILS_TEXTURE_NO_ATLAS,
COGL_PIXEL_FORMAT_RGB_888,
COGL_PIXEL_FORMAT_ANY,
6, /* rowstride */
tex_data);
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,
1, 1, /* width / height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */
tex_data,
NULL);

View file

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

View file

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

View file

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

View file

@ -11,6 +11,7 @@ check_texture (int width, int height, TestUtilsTextureFlags flags)
uint8_t *data, *p;
int y, x;
int rowstride;
CoglBitmap *bmp;
p = data = g_malloc (width * height * 4);
for (y = 0; y < height; y++)
@ -22,13 +23,14 @@ check_texture (int width, int height, TestUtilsTextureFlags flags)
*(p++) = (x ^ y);
}
tex = test_utils_texture_new_from_data (test_ctx,
width, height,
flags,
COGL_PIXEL_FORMAT_RGBA_8888,
COGL_PIXEL_FORMAT_RGBA_8888,
width * 4,
data);
bmp = cogl_bitmap_new_for_data (test_ctx,
width, height,
COGL_PIXEL_FORMAT_RGBA_8888,
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
test set_region */

View file

@ -32,8 +32,6 @@ test_texture_no_allocate (void)
BIG_TEX_HEIGHT,
/* format */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
/* internal format */
COGL_PIXEL_FORMAT_ANY,
/* rowstride */
BIG_TEX_WIDTH * 4,
tex_data,
@ -54,14 +52,12 @@ test_texture_no_allocate (void)
cogl_texture_2d_sliced_new_with_size (test_ctx,
BIG_TEX_WIDTH,
BIG_TEX_HEIGHT,
COGL_TEXTURE_MAX_WASTE,
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
COGL_TEXTURE_MAX_WASTE);
cogl_object_unref (texture);
/* 2D texture */
texture_2d = cogl_texture_2d_new_with_size (test_ctx,
64, 64,
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
64, 64);
cogl_object_unref (texture_2d);
/* 3D texture */
@ -69,8 +65,7 @@ test_texture_no_allocate (void)
{
CoglTexture3D *texture_3d =
cogl_texture_3d_new_with_size (test_ctx,
64, 64, 64,
COGL_PIXEL_FORMAT_RGBA_8888_PRE);
64, 64, 64);
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_SIZE, TEX_SIZE, flags,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
COGL_PIXEL_FORMAT_ANY,
TEX_SIZE * 4,
data);
g_free (data);

View file

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