diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c index d9cc03145..4147746c2 100644 --- a/cogl/cogl-texture-2d.c +++ b/cogl/cogl-texture-2d.c @@ -191,6 +191,31 @@ cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp, return _cogl_texture_2d_new_from_bitmap (bmp, internal_format, FALSE, error); } +CoglTexture2D * +cogl_texture_2d_new_from_file (CoglContext *ctx, + const char *filename, + CoglPixelFormat internal_format, + CoglError **error) +{ + CoglBitmap *bmp; + CoglTexture2D *tex_2d = NULL; + + _COGL_RETURN_VAL_IF_FAIL (error == NULL || *error == NULL, NULL); + + bmp = _cogl_bitmap_from_file (ctx, filename, error); + if (bmp == NULL) + return NULL; + + tex_2d = _cogl_texture_2d_new_from_bitmap (bmp, + internal_format, + TRUE, /* can convert in-place */ + error); + + cogl_object_unref (bmp); + + return tex_2d; +} + CoglTexture2D * cogl_texture_2d_new_from_data (CoglContext *ctx, int width, diff --git a/cogl/cogl-texture-2d.h b/cogl/cogl-texture-2d.h index 5a5ff2f54..c1ae57f26 100644 --- a/cogl/cogl-texture-2d.h +++ b/cogl/cogl-texture-2d.h @@ -102,6 +102,33 @@ cogl_texture_2d_new_with_size (CoglContext *ctx, int height, CoglPixelFormat internal_format); +/** + * 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 #CoglTexture2D from an image file. + * + * Return value: A newly created #CoglTexture2D or %NULL on failure + * and @error will be updated. + * + * Since: 1.16 + */ +CoglTexture2D * +cogl_texture_2d_new_from_file (CoglContext *ctx, + const char *filename, + CoglPixelFormat internal_format, + CoglError **error); + /** * cogl_texture_2d_new_from_data: * @ctx: A #CoglContext diff --git a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt index b0feae72b..939a4f021 100644 --- a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt +++ b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt @@ -417,6 +417,7 @@ COGL_TEXTURE_MAX_WASTE 2D textures CoglTexture2D 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