[Cogl] [PATCH 03/11] texture-2d: Add _new_from_file api

Robert Bragg robert at sixbynine.org
Thu Jun 27 09:22:10 PDT 2013


From: Robert Bragg <robert at linux.intel.com>

This adds a cogl_texture_2d_new_from_file() api since we are planning to
remove cogl_texture_new_from_file() but don't want to loose the
convenience it had.
---
 cogl/cogl-texture-2d.c                 | 25 +++++++++++++++++++++++++
 cogl/cogl-texture-2d.h                 | 27 +++++++++++++++++++++++++++
 doc/reference/cogl2/cogl2-sections.txt |  1 +
 3 files changed, 53 insertions(+)

diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index 38e6212..609960e 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -192,6 +192,31 @@ cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
 }
 
 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_new_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,
                                int height,
diff --git a/cogl/cogl-texture-2d.h b/cogl/cogl-texture-2d.h
index 5a5ff2f..c1ae57f 100644
--- a/cogl/cogl-texture-2d.h
+++ b/cogl/cogl-texture-2d.h
@@ -103,6 +103,33 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
                                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
  * @width: width of texture in pixels
diff --git a/doc/reference/cogl2/cogl2-sections.txt b/doc/reference/cogl2/cogl2-sections.txt
index bd250d1..9e7df49 100644
--- a/doc/reference/cogl2/cogl2-sections.txt
+++ b/doc/reference/cogl2/cogl2-sections.txt
@@ -361,6 +361,7 @@ cogl_is_texture_2d
 
 <SUBSECTION>
 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_gl_new_from_foreign
-- 
1.8.2.1



More information about the Cogl mailing list