summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2012-11-08 20:33:00 +0000
committerRobert Bragg <robert@linux.intel.com>2012-11-26 23:33:06 +0000
commita1cabfae6ad50c51006c608cdde7d631b7832e71 (patch)
tree6637884d5d1690ec95fb207a4421817b9ce80f89
parentb8d1a1db482e1417979df9f88f92da47aa954bd0 (diff)
downloadcogl-a1cabfae6ad50c51006c608cdde7d631b7832e71.tar.gz
texture: split out high-level texture constructors
This splits out the very high level texture constructors that may internally construct one of several types of lower level texture due to various constraints. This also updates the prototypes for these constructors to take an explicit context pointer and return a CoglError consistent with other texture constructors. Reviewed-by: Neil Roberts <neil@linux.intel.com>
-rw-r--r--cogl/Makefile.am1
-rw-r--r--cogl/cogl-atlas-texture.c9
-rw-r--r--cogl/cogl-atlas.c25
-rw-r--r--cogl/cogl-atlas.h14
-rw-r--r--cogl/cogl-auto-texture.c307
-rw-r--r--cogl/cogl-texture-2d-sliced-private.h16
-rw-r--r--cogl/cogl-texture-2d-sliced.c34
-rw-r--r--cogl/cogl-texture-private.h4
-rw-r--r--cogl/cogl-texture.c259
-rw-r--r--cogl/cogl-texture.h46
-rw-r--r--cogl/winsys/cogl-texture-pixmap-x11.c7
-rw-r--r--examples/cogl-crate.c3
-rw-r--r--examples/cogl-gles2-context.c6
-rw-r--r--examples/cogl-msaa.c6
-rw-r--r--tests/conform/test-backface-culling.c6
-rw-r--r--tests/conform/test-color-mask.c5
16 files changed, 423 insertions, 325 deletions
diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index fafb4bc4..937a64b7 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -331,6 +331,7 @@ cogl_sources_c = \
$(srcdir)/cogl-texture-driver.h \
$(srcdir)/cogl-sub-texture.c \
$(srcdir)/cogl-texture.c \
+ $(srcdir)/cogl-auto-texture.c \
$(srcdir)/cogl-texture-2d.c \
$(srcdir)/cogl-texture-2d-sliced.c \
$(srcdir)/cogl-texture-3d.c \
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index 1403c64c..1ea22601 100644
--- a/cogl/cogl-atlas-texture.c
+++ b/cogl/cogl-atlas-texture.c
@@ -388,6 +388,15 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
atlas_tex->rectangle.height - 2,
COGL_TEXTURE_NO_ATLAS,
atlas_tex->format);
+ /* Note: we simply silently ignore failures to migrate a texture
+ * out (most likely due to lack of memory) and hope for the
+ * best.
+ *
+ * Maybe we should find a way to report the problem back to the
+ * app.
+ */
+ if (!standalone_tex)
+ return;
/* Notify cogl-pipeline.c that the texture's underlying GL texture
* storage is changing so it knows it may need to bind a new texture
diff --git a/cogl/cogl-atlas.c b/cogl/cogl-atlas.c
index 855fb50a..3c0d5547 100644
--- a/cogl/cogl-atlas.c
+++ b/cogl/cogl-atlas.c
@@ -537,19 +537,28 @@ _cogl_atlas_remove (CoglAtlas *atlas,
};
CoglTexture *
-_cogl_atlas_copy_rectangle (CoglAtlas *atlas,
- unsigned int x,
- unsigned int y,
- unsigned int width,
- unsigned int height,
- CoglTextureFlags flags,
- CoglPixelFormat format)
+_cogl_atlas_copy_rectangle (CoglAtlas *atlas,
+ int x,
+ int y,
+ int width,
+ int height,
+ CoglTextureFlags flags,
+ CoglPixelFormat format)
{
CoglTexture *tex;
CoglBlitData blit_data;
+ CoglError *ignore_error = NULL;
+
+ _COGL_GET_CONTEXT (ctx, NULL);
/* Create a new texture at the right size */
- tex = cogl_texture_new_with_size (width, height, flags, format);
+ tex = cogl_texture_new_with_size (ctx, width, height, flags, format,
+ &ignore_error);
+ if (!tex)
+ {
+ cogl_error_free (ignore_error);
+ return NULL;
+ }
/* Blit the data out of the atlas to the new texture. If FBOs
aren't available this will end up having to copy the entire
diff --git a/cogl/cogl-atlas.h b/cogl/cogl-atlas.h
index 02fac4a2..85e0aab5 100644
--- a/cogl/cogl-atlas.h
+++ b/cogl/cogl-atlas.h
@@ -75,13 +75,13 @@ _cogl_atlas_remove (CoglAtlas *atlas,
const CoglRectangleMapEntry *rectangle);
CoglTexture *
-_cogl_atlas_copy_rectangle (CoglAtlas *atlas,
- unsigned int x,
- unsigned int y,
- unsigned int width,
- unsigned int height,
- CoglTextureFlags flags,
- CoglPixelFormat format);
+_cogl_atlas_copy_rectangle (CoglAtlas *atlas,
+ int x,
+ int y,
+ int width,
+ int height,
+ CoglTextureFlags flags,
+ CoglPixelFormat format);
void
_cogl_atlas_add_reorganize_callback (CoglAtlas *atlas,
diff --git a/cogl/cogl-auto-texture.c b/cogl/cogl-auto-texture.c
new file mode 100644
index 00000000..824a8dbe
--- /dev/null
+++ b/cogl/cogl-auto-texture.c
@@ -0,0 +1,307 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2007,2008,2009,2011,2012 Intel Corporation.
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ *
+ * Authors:
+ * Matthew Allum <mallum@openedhand.com>
+ * Neil Roberts <neil@linux.intel.com>
+ * Robert Bragg <robert@linux.intel.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "cogl-texture.h"
+#include "cogl-util.h"
+#include "cogl-texture-2d.h"
+#include "cogl-primitive-texture.h"
+#include "cogl-texture-2d-sliced-private.h"
+#include "cogl-private.h"
+#include "cogl-object.h"
+#include "cogl-bitmap-private.h"
+#include "cogl-atlas-texture-private.h"
+#include "cogl-error-private.h"
+#include "cogl-texture-rectangle.h"
+#include "cogl-sub-texture.h"
+#include "cogl-texture-2d-gl.h"
+
+CoglTexture *
+cogl_texture_new_with_size (CoglContext *ctx,
+ int width,
+ int height,
+ CoglTextureFlags flags,
+ CoglPixelFormat internal_format,
+ CoglError **error)
+{
+ CoglTexture *tex;
+ CoglError *skip_error = NULL;
+
+ if ((_cogl_util_is_pot (width) && _cogl_util_is_pot (height)) ||
+ (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
+ 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,
+ &skip_error));
+ }
+ else
+ tex = NULL;
+
+ if (tex)
+ {
+ CoglBool auto_mipmap = !(flags & COGL_TEXTURE_NO_AUTO_MIPMAP);
+ cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex),
+ auto_mipmap);
+ }
+ else
+ {
+ /* If it fails resort to sliced textures */
+ int max_waste = flags & COGL_TEXTURE_NO_SLICING ? -1 : COGL_TEXTURE_MAX_WASTE;
+ cogl_error_free (skip_error);
+ tex = COGL_TEXTURE (cogl_texture_2d_sliced_new_with_size (ctx,
+ width,
+ height,
+ max_waste,
+ internal_format,
+ error));
+ }
+
+ return tex;
+}
+
+CoglTexture *
+cogl_texture_new_from_data (CoglContext *ctx,
+ int width,
+ int height,
+ CoglTextureFlags flags,
+ CoglPixelFormat format,
+ CoglPixelFormat internal_format,
+ int rowstride,
+ const uint8_t *data,
+ CoglError **error)
+{
+ CoglBitmap *bmp;
+ CoglTexture *tex;
+
+ _COGL_RETURN_VAL_IF_FAIL (format != COGL_PIXEL_FORMAT_ANY, NULL);
+ _COGL_RETURN_VAL_IF_FAIL (data != NULL, NULL);
+
+ /* Rowstride from width if not given */
+ if (rowstride == 0)
+ rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format);
+
+ /* Wrap the data into a bitmap */
+ bmp = cogl_bitmap_new_for_data (ctx,
+ width, height,
+ format,
+ rowstride,
+ (uint8_t *) data);
+
+ tex = cogl_texture_new_from_bitmap (bmp, flags, internal_format, error);
+
+ cogl_object_unref (bmp);
+
+ return tex;
+}
+
+CoglTexture *
+cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
+ CoglTextureFlags flags,
+ CoglPixelFormat internal_format,
+ CoglError **error)
+{
+ CoglContext *ctx = _cogl_bitmap_get_context (bitmap);
+ CoglAtlasTexture *atlas_tex;
+ CoglTexture *tex;
+ CoglError *internal_error = NULL;
+
+ /* First try putting the texture in the atlas */
+ if ((atlas_tex = _cogl_atlas_texture_new_from_bitmap (bitmap,
+ flags,
+ internal_format,
+ &internal_error)))
+ return COGL_TEXTURE (atlas_tex);
+
+ if (cogl_error_matches (internal_error,
+ COGL_SYSTEM_ERROR,
+ COGL_SYSTEM_ERROR_NO_MEMORY))
+ {
+ _cogl_propogate_error (error, internal_error);
+ return NULL;
+ }
+
+ cogl_error_free (internal_error);
+ internal_error = NULL;
+
+ /* If that doesn't work try a fast path 2D texture */
+ if ((_cogl_util_is_pot (bitmap->width) &&
+ _cogl_util_is_pot (bitmap->height)) ||
+ (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
+ cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP)))
+ {
+ tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap,
+ internal_format,
+ &internal_error));
+
+ if (cogl_error_matches (internal_error,
+ COGL_SYSTEM_ERROR,
+ COGL_SYSTEM_ERROR_NO_MEMORY))
+ {
+ _cogl_propogate_error (error, internal_error);
+ return NULL;
+ }
+
+ if (!tex)
+ {
+ cogl_error_free (internal_error);
+ internal_error = NULL;
+ }
+ }
+ else
+ tex = NULL;
+
+ if (tex)
+ {
+ CoglBool auto_mipmap = !(flags & COGL_TEXTURE_NO_AUTO_MIPMAP);
+ cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex),
+ auto_mipmap);
+ }
+ else
+ {
+ /* Otherwise create a sliced texture */
+ tex = COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_bitmap (bitmap,
+ flags,
+ internal_format,
+ error));
+ }
+
+ return tex;
+}
+
+CoglTexture *
+cogl_texture_new_from_file (CoglContext *ctx,
+ const char *filename,
+ CoglTextureFlags flags,
+ CoglPixelFormat internal_format,
+ CoglError **error)
+{
+ CoglBitmap *bmp;
+ CoglTexture *texture = NULL;
+ CoglPixelFormat src_format;
+
+ _COGL_RETURN_VAL_IF_FAIL (error == NULL || *error == NULL, NULL);
+
+ bmp = cogl_bitmap_new_from_file (ctx, filename, error);
+ if (bmp == NULL)
+ return NULL;
+
+ src_format = cogl_bitmap_get_format (bmp);
+
+ /* We know that the bitmap data is solely owned by this function so
+ we can do the premult conversion in place. This avoids having to
+ copy the bitmap which will otherwise happen in
+ _cogl_texture_prepare_for_upload */
+ internal_format =
+ _cogl_texture_determine_internal_format (src_format, internal_format);
+ if (!_cogl_texture_needs_premult_conversion (src_format, internal_format) ||
+ _cogl_bitmap_convert_premult_status (bmp,
+ src_format ^ COGL_PREMULT_BIT,
+ error))
+ {
+ texture =
+ cogl_texture_new_from_bitmap (bmp, flags, internal_format, error);
+ }
+
+ cogl_object_unref (bmp);
+
+ return texture;
+}
+
+CoglTexture *
+cogl_texture_gl_new_from_foreign (CoglContext *ctx,
+ unsigned int gl_handle,
+ unsigned int gl_target,
+ int width,
+ int height,
+ int x_pot_waste,
+ int y_pot_waste,
+ CoglPixelFormat format,
+ CoglError **error)
+{
+#if HAVE_COGL_GL
+ if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
+ {
+ CoglTextureRectangle *texture_rectangle;
+ CoglSubTexture *sub_texture;
+
+ if (x_pot_waste != 0 || y_pot_waste != 0)
+ {
+ /* It shouldn't be necessary to have waste in this case since
+ * the texture isn't limited to power of two sizes. */
+ g_warning ("You can't create a foreign GL_TEXTURE_RECTANGLE cogl "
+ "texture with waste\n");
+ return NULL;
+ }
+
+ texture_rectangle = cogl_texture_rectangle_new_from_foreign (ctx,
+ gl_handle,
+ width,
+ height,
+ format,
+ error);
+ if (!texture_rectangle)
+ return NULL;
+
+ /* CoglTextureRectangle textures work with non-normalized
+ * coordinates, but the semantics for this function that people
+ * depend on are that all returned textures work with normalized
+ * coordinates so we wrap with a CoglSubTexture... */
+ sub_texture = cogl_sub_texture_new (ctx,
+ COGL_TEXTURE (texture_rectangle),
+ 0, 0, width, height);
+ return COGL_TEXTURE (sub_texture);
+ }
+#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,
+ error));
+ else
+ {
+ return COGL_TEXTURE (cogl_texture_2d_gl_new_from_foreign (ctx,
+ gl_handle,
+ width,
+ height,
+ format,
+ error));
+ }
+}
diff --git a/cogl/cogl-texture-2d-sliced-private.h b/cogl/cogl-texture-2d-sliced-private.h
index 760db98d..9a43bdf7 100644
--- a/cogl/cogl-texture-2d-sliced-private.h
+++ b/cogl/cogl-texture-2d-sliced-private.h
@@ -44,13 +44,15 @@ struct _CoglTexture2DSliced
};
CoglTexture2DSliced *
-_cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle,
- GLenum gl_target,
- GLuint width,
- GLuint height,
- GLuint x_pot_waste,
- GLuint y_pot_waste,
- CoglPixelFormat format);
+_cogl_texture_2d_sliced_new_from_foreign (CoglContext *context,
+ unsigned int gl_handle,
+ unsigned int gl_target,
+ int width,
+ int height,
+ int x_pot_waste,
+ int y_pot_waste,
+ CoglPixelFormat format,
+ CoglError **error);
CoglTexture2DSliced *
_cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c
index 579759e1..ce498d3a 100644
--- a/cogl/cogl-texture-2d-sliced.c
+++ b/cogl/cogl-texture-2d-sliced.c
@@ -992,32 +992,32 @@ _cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
}
CoglTexture2DSliced *
-_cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle,
- GLenum gl_target,
- GLuint width,
- GLuint height,
- GLuint x_pot_waste,
- GLuint y_pot_waste,
- CoglPixelFormat format)
+_cogl_texture_2d_sliced_new_from_foreign (CoglContext *ctx,
+ unsigned int gl_handle,
+ unsigned int gl_target,
+ int width,
+ int height,
+ int x_pot_waste,
+ int y_pot_waste,
+ CoglPixelFormat format,
+ CoglError **error)
{
/* NOTE: width, height and internal format are not queriable
* in GLES, hence such a function prototype.
*/
- GLint gl_width = 0;
- GLint gl_height = 0;
+ int gl_width = 0;
+ int gl_height = 0;
CoglTexture2DSliced *tex_2ds;
- CoglTexture *tex;
- CoglSpan x_span;
- CoglSpan y_span;
- CoglTexture2D *tex_2d;
-
- _COGL_GET_CONTEXT (ctx, NULL);
+ CoglTexture *tex;
+ CoglSpan x_span;
+ CoglSpan y_span;
+ CoglTexture2D *tex_2d;
/* This should only be called when the texture target is 2D. If a
rectangle texture is used then _cogl_texture_new_from_foreign
will create a cogl_texture_rectangle instead */
- g_assert (gl_target == GL_TEXTURE_2D);
+ _COGL_RETURN_VAL_IF_FAIL (gl_target == GL_TEXTURE_2D, NULL);
gl_width = width + x_pot_waste;
gl_height = height + y_pot_waste;
@@ -1032,7 +1032,7 @@ _cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle,
gl_width,
gl_height,
format,
- NULL);
+ error);
if (!tex_2d)
return NULL;
diff --git a/cogl/cogl-texture-private.h b/cogl/cogl-texture-private.h
index ceec118d..e907242c 100644
--- a/cogl/cogl-texture-private.h
+++ b/cogl/cogl-texture-private.h
@@ -295,4 +295,8 @@ _cogl_texture_spans_foreach_in_region (CoglSpan *x_spans,
CoglTextureType
_cogl_texture_get_type (CoglTexture *texture);
+CoglBool
+_cogl_texture_needs_premult_conversion (CoglPixelFormat src_format,
+ CoglPixelFormat dst_format);
+
#endif /* __COGL_TEXTURE_PRIVATE_H */
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 4fa223f1..04f362d4 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -114,7 +114,7 @@ _cogl_texture_free (CoglTexture *texture)
g_free (texture);
}
-static CoglBool
+CoglBool
_cogl_texture_needs_premult_conversion (CoglPixelFormat src_format,
CoglPixelFormat dst_format)
{
@@ -282,263 +282,6 @@ _cogl_texture_prep_gl_alignment_for_pixels_download (int bpp,
GE( ctx, glPixelStorei (GL_PACK_ALIGNMENT, alignment) );
}
-CoglTexture *
-cogl_texture_new_with_size (unsigned int width,
- unsigned int height,
- CoglTextureFlags flags,
- CoglPixelFormat internal_format)
-{
- CoglTexture *tex;
-
- _COGL_GET_CONTEXT (ctx, NULL);
-
- if ((_cogl_util_is_pot (width) && _cogl_util_is_pot (height)) ||
- (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
- 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,
- NULL));
- }
- else
- tex = NULL;
-
- if (tex)
- {
- CoglBool auto_mipmap = !(flags & COGL_TEXTURE_NO_AUTO_MIPMAP);
- cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex),
- auto_mipmap);
- }
- else
- {
- /* If it fails resort to sliced textures */
- int max_waste = flags & COGL_TEXTURE_NO_SLICING ? -1 : COGL_TEXTURE_MAX_WASTE;
- tex = COGL_TEXTURE (cogl_texture_2d_sliced_new_with_size (ctx,
- width,
- height,
- max_waste,
- internal_format,
- NULL));
- }
-
- return tex;
-}
-
-CoglTexture *
-cogl_texture_new_from_data (CoglContext *ctx,
- int width,
- int height,
- CoglTextureFlags flags,
- CoglPixelFormat format,
- CoglPixelFormat internal_format,
- int rowstride,
- const uint8_t *data,
- CoglError **error)
-{
- CoglBitmap *bmp;
- CoglTexture *tex;
-
- _COGL_RETURN_VAL_IF_FAIL (format != COGL_PIXEL_FORMAT_ANY, NULL);
- _COGL_RETURN_VAL_IF_FAIL (data != NULL, NULL);
-
- /* Rowstride from width if not given */
- if (rowstride == 0)
- rowstride = width * _cogl_pixel_format_get_bytes_per_pixel (format);
-
- /* Wrap the data into a bitmap */
- bmp = cogl_bitmap_new_for_data (ctx,
- width, height,
- format,
- rowstride,
- (uint8_t *) data);
-
- tex = cogl_texture_new_from_bitmap (bmp, flags, internal_format, error);
-
- cogl_object_unref (bmp);
-
- return tex;
-}
-
-CoglTexture *
-cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
- CoglTextureFlags flags,
- CoglPixelFormat internal_format,
- CoglError **error)
-{
- CoglContext *ctx = _cogl_bitmap_get_context (bitmap);
- CoglAtlasTexture *atlas_tex;
- CoglTexture *tex;
- CoglError *internal_error = NULL;
-
- /* First try putting the texture in the atlas */
- if ((atlas_tex = _cogl_atlas_texture_new_from_bitmap (bitmap,
- flags,
- internal_format,
- &internal_error)))
- return COGL_TEXTURE (atlas_tex);
-
- if (cogl_error_matches (internal_error,
- COGL_SYSTEM_ERROR,
- COGL_SYSTEM_ERROR_NO_MEMORY))
- {
- _cogl_propogate_error (error, internal_error);
- return NULL;
- }
-
- cogl_error_free (internal_error);
- internal_error = NULL;
-
- /* If that doesn't work try a fast path 2D texture */
- if ((_cogl_util_is_pot (bitmap->width) &&
- _cogl_util_is_pot (bitmap->height)) ||
- (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
- cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP)))
- {
- tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap,
- internal_format,
- &internal_error));
-
- if (cogl_error_matches (internal_error,
- COGL_SYSTEM_ERROR,
- COGL_SYSTEM_ERROR_NO_MEMORY))
- {
- _cogl_propogate_error (error, internal_error);
- return NULL;
- }
-
- if (!tex)
- {
- cogl_error_free (internal_error);
- internal_error = NULL;
- }
- }
- else
- tex = NULL;
-
- if (tex)
- {
- CoglBool auto_mipmap = !(flags & COGL_TEXTURE_NO_AUTO_MIPMAP);
- cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex),
- auto_mipmap);
- }
- else
- {
- /* Otherwise create a sliced texture */
- tex = COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_bitmap (bitmap,
- flags,
- internal_format,
- error));
- }
-
- return tex;
-}
-
-CoglTexture *
-cogl_texture_new_from_file (const char *filename,
- CoglTextureFlags flags,
- CoglPixelFormat internal_format,
- CoglError **error)
-{
- CoglBitmap *bmp;
- CoglTexture *texture = NULL;
- CoglPixelFormat src_format;
-
- _COGL_GET_CONTEXT (ctx, 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;
-
- src_format = cogl_bitmap_get_format (bmp);
-
- /* We know that the bitmap data is solely owned by this function so
- we can do the premult conversion in place. This avoids having to
- copy the bitmap which will otherwise happen in
- _cogl_texture_prepare_for_upload */
- internal_format =
- _cogl_texture_determine_internal_format (src_format, internal_format);
- if (!_cogl_texture_needs_premult_conversion (src_format, internal_format) ||
- _cogl_bitmap_convert_premult_status (bmp,
- src_format ^ COGL_PREMULT_BIT,
- error))
- {
- texture =
- cogl_texture_new_from_bitmap (bmp, flags, internal_format, error);
- }
-
- cogl_object_unref (bmp);
-
- return texture;
-}
-
-CoglTexture *
-cogl_texture_new_from_foreign (GLuint gl_handle,
- GLenum gl_target,
- GLuint width,
- GLuint height,
- GLuint x_pot_waste,
- GLuint y_pot_waste,
- CoglPixelFormat format)
-{
-#if HAVE_COGL_GL
- if (gl_target == GL_TEXTURE_RECTANGLE_ARB)
- {
- CoglTextureRectangle *texture_rectangle;
- CoglSubTexture *sub_texture;
-
- _COGL_GET_CONTEXT (ctx, NULL);
-
- if (x_pot_waste != 0 || y_pot_waste != 0)
- {
- /* It shouldn't be necessary to have waste in this case since
- * the texture isn't limited to power of two sizes. */
- g_warning ("You can't create a foreign GL_TEXTURE_RECTANGLE cogl "
- "texture with waste\n");
- return NULL;
- }
-
- texture_rectangle = cogl_texture_rectangle_new_from_foreign (ctx,
- gl_handle,
- width,
- height,
- format,
- NULL);
-
- /* CoglTextureRectangle textures work with non-normalized
- * coordinates, but the semantics for this function that people
- * depend on are that all returned texture works with normalized
- * coordinates so we wrap with a CoglSubTexture... */
- sub_texture = cogl_sub_texture_new (ctx,
- COGL_TEXTURE (texture_rectangle),
- 0, 0, width, height);
- return COGL_TEXTURE (sub_texture);
- }
-#endif
-
- if (x_pot_waste != 0 || y_pot_waste != 0)
- return COGL_TEXTURE (_cogl_texture_2d_sliced_new_from_foreign (gl_handle,
- gl_target,
- width,
- height,
- x_pot_waste,
- y_pot_waste,
- format));
- else
- {
- _COGL_GET_CONTEXT (ctx, NULL);
- return COGL_TEXTURE (cogl_texture_2d_gl_new_from_foreign (ctx,
- gl_handle,
- width,
- height,
- format,
- NULL));
- }
-}
-
CoglBool
_cogl_texture_is_foreign (CoglTexture *texture)
{
diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h
index 6bac91ee..27adf936 100644
--- a/cogl/cogl-texture.h
+++ b/cogl/cogl-texture.h
@@ -102,11 +102,13 @@ uint32_t cogl_texture_error_domain (void);
/**
* cogl_texture_new_with_size:
+ * @context: A #CoglContext
* @width: width of texture in pixels.
* @height: height of texture in pixels.
* @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture.
+ * @error: A #CoglError to catch exceptional errors or %NULL
*
* Creates a new #CoglTexture with the specified dimensions and pixel format.
*
@@ -115,13 +117,16 @@ uint32_t cogl_texture_error_domain (void);
* Since: 0.8
*/
CoglTexture *
-cogl_texture_new_with_size (unsigned int width,
- unsigned int height,
+cogl_texture_new_with_size (CoglContext *ctx,
+ int width,
+ int height,
CoglTextureFlags flags,
- CoglPixelFormat internal_format);
+ CoglPixelFormat internal_format,
+ CoglError **error);
/**
* cogl_texture_new_from_file:
+ * @context: A #CoglContext
* @filename: the file to load
* @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
@@ -132,7 +137,7 @@ cogl_texture_new_with_size (unsigned int width,
* 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: return location for a #CoglError or %NULL
+ * @error: A #CoglError to catch exceptional errors or %NULL
*
* Creates a #CoglTexture from an image file.
*
@@ -141,13 +146,15 @@ cogl_texture_new_with_size (unsigned int width,
* Since: 0.8
*/
CoglTexture *
-cogl_texture_new_from_file (const char *filename,
- CoglTextureFlags flags,
- CoglPixelFormat internal_format,
- CoglError **error);
+cogl_texture_new_from_file (CoglContext *context,
+ const char *filename,
+ CoglTextureFlags flags,
+ CoglPixelFormat internal_format,
+ CoglError **error);
/**
* cogl_texture_new_from_data:
+ * @context: A #CoglContext
* @width: width of texture in pixels
* @height: height of texture in pixels
* @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
@@ -163,7 +170,7 @@ cogl_texture_new_from_file (const char *filename,
* @rowstride: the memory offset in bytes between the starts of
* scanlines in @data
* @data: pointer the memory region where the source buffer resides
- * @error: A #CoglError for returning exceptional errors
+ * @error: A #CoglError to catch exceptional errors or %NULL
*
* Creates a new #CoglTexture based on data residing in memory.
*
@@ -183,7 +190,8 @@ cogl_texture_new_from_data (CoglContext *ctx,
CoglError **error);
/**
- * cogl_texture_new_from_foreign:
+ * cogl_texture_gl_new_from_foreign:
+ * @context: A #CoglContext
* @gl_handle: opengl handle of foreign texture.
* @gl_target: opengl target type of foreign texture
* @width: width of foreign texture
@@ -191,6 +199,7 @@ cogl_texture_new_from_data (CoglContext *ctx,
* @x_pot_waste: horizontal waste on the right hand edge of the texture.
* @y_pot_waste: vertical waste on the bottom edge of the texture.
* @format: format of the foreign texture.
+ * @error: A #CoglError to catch exceptional errors or %NULL
*
* Creates a #CoglTexture based on an existing OpenGL texture; the
* width, height and format are passed along since it is not always
@@ -208,13 +217,15 @@ cogl_texture_new_from_data (CoglContext *ctx,
* Since: 0.8
*/
CoglTexture *
-cogl_texture_new_from_foreign (unsigned int gl_handle,
- unsigned int gl_target,
- unsigned int width,
- unsigned int height,
- unsigned int x_pot_waste,
- unsigned int y_pot_waste,
- CoglPixelFormat format);
+cogl_texture_gl_new_from_foreign (CoglContext *context,
+ unsigned int gl_handle,
+ unsigned int gl_target,
+ int width,
+ int height,
+ int x_pot_waste,
+ int y_pot_waste,
+ CoglPixelFormat format,
+ CoglError **error);
/**
* cogl_texture_new_from_bitmap:
@@ -222,6 +233,7 @@ cogl_texture_new_from_foreign (unsigned int gl_handle,
* @flags: Optional flags for the texture, or %COGL_TEXTURE_NONE
* @internal_format: the #CoglPixelFormat to use for the GPU storage of the
* texture
+ * @error: A #CoglError to catch exceptional errors or %NULL
*
* Creates a #CoglTexture from a #CoglBitmap.
*
diff --git a/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/winsys/cogl-texture-pixmap-x11.c
index ddeee447..31492f9b 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11.c
+++ b/cogl/winsys/cogl-texture-pixmap-x11.c
@@ -500,15 +500,18 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
if (tex_pixmap->tex == NULL)
{
CoglPixelFormat texture_format;
+ CoglContext *ctx = COGL_TEXTURE (tex_pixmap)->context;
texture_format = (tex_pixmap->depth >= 32
? COGL_PIXEL_FORMAT_RGBA_8888_PRE
: COGL_PIXEL_FORMAT_RGB_888);
- tex_pixmap->tex = cogl_texture_new_with_size (tex_pixmap->width,
+ tex_pixmap->tex = cogl_texture_new_with_size (ctx,
+ tex_pixmap->width,
tex_pixmap->height,
COGL_TEXTURE_NONE,
- texture_format);
+ texture_format,
+ NULL);
}
if (tex_pixmap->image == NULL)
diff --git a/examples/cogl-crate.c b/examples/cogl-crate.c
index 6fd47aed..3d9fb28d 100644
--- a/examples/cogl-crate.c
+++ b/examples/cogl-crate.c
@@ -220,7 +220,8 @@ main (int argc, char **argv)
/* Load a jpeg crate texture from a file */
printf ("crate.jpg (CC by-nc-nd http://bit.ly/9kP45T) ShadowRunner27 http://bit.ly/m1YXLh\n");
- data.texture = cogl_texture_new_from_file (COGL_EXAMPLES_DATA "crate.jpg",
+ data.texture = cogl_texture_new_from_file (ctx,
+ COGL_EXAMPLES_DATA "crate.jpg",
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY,
&error);
diff --git a/examples/cogl-gles2-context.c b/examples/cogl-gles2-context.c
index 70aed2f4..d9a4d12a 100644
--- a/examples/cogl-gles2-context.c
+++ b/examples/cogl-gles2-context.c
@@ -99,10 +99,12 @@ main (int argc, char **argv)
data.pipeline = cogl_pipeline_new (data.ctx);
data.offscreen_texture =
- cogl_texture_new_with_size (OFFSCREEN_WIDTH,
+ cogl_texture_new_with_size (data.ctx,
+ OFFSCREEN_WIDTH,
OFFSCREEN_HEIGHT,
COGL_TEXTURE_NO_SLICING,
- COGL_PIXEL_FORMAT_ANY);
+ COGL_PIXEL_FORMAT_ANY,
+ NULL);
data.offscreen = cogl_offscreen_new_to_texture (data.offscreen_texture);
data.gles2_ctx = cogl_gles2_context_new (data.ctx, &error);
diff --git a/examples/cogl-msaa.c b/examples/cogl-msaa.c
index 73f9c4e2..744f7e31 100644
--- a/examples/cogl-msaa.c
+++ b/examples/cogl-msaa.c
@@ -62,9 +62,11 @@ main (int argc, char **argv)
cogl_onscreen_show (onscreen);
- tex = cogl_texture_new_with_size (320, 480,
+ tex = cogl_texture_new_with_size (ctx,
+ 320, 480,
COGL_TEXTURE_NO_SLICING,
- COGL_PIXEL_FORMAT_ANY);
+ COGL_PIXEL_FORMAT_ANY,
+ NULL);
offscreen = cogl_offscreen_new_to_texture (tex);
offscreen_fb = COGL_FRAMEBUFFER (offscreen);
cogl_framebuffer_set_samples_per_pixel (offscreen_fb, 4);
diff --git a/tests/conform/test-backface-culling.c b/tests/conform/test-backface-culling.c
index 13dde32f..65b55bdb 100644
--- a/tests/conform/test-backface-culling.c
+++ b/tests/conform/test-backface-culling.c
@@ -238,9 +238,11 @@ test_backface_culling (void)
state.texture = make_texture ();
- tex = cogl_texture_new_with_size (state.width, state.height,
+ tex = cogl_texture_new_with_size (test_ctx,
+ state.width, state.height,
COGL_TEXTURE_NO_SLICING,
- COGL_PIXEL_FORMAT_ANY); /* internal fmt */
+ COGL_PIXEL_FORMAT_ANY, /* internal fmt */
+ NULL); /* don't catch errors */
state.offscreen = COGL_FRAMEBUFFER (cogl_offscreen_new_to_texture (tex));
state.offscreen_tex = tex;
diff --git a/tests/conform/test-color-mask.c b/tests/conform/test-color-mask.c
index 9068363d..cb65f9c5 100644
--- a/tests/conform/test-color-mask.c
+++ b/tests/conform/test-color-mask.c
@@ -81,9 +81,10 @@ test_color_mask (void)
for (i = 0; i < NUM_FBOS; i++)
{
- state.tex[i] = cogl_texture_new_with_size (128, 128,
+ state.tex[i] = cogl_texture_new_with_size (test_ctx, 128, 128,
COGL_TEXTURE_NO_ATLAS,
- COGL_PIXEL_FORMAT_RGB_888);
+ COGL_PIXEL_FORMAT_RGB_888,
+ NULL);
state.fbo[i] = COGL_FRAMEBUFFER (