[Cogl] [PATCH 3/4] Add constructors which take a CoglBitmap to all primitive textures
Neil Roberts
neil at linux.intel.com
Wed Apr 4 09:13:11 PDT 2012
This adds public constructors which take a CoglBitmap to all primitive
texture types. This constructor should be considered the canonical
constructor for initializing the texture with data because it should
be possible to wrap any type of data in a CoglBitmap. Having at least
this single constructor avoids the need to have an explosion of
constructors such as new_from_data, new_from_pixel_buffer and
new_from_file etc.
The already available internal bitmap constructor for CoglTexture2D
has had its flags parameter removed under the assumption that flags do
not make sense for primitive textures. The meta constructor
cogl_texture_new_from_bitmap now just explicitly calls set_auto_mipmap
after constructing the texture depending on the value of the
COGL_TEXTURE_NO_AUTO_MIPMAP flag.
---
cogl/cogl-atlas.c | 6 ++--
cogl/cogl-context.c | 25 ++++++-------
cogl/cogl-texture-2d-private.h | 6 ---
cogl/cogl-texture-2d.c | 14 +++-----
cogl/cogl-texture-2d.h | 38 ++++++++++++++++++++
cogl/cogl-texture-3d-private.h | 32 ----------------
cogl/cogl-texture-3d.c | 20 +++++-----
cogl/cogl-texture-3d.h | 34 +++++++++++++++++
cogl/cogl-texture-rectangle-private.h | 5 ---
cogl/cogl-texture-rectangle.c | 8 ++--
cogl/cogl-texture-rectangle.h | 34 +++++++++++++++++-
cogl/cogl-texture.c | 16 ++++++---
.../cogl-2.0-experimental-sections.txt | 3 ++
13 files changed, 153 insertions(+), 88 deletions(-)
diff --git a/cogl/cogl-atlas.c b/cogl/cogl-atlas.c
index 014d612..7dd1cdc 100644
--- a/cogl/cogl-atlas.c
+++ b/cogl/cogl-atlas.c
@@ -293,9 +293,9 @@ _cogl_atlas_create_texture (CoglAtlas *atlas,
width * bpp,
clear_data);
- tex = _cogl_texture_2d_new_from_bitmap (clear_bmp, COGL_TEXTURE_NONE,
- atlas->texture_format,
- NULL);
+ tex = cogl_texture_2d_new_from_bitmap (clear_bmp,
+ atlas->texture_format,
+ NULL);
cogl_object_unref (clear_bmp);
g_free (clear_data);
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index 937ea13..40d6de0 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -397,23 +397,22 @@ cogl_context_new (CoglDisplay *display,
/* Create default textures used for fall backs */
context->default_gl_texture_2d_tex =
- _cogl_texture_2d_new_from_bitmap (default_texture_bitmap,
- COGL_TEXTURE_NONE,
- /* internal format */
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- NULL);
+ cogl_texture_2d_new_from_bitmap (default_texture_bitmap,
+ /* internal format */
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ NULL);
/* If 3D or rectangle textures aren't supported then these should
just silently return NULL */
context->default_gl_texture_3d_tex =
- _cogl_texture_3d_new_from_bitmap (default_texture_bitmap,
- 1, /* height */
- 1, /* depth */
- COGL_PIXEL_FORMAT_RGBA_8888_PRE,
- NULL);
+ cogl_texture_3d_new_from_bitmap (default_texture_bitmap,
+ 1, /* height */
+ 1, /* depth */
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ NULL);
context->default_gl_texture_rect_tex =
- _cogl_texture_rectangle_new_from_bitmap (default_texture_bitmap,
- COGL_TEXTURE_NONE,
- COGL_PIXEL_FORMAT_RGBA_8888_PRE);
+ cogl_texture_rectangle_new_from_bitmap (default_texture_bitmap,
+ COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+ NULL);
cogl_object_unref (default_texture_bitmap);
diff --git a/cogl/cogl-texture-2d-private.h b/cogl/cogl-texture-2d-private.h
index b19c6ea..8907610 100644
--- a/cogl/cogl-texture-2d-private.h
+++ b/cogl/cogl-texture-2d-private.h
@@ -53,12 +53,6 @@ struct _CoglTexture2D
CoglTexturePixel first_pixel;
};
-CoglHandle
-_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
- CoglTextureFlags flags,
- CoglPixelFormat internal_format,
- GError **error);
-
#if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
/* NB: The reason we require the width, height and format to be passed
* even though they may seem redundant is because GLES 1/2 don't
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index da78f13..7328423 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -221,11 +221,10 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
return _cogl_texture_2d_handle_new (tex_2d);
}
-CoglHandle
-_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
- CoglTextureFlags flags,
- CoglPixelFormat internal_format,
- GError **error)
+CoglTexture2D *
+cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
+ CoglPixelFormat internal_format,
+ GError **error)
{
CoglTexture2D *tex_2d;
CoglBitmap *dst_bmp;
@@ -301,9 +300,6 @@ _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
cogl_object_unref (dst_bmp);
- _cogl_texture_2d_set_auto_mipmap (COGL_TEXTURE (tex_2d),
- !(flags & COGL_TEXTURE_NO_AUTO_MIPMAP));
-
return _cogl_texture_2d_handle_new (tex_2d);
}
@@ -334,7 +330,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
rowstride,
(guint8 *) data);
- tex =_cogl_texture_2d_new_from_bitmap (bmp, COGL_TEXTURE_NONE,
+ tex = cogl_texture_2d_new_from_bitmap (bmp,
internal_format,
error);
diff --git a/cogl/cogl-texture-2d.h b/cogl/cogl-texture-2d.h
index f191924..3389fb4 100644
--- a/cogl/cogl-texture-2d.h
+++ b/cogl/cogl-texture-2d.h
@@ -152,6 +152,44 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
const guint8 *data,
GError **error);
+/**
+ * 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_material_set_blend()) or use the data for
+ * something other than straight blending.
+ * @error: A #GError for exceptions
+ *
+ * Creates a new #CoglTexture2D texture based on data residing in a
+ * bitmap. These are unlike sliced textures for example which may be
+ * comprised of multiple internal textures, or atlas textures where
+ * Cogl has to modify texture coordinates before they may be used by
+ * the GPU.
+ *
+ * <note>Many GPUs only support power of two sizes for #CoglTexture2D
+ * textures. You can check support for non power of two textures by
+ * checking for the %COGL_FEATURE_ID_TEXTURE_NPOT feature via
+ * cogl_has_feature().</note>
+ *
+ * Returns: 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.
+ *
+ * Since: 2.0
+ * Stability: unstable
+ */
+CoglTexture2D *
+cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap,
+ CoglPixelFormat internal_format,
+ GError **error);
+
+
#define cogl_texture_2d_new_from_foreign cogl_texture_2d_new_from_foreign_EXP
/**
* cogl_texture_2d_new_from_foreign:
diff --git a/cogl/cogl-texture-3d-private.h b/cogl/cogl-texture-3d-private.h
index 7b3f9cd..db7194e 100644
--- a/cogl/cogl-texture-3d-private.h
+++ b/cogl/cogl-texture-3d-private.h
@@ -55,36 +55,4 @@ struct _CoglTexture3D
CoglTexturePixel first_pixel;
};
-/*
- * cogl_texture_3d_new_from_bitmap:
- * @bmp_handle: 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 GError return location.
- *
- * Creates a new 3D texture and initializes it with the images in
- * @bmp_handle. The images are assumed to be packed together after one
- * another in the increasing y axis. The height of individual image is
- * given as @height and the number of images is given in @depth. The
- * actual height of the bitmap can be larger than @height × @depth. In
- * this case it assumes there is padding between the images.
- *
- * Return value: the newly created texture or %NULL if
- * there was an error.
- */
-CoglTexture3D *
-_cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
- unsigned int height,
- unsigned int depth,
- CoglPixelFormat internal_format,
- GError **error);
-
#endif /* __COGL_TEXTURE_3D_PRIVATE_H */
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
index 9d5b01e..c4500d5 100644
--- a/cogl/cogl-texture-3d.c
+++ b/cogl/cogl-texture-3d.c
@@ -245,11 +245,11 @@ cogl_texture_3d_new_with_size (CoglContext *ctx,
}
CoglTexture3D *
-_cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
- unsigned int height,
- unsigned int depth,
- CoglPixelFormat internal_format,
- GError **error)
+cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
+ unsigned int height,
+ unsigned int depth,
+ CoglPixelFormat internal_format,
+ GError **error)
{
CoglTexture3D *tex_3d;
CoglBitmap *dst_bmp;
@@ -407,11 +407,11 @@ cogl_texture_3d_new_from_data (CoglContext *context,
rowstride,
(guint8 *) data);
- ret = _cogl_texture_3d_new_from_bitmap (bitmap,
- height,
- depth,
- internal_format,
- error);
+ ret = cogl_texture_3d_new_from_bitmap (bitmap,
+ height,
+ depth,
+ internal_format,
+ error);
cogl_object_unref (bitmap);
diff --git a/cogl/cogl-texture-3d.h b/cogl/cogl-texture-3d.h
index 6c14912..35b062c 100644
--- a/cogl/cogl-texture-3d.h
+++ b/cogl/cogl-texture-3d.h
@@ -132,6 +132,40 @@ cogl_texture_3d_new_from_data (CoglContext *context,
GError **error);
/**
+ * cogl_texture_3d_new_from_bitmap:
+ * @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 GError return location.
+ *
+ * Creates a new 3D texture and initializes it with the images in
+ * @bitmap. The images are assumed to be packed together after one
+ * another in the increasing y axis. The height of individual image is
+ * given as @height and the number of images is given in @depth. The
+ * actual height of the bitmap can be larger than @height × @depth. In
+ * this case it assumes there is padding between the images.
+ *
+ * Return value: the newly created texture or %NULL if
+ * there was an error.
+ * Since: 2.0
+ * Stability: unstable
+ */
+CoglTexture3D *
+cogl_texture_3d_new_from_bitmap (CoglBitmap *bitmap,
+ unsigned int height,
+ unsigned int depth,
+ CoglPixelFormat internal_format,
+ GError **error);
+
+/**
* cogl_is_texture_3d:
* @object: a #CoglObject
*
diff --git a/cogl/cogl-texture-rectangle-private.h b/cogl/cogl-texture-rectangle-private.h
index 0e95106..cfc7dc7 100644
--- a/cogl/cogl-texture-rectangle-private.h
+++ b/cogl/cogl-texture-rectangle-private.h
@@ -49,11 +49,6 @@ struct _CoglTextureRectangle
};
CoglTextureRectangle *
-_cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
- CoglTextureFlags flags,
- CoglPixelFormat internal_format);
-
-CoglTextureRectangle *
_cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
GLuint width,
GLuint height,
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
index cc665a0..3f8594f 100644
--- a/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl-texture-rectangle.c
@@ -229,9 +229,9 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
}
CoglTextureRectangle *
-_cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
- CoglTextureFlags flags,
- CoglPixelFormat internal_format)
+cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
+ CoglPixelFormat internal_format,
+ GError **error)
{
CoglTextureRectangle *tex_rect;
CoglBitmap *dst_bmp;
@@ -251,7 +251,7 @@ _cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
if (!_cogl_texture_rectangle_can_create (cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp),
internal_format,
- NULL))
+ error))
return NULL;
dst_bmp = _cogl_texture_prepare_for_upload (bmp,
diff --git a/cogl/cogl-texture-rectangle.h b/cogl/cogl-texture-rectangle.h
index 927bb93..b538e47 100644
--- a/cogl/cogl-texture-rectangle.h
+++ b/cogl/cogl-texture-rectangle.h
@@ -87,7 +87,7 @@ cogl_is_texture_rectangle (void *object);
* @internal_format: The desired internal texture format
* @error: An optional GError pointer for reporting exceptions
*
- * Allocates a new #CoglRectangle texture with a given @width, @height
+ * 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.
@@ -113,6 +113,38 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
CoglPixelFormat internal_format,
GError **error);
+/**
+ * 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 GError 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.
+ *
+ * <note>If you want to sample from a rectangle texture from GLSL you
+ * should use the sampler2DRect sampler type.</note>
+ *
+ * <note>Applications wanting to use #CoglTextureRectangle should
+ * first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
+ * using cogl_has_feature().</note>
+ *
+ * Returns: A pointer to a newly allocated #CoglRectangle texture
+ * or if the size was too large or there wasn't enough memory
+ * %NULL is returned and @error set.
+ * Since: 2.0
+ * Stability: unstable
+ */
+CoglTextureRectangle *
+cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap,
+ CoglPixelFormat internal_format,
+ GError **error);
+
G_END_DECLS
#endif /* __COGL_TEXURE_RECTANGLE_H */
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index f44970c..dcf89a8 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -53,6 +53,7 @@
#include "cogl-framebuffer-private.h"
#include "cogl1-context.h"
#include "cogl-sub-texture.h"
+#include "cogl-primitive-texture.h"
#include <string.h>
#include <stdlib.h>
@@ -373,6 +374,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
CoglPixelFormat internal_format)
{
CoglTexture *tex;
+ CoglTexture2D *tex_2d;
/* First try putting the texture in the atlas */
if ((tex = _cogl_atlas_texture_new_from_bitmap (bitmap,
@@ -381,11 +383,15 @@ cogl_texture_new_from_bitmap (CoglBitmap *bitmap,
return tex;
/* If that doesn't work try a fast path 2D texture */
- if ((tex = _cogl_texture_2d_new_from_bitmap (bitmap,
- flags,
- internal_format,
- NULL)))
- return tex;
+ if ((tex_2d = cogl_texture_2d_new_from_bitmap (bitmap,
+ internal_format,
+ NULL)))
+ {
+ cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex_2d),
+ !(flags &
+ COGL_TEXTURE_NO_AUTO_MIPMAP));
+ return COGL_TEXTURE (tex_2d);
+ }
/* Otherwise create a sliced texture */
return
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 ccf4a6d..a3852bc 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
@@ -314,6 +314,7 @@ COGL_TEXTURE_MAX_WASTE
<TITLE>2D textures</TITLE>
CoglTexture2D
cogl_texture_2d_new_with_size
+cogl_texture_2d_new_from_bitmap
cogl_texture_2d_new_from_data
cogl_texture_2d_new_from_foreign
cogl_is_texture_rectangle
@@ -324,6 +325,7 @@ cogl_is_texture_rectangle
<TITLE>Rectangle textures (non-normalized coordinates)</TITLE>
CoglTextureRectangle
cogl_texture_rectangle_new_with_size
+cogl_texture_rectangle_new_from_bitmap
cogl_is_texture_rectangle
</SECTION>
@@ -332,6 +334,7 @@ cogl_is_texture_rectangle
<TITLE>3D textures</TITLE>
CoglTexture3D
cogl_texture_3d_new_with_size
+cogl_texture_3d_new_from_bitmap
cogl_texture_3d_new_from_data
cogl_is_texture_3d
</SECTION>
--
1.7.3.16.g9464b
More information about the Cogl
mailing list