Add constructors which take a CoglBitmap to all primitive textures

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.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Neil Roberts 2012-04-04 15:10:04 +01:00
parent e7f1582630
commit 6197e3abf3
13 changed files with 157 additions and 92 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -112,12 +112,12 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
* @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
* 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
* 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
@ -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_pipeline_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:

View File

@ -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 */

View File

@ -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);

View File

@ -88,12 +88,12 @@ cogl_texture_3d_new_with_size (CoglContext *context,
* @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
* 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
* 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
@ -131,6 +131,40 @@ cogl_texture_3d_new_from_data (CoglContext *context,
const guint8 *data,
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

View File

@ -48,11 +48,6 @@ struct _CoglTextureRectangle
gboolean is_foreign;
};
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,

View File

@ -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,

View File

@ -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 */

View File

@ -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

View File

@ -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>