int dst_y,
unsigned int dst_width,
unsigned int dst_height,
- int width,
- int height,
- CoglPixelFormat format,
- unsigned int rowstride,
- const guint8 *data)
+ CoglBitmap *bmp)
{
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
/* If the texture is in the atlas then we need to copy the edge
pixels to the border */
if (atlas_tex->in_atlas)
- {
- int bpp;
- CoglBitmap source_bmp;
- CoglBitmap tmp_bmp;
- gboolean tmp_bmp_owner = FALSE;
- gboolean success;
-
- /* Check for valid format */
- if (format == COGL_PIXEL_FORMAT_ANY)
- return FALSE;
-
- /* Shortcut out early if the image is empty */
- if (width == 0 || height == 0)
- return TRUE;
-
- /* Init source bitmap */
- source_bmp.width = width;
- source_bmp.height = height;
- source_bmp.format = format;
- source_bmp.data = (guint8 *)data;
-
- /* Rowstride from width if none specified */
- bpp = _cogl_get_format_bpp (format);
- source_bmp.rowstride = (rowstride == 0) ? width * bpp : rowstride;
-
- /* Prepare the bitmap so that it will do the premultiplication
- conversion */
- _cogl_texture_prepare_for_upload (&source_bmp,
- atlas_tex->format,
- NULL,
- &tmp_bmp,
- &tmp_bmp_owner,
- NULL, NULL, NULL);
-
- /* Upload the data ignoring the premult bit */
- success =
- _cogl_atlas_texture_set_region_with_border (atlas_tex,
- src_x, src_y,
- dst_x, dst_y,
- dst_width, dst_height,
- tmp_bmp.width,
- tmp_bmp.height,
- tmp_bmp.format &
- ~COGL_PREMULT_BIT,
- tmp_bmp.rowstride,
- tmp_bmp.data);
-
- /* Free data if owner */
- if (tmp_bmp_owner)
- g_free (tmp_bmp.data);
-
- return success;
- }
+ /* Upload the data ignoring the premult bit */
+ return _cogl_atlas_texture_set_region_with_border (atlas_tex,
+ src_x, src_y,
+ dst_x, dst_y,
+ dst_width, dst_height,
+ bmp->width,
+ bmp->height,
+ bmp->format &
+ ~COGL_PREMULT_BIT,
+ bmp->rowstride,
+ bmp->data);
+
else
/* Otherwise we can just forward on to the sub texture */
- return cogl_texture_set_region (atlas_tex->sub_texture,
- src_x, src_y,
- dst_x, dst_y,
- dst_width, dst_height,
- width, height,
- format, rowstride,
- data);
+ return _cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
+ src_x, src_y,
+ dst_x, dst_y,
+ dst_width, dst_height,
+ bmp);
}
static gboolean
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
- int width,
- int height,
- CoglPixelFormat format,
- unsigned int rowstride,
- const guint8 *data)
+ CoglBitmap *bmp)
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
- return cogl_texture_set_region (sub_tex->full_texture,
- src_x, src_y,
- dst_x + sub_tex->sub_x,
- dst_y + sub_tex->sub_y,
- dst_width, dst_height,
- width, height,
- format,
- rowstride,
- data);
+ return _cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
+ src_x, src_y,
+ dst_x + sub_tex->sub_x,
+ dst_y + sub_tex->sub_y,
+ dst_width, dst_height,
+ bmp);
}
static void
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
- int width,
- int height,
- CoglPixelFormat format,
- unsigned int rowstride,
- const guint8 *data)
+ CoglBitmap *bmp)
{
CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex);
- int bpp;
- CoglBitmap source_bmp;
- CoglBitmap tmp_bmp;
- gboolean tmp_bmp_owner = FALSE;
- GLenum closest_gl_format;
- GLenum closest_gl_type;
-
- /* Check for valid format */
- if (format == COGL_PIXEL_FORMAT_ANY)
- return FALSE;
-
- /* Shortcut out early if the image is empty */
- if (width == 0 || height == 0)
- return TRUE;
-
- /* Init source bitmap */
- source_bmp.width = width;
- source_bmp.height = height;
- source_bmp.format = format;
- source_bmp.data = (guint8 *)data;
-
- /* Rowstride from width if none specified */
- bpp = _cogl_get_format_bpp (format);
- source_bmp.rowstride = (rowstride == 0) ? width * bpp : rowstride;
-
- /* Prepare the bitmap so that it will do the premultiplication
- conversion */
- _cogl_texture_prepare_for_upload (&source_bmp,
- tex_2ds->format,
- NULL,
- &tmp_bmp,
- &tmp_bmp_owner,
- NULL,
- &closest_gl_format,
- &closest_gl_type);
+ GLenum gl_format;
+ GLenum gl_type;
+ _cogl_pixel_format_to_gl (bmp->format,
+ NULL, /* internal format */
+ &gl_format,
+ &gl_type);
/* Send data to GL */
_cogl_texture_2d_sliced_upload_subregion_to_gl (tex_2ds,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
- &tmp_bmp,
- closest_gl_format,
- closest_gl_type);
-
- /* Free data if owner */
- if (tmp_bmp_owner)
- g_free (tmp_bmp.data);
+ bmp,
+ gl_format,
+ gl_type);
return TRUE;
}
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
- int width,
- int height,
- CoglPixelFormat format,
- unsigned int rowstride,
- const guint8 *data)
+ CoglBitmap *bmp)
{
- CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
- int bpp;
- CoglBitmap source_bmp;
- CoglBitmap tmp_bmp;
- gboolean tmp_bmp_owner = FALSE;
- GLenum closest_gl_format;
- GLenum closest_gl_type;
-
- /* Check for valid format */
- if (format == COGL_PIXEL_FORMAT_ANY)
- return FALSE;
-
- /* Shortcut out early if the image is empty */
- if (width == 0 || height == 0)
- return TRUE;
-
- /* Init source bitmap */
- source_bmp.width = width;
- source_bmp.height = height;
- source_bmp.format = format;
- source_bmp.data = (guint8 *)data;
+ CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
+ GLenum gl_format;
+ GLenum gl_type;
- /* Rowstride from width if none specified */
- bpp = _cogl_get_format_bpp (format);
- source_bmp.rowstride = (rowstride == 0) ? width * bpp : rowstride;
-
- /* Prepare the bitmap so that it will do the premultiplication
- conversion */
- _cogl_texture_prepare_for_upload (&source_bmp,
- tex_2d->format,
- NULL,
- &tmp_bmp,
- &tmp_bmp_owner,
- NULL,
- &closest_gl_format,
- &closest_gl_type);
+ _cogl_pixel_format_to_gl (bmp->format,
+ NULL, /* internal format */
+ &gl_format,
+ &gl_type);
/* Send data to GL */
_cogl_texture_driver_upload_subregion_to_gl (GL_TEXTURE_2D,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
- &tmp_bmp,
- closest_gl_format,
- closest_gl_type);
-
- /* Free data if owner */
- if (tmp_bmp_owner)
- g_free (tmp_bmp.data);
+ bmp,
+ gl_format,
+ gl_type);
tex_2d->mipmaps_dirty = TRUE;
/* Virtual functions that must be implemented for a texture
backend */
+ /* This should update the specified sub region of the texture with a
+ sub region of the given bitmap. The bitmap will have first been
+ converted to a suitable format for uploading if neccessary. */
gboolean (* set_region) (CoglTexture *tex,
int src_x,
int src_y,
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
- int width,
- int height,
- CoglPixelFormat format,
- unsigned int rowstride,
- const guint8 *data);
+ CoglBitmap *bitmap);
/* This should copy the image data of the texture into @data. The
requested format will have been first passed through
gboolean
_cogl_texture_is_foreign (CoglHandle handle);
+gboolean
+_cogl_texture_set_region_from_bitmap (CoglHandle handle,
+ int src_x,
+ int src_y,
+ int dst_x,
+ int dst_y,
+ unsigned int dst_width,
+ unsigned int dst_height,
+ CoglBitmap *bmp);
+
#endif /* __COGL_TEXTURE_PRIVATE_H */
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
- int width,
- int height,
- CoglPixelFormat format,
- unsigned int rowstride,
- const guint8 *data)
+ CoglBitmap *bmp)
{
- CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
- int bpp;
- CoglBitmap source_bmp;
- CoglBitmap tmp_bmp;
- gboolean tmp_bmp_owner = FALSE;
- GLenum closest_gl_format;
- GLenum closest_gl_type;
-
- /* Check for valid format */
- if (format == COGL_PIXEL_FORMAT_ANY)
- return FALSE;
-
- /* Shortcut out early if the image is empty */
- if (width == 0 || height == 0)
- return TRUE;
-
- /* Init source bitmap */
- source_bmp.width = width;
- source_bmp.height = height;
- source_bmp.format = format;
- source_bmp.data = (guint8 *)data;
+ CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
+ GLenum gl_format;
+ GLenum gl_type;
- /* Rowstride from width if none specified */
- bpp = _cogl_get_format_bpp (format);
- source_bmp.rowstride = (rowstride == 0) ? width * bpp : rowstride;
-
- /* Prepare the bitmap so that it will do the premultiplication
- conversion */
- _cogl_texture_prepare_for_upload (&source_bmp,
- tex_rect->format,
- NULL,
- &tmp_bmp,
- &tmp_bmp_owner,
- NULL,
- &closest_gl_format,
- &closest_gl_type);
+ _cogl_pixel_format_to_gl (bmp->format,
+ NULL, /* internal format */
+ &gl_format,
+ &gl_type);
/* Send data to GL */
_cogl_texture_driver_upload_subregion_to_gl (GL_TEXTURE_RECTANGLE_ARB,
src_x, src_y,
dst_x, dst_y,
dst_width, dst_height,
- &tmp_bmp,
- closest_gl_format,
- closest_gl_type);
-
- /* Free data if owner */
- if (tmp_bmp_owner)
- g_free (tmp_bmp.data);
+ bmp,
+ gl_format,
+ gl_type);
return TRUE;
}
}
gboolean
+_cogl_texture_set_region_from_bitmap (CoglHandle handle,
+ int src_x,
+ int src_y,
+ int dst_x,
+ int dst_y,
+ unsigned int dst_width,
+ unsigned int dst_height,
+ CoglBitmap *bmp)
+{
+ CoglTexture *tex = COGL_TEXTURE (handle);
+ CoglBitmap tmp_bmp;
+ gboolean tmp_bmp_owner = FALSE;
+ GLenum closest_gl_format;
+ GLenum closest_gl_type;
+ gboolean ret;
+
+ /* Shortcut out early if the image is empty */
+ if (dst_width == 0 || dst_height == 0)
+ return TRUE;
+
+ /* Prepare the bitmap so that it will do the premultiplication
+ conversion */
+ _cogl_texture_prepare_for_upload (bmp,
+ cogl_texture_get_format (handle),
+ NULL,
+ &tmp_bmp,
+ &tmp_bmp_owner,
+ NULL,
+ &closest_gl_format,
+ &closest_gl_type);
+
+ ret = tex->vtable->set_region (handle,
+ src_x, src_y,
+ dst_x, dst_y,
+ dst_width, dst_height,
+ &tmp_bmp);
+
+ /* Free data if owner */
+ if (tmp_bmp_owner)
+ g_free (tmp_bmp.data);
+
+ return ret;
+}
+
+gboolean
cogl_texture_set_region (CoglHandle handle,
int src_x,
int src_y,
unsigned int rowstride,
const guint8 *data)
{
- CoglTexture *tex;
+ int bpp;
+ CoglBitmap source_bmp;
- if (!cogl_is_texture (handle))
+ /* Check for valid format */
+ if (format == COGL_PIXEL_FORMAT_ANY)
return FALSE;
- tex = COGL_TEXTURE (handle);
+ /* Init source bitmap */
+ source_bmp.width = width;
+ source_bmp.height = height;
+ source_bmp.format = format;
+ source_bmp.data = (guint8 *) data;
+
+ /* Rowstride from width if none specified */
+ bpp = _cogl_get_format_bpp (format);
+ source_bmp.rowstride = (rowstride == 0) ? width * bpp : rowstride;
- return tex->vtable->set_region (tex,
- src_x, src_y,
- dst_x, dst_y,
- dst_width, dst_height,
- width, height,
- format,
- rowstride,
- data);
+ return _cogl_texture_set_region_from_bitmap (handle,
+ src_x, src_y,
+ dst_x, dst_y,
+ dst_width, dst_height,
+ &source_bmp);
}
/* Reads back the contents of a texture by rendering it to the framebuffer
int dst_y,
unsigned int dst_width,
unsigned int dst_height,
- int width,
- int height,
- CoglPixelFormat format,
- unsigned int rowstride,
- const guint8 *data)
+ CoglBitmap *bmp)
{
/* This doesn't make much sense for texture from pixmap so it's not
supported */