Export API for uploading a tex subregion from a CoglBuffer
This exposes 2 experimental functions that make it possible to upload a subregion of a texture from a CoglBuffer by first wrapping the buffer as a CoglBitmap and then allowing uploading of a subregion from a CoglBitmap. The new functions are: cogl_bitmap_new_from_buffer() and cogl_texture_set_region_from_bitmap() Actually for now we are exporting this API for practical reasons since we already had this API internally and it enables a specific feature that was requested, but it is worth nothing that it's quite likely we will replace these with functions that don't involve the CoglBitmap API at some point. For reference: The CoglBitmap API was actually removed from the 2.0 experimental API reference manual some time ago because the hope was that we'd come up with a neater replacement. It doesn't seem entirely clear what the scope of the CoglBitmap api is so it has became a bit of a dumping ground. CoglBitmap is used for image loading, as a means to represent the layout of image data and also internally deals with format conversions. Note: Because we are avoiding including CoglBitmap as part of the 2.0 API these functions aren't currently included in the 2.0 reference manual. Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
parent
7860df92d1
commit
a9184d5cb7
@ -437,7 +437,7 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
|||||||
CoglAtlas *atlas = atlas_tex->atlas;
|
CoglAtlas *atlas = atlas_tex->atlas;
|
||||||
|
|
||||||
/* Copy the central data */
|
/* Copy the central data */
|
||||||
if (!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
if (!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
dst_y + atlas_tex->rectangle.y + 1,
|
dst_y + atlas_tex->rectangle.y + 1,
|
||||||
@ -448,7 +448,7 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
|||||||
|
|
||||||
/* Update the left edge pixels */
|
/* Update the left edge pixels */
|
||||||
if (dst_x == 0 &&
|
if (dst_x == 0 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
atlas_tex->rectangle.x,
|
atlas_tex->rectangle.x,
|
||||||
dst_y + atlas_tex->rectangle.y + 1,
|
dst_y + atlas_tex->rectangle.y + 1,
|
||||||
@ -457,7 +457,7 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the right edge pixels */
|
/* Update the right edge pixels */
|
||||||
if (dst_x + dst_width == atlas_tex->rectangle.width - 2 &&
|
if (dst_x + dst_width == atlas_tex->rectangle.width - 2 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x + dst_width - 1, src_y,
|
src_x + dst_width - 1, src_y,
|
||||||
atlas_tex->rectangle.x +
|
atlas_tex->rectangle.x +
|
||||||
atlas_tex->rectangle.width - 1,
|
atlas_tex->rectangle.width - 1,
|
||||||
@ -467,7 +467,7 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the top edge pixels */
|
/* Update the top edge pixels */
|
||||||
if (dst_y == 0 &&
|
if (dst_y == 0 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
atlas_tex->rectangle.y,
|
atlas_tex->rectangle.y,
|
||||||
@ -476,7 +476,7 @@ _cogl_atlas_texture_set_region_with_border (CoglAtlasTexture *atlas_tex,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
/* Update the bottom edge pixels */
|
/* Update the bottom edge pixels */
|
||||||
if (dst_y + dst_height == atlas_tex->rectangle.height - 2 &&
|
if (dst_y + dst_height == atlas_tex->rectangle.height - 2 &&
|
||||||
!_cogl_texture_set_region_from_bitmap (atlas->texture,
|
!cogl_texture_set_region_from_bitmap (atlas->texture,
|
||||||
src_x, src_y + dst_height - 1,
|
src_x, src_y + dst_height - 1,
|
||||||
dst_x + atlas_tex->rectangle.x + 1,
|
dst_x + atlas_tex->rectangle.x + 1,
|
||||||
atlas_tex->rectangle.y +
|
atlas_tex->rectangle.y +
|
||||||
@ -526,7 +526,7 @@ _cogl_atlas_texture_set_region (CoglTexture *tex,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* Otherwise we can just forward on to the sub texture */
|
/* Otherwise we can just forward on to the sub texture */
|
||||||
return _cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
|
return cogl_texture_set_region_from_bitmap (atlas_tex->sub_texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
|
@ -83,17 +83,6 @@ _cogl_bitmap_new_shared (CoglBitmap *shared_bmp,
|
|||||||
int height,
|
int height,
|
||||||
int rowstride);
|
int rowstride);
|
||||||
|
|
||||||
/* This creates a cogl bitmap that internally references a pixel
|
|
||||||
array. The data is not copied. _cogl_bitmap_map will divert to
|
|
||||||
mapping the pixel array */
|
|
||||||
CoglBitmap *
|
|
||||||
_cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
|
|
||||||
CoglPixelFormat format,
|
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
int rowstride,
|
|
||||||
int offset);
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
|
_cogl_bitmap_can_convert (CoglPixelFormat src, CoglPixelFormat dst);
|
||||||
|
|
||||||
|
@ -327,7 +327,7 @@ cogl_bitmap_new_from_file (const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoglBitmap *
|
CoglBitmap *
|
||||||
_cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
|
cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
|
||||||
CoglPixelFormat format,
|
CoglPixelFormat format,
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#define __COGL_BITMAP_H__
|
#define __COGL_BITMAP_H__
|
||||||
|
|
||||||
#include <cogl/cogl-types.h>
|
#include <cogl/cogl-types.h>
|
||||||
|
#include <cogl/cogl-buffer.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -62,6 +63,37 @@ CoglBitmap *
|
|||||||
cogl_bitmap_new_from_file (const char *filename,
|
cogl_bitmap_new_from_file (const char *filename,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
#if defined (COGL_ENABLE_EXPERIMENTAL_API)
|
||||||
|
|
||||||
|
#define cogl_bitmap_new_from_buffer cogl_bitmap_new_from_buffer_EXP
|
||||||
|
/**
|
||||||
|
* cogl_bitmap_new_from_buffer:
|
||||||
|
* @buffer: A #CoglBuffer containing image data
|
||||||
|
* @format: The #CoglPixelFormat defining the format of the image data
|
||||||
|
* in the given @buffer.
|
||||||
|
* @width: The width of the image data in the given @buffer.
|
||||||
|
* @height: The height of the image data in the given @buffer.
|
||||||
|
* @rowstride: The rowstride in bytes of the image data in the given @buffer.
|
||||||
|
* @offset: The offset into the given @buffer to the first pixel that
|
||||||
|
* should be considered part of the #CoglBitmap.
|
||||||
|
*
|
||||||
|
* Wraps some image data that has been uploaded into a #CoglBuffer as
|
||||||
|
* a #CoglBitmap. The data is not copied in this process.
|
||||||
|
*
|
||||||
|
* Return value: a #CoglBitmap encapsulating the given @buffer.
|
||||||
|
*
|
||||||
|
* Since: 1.8
|
||||||
|
* Stability: unstable
|
||||||
|
*/
|
||||||
|
CoglBitmap *
|
||||||
|
cogl_bitmap_new_from_buffer (CoglBuffer *buffer,
|
||||||
|
CoglPixelFormat format,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int rowstride,
|
||||||
|
int offset);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_bitmap_get_size_from_file:
|
* cogl_bitmap_get_size_from_file:
|
||||||
* @filename: the file to check
|
* @filename: the file to check
|
||||||
|
@ -409,7 +409,7 @@ _cogl_sub_texture_set_region (CoglTexture *tex,
|
|||||||
{
|
{
|
||||||
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
|
||||||
|
|
||||||
return _cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
|
return cogl_texture_set_region_from_bitmap (sub_tex->full_texture,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x + sub_tex->sub_x,
|
dst_x + sub_tex->sub_x,
|
||||||
dst_y + sub_tex->sub_y,
|
dst_y + sub_tex->sub_y,
|
||||||
|
@ -318,7 +318,7 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
|
|||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
_cogl_texture_set_region_from_bitmap (slice_tex,
|
cogl_texture_set_region_from_bitmap (slice_tex,
|
||||||
0, /* src_x */
|
0, /* src_x */
|
||||||
0, /* src_y */
|
0, /* src_y */
|
||||||
/* dst_x */
|
/* dst_x */
|
||||||
@ -374,7 +374,7 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds,
|
|||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
_cogl_texture_set_region_from_bitmap (slice_tex,
|
cogl_texture_set_region_from_bitmap (slice_tex,
|
||||||
0, /* src_x */
|
0, /* src_x */
|
||||||
0, /* src_y */
|
0, /* src_y */
|
||||||
/* dst_x */
|
/* dst_x */
|
||||||
@ -426,7 +426,7 @@ _cogl_texture_2d_sliced_upload_to_gl (CoglTexture2DSliced *tex_2ds,
|
|||||||
slice_tex = g_array_index (tex_2ds->slice_textures,
|
slice_tex = g_array_index (tex_2ds->slice_textures,
|
||||||
CoglHandle, slice_num);
|
CoglHandle, slice_num);
|
||||||
|
|
||||||
_cogl_texture_set_region_from_bitmap (slice_tex,
|
cogl_texture_set_region_from_bitmap (slice_tex,
|
||||||
x_span->start, /* src x */
|
x_span->start, /* src x */
|
||||||
y_span->start, /* src y */
|
y_span->start, /* src y */
|
||||||
0, /* dst x */
|
0, /* dst x */
|
||||||
@ -559,7 +559,7 @@ _cogl_texture_2d_sliced_upload_subregion_to_gl (CoglTexture2DSliced *tex_2ds,
|
|||||||
slice_tex = g_array_index (tex_2ds->slice_textures,
|
slice_tex = g_array_index (tex_2ds->slice_textures,
|
||||||
CoglHandle, slice_num);
|
CoglHandle, slice_num);
|
||||||
|
|
||||||
_cogl_texture_set_region_from_bitmap (slice_tex,
|
cogl_texture_set_region_from_bitmap (slice_tex,
|
||||||
source_x,
|
source_x,
|
||||||
source_y,
|
source_y,
|
||||||
local_x, /* dst x */
|
local_x, /* dst x */
|
||||||
|
@ -280,16 +280,6 @@ _cogl_texture_draw_and_read (CoglHandle handle,
|
|||||||
gboolean
|
gboolean
|
||||||
_cogl_texture_is_foreign (CoglHandle handle);
|
_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);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_texture_associate_framebuffer (CoglHandle handle,
|
_cogl_texture_associate_framebuffer (CoglHandle handle,
|
||||||
CoglFramebuffer *framebuffer);
|
CoglFramebuffer *framebuffer);
|
||||||
|
@ -627,7 +627,7 @@ cogl_texture_new_from_buffer_EXP (CoglHandle buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap the buffer into a bitmap */
|
/* Wrap the buffer into a bitmap */
|
||||||
bmp = _cogl_bitmap_new_from_buffer (cogl_buffer,
|
bmp = cogl_bitmap_new_from_buffer (cogl_buffer,
|
||||||
format,
|
format,
|
||||||
width, height,
|
width, height,
|
||||||
rowstride,
|
rowstride,
|
||||||
@ -852,7 +852,7 @@ _cogl_texture_ensure_non_quad_rendering (CoglHandle handle)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
_cogl_texture_set_region_from_bitmap (CoglHandle handle,
|
cogl_texture_set_region_from_bitmap (CoglHandle handle,
|
||||||
int src_x,
|
int src_x,
|
||||||
int src_y,
|
int src_y,
|
||||||
int dst_x,
|
int dst_x,
|
||||||
@ -924,7 +924,7 @@ cogl_texture_set_region (CoglHandle handle,
|
|||||||
NULL, /* destroy_fn */
|
NULL, /* destroy_fn */
|
||||||
NULL); /* destroy_fn_data */
|
NULL); /* destroy_fn_data */
|
||||||
|
|
||||||
ret = _cogl_texture_set_region_from_bitmap (handle,
|
ret = cogl_texture_set_region_from_bitmap (handle,
|
||||||
src_x, src_y,
|
src_x, src_y,
|
||||||
dst_x, dst_y,
|
dst_x, dst_y,
|
||||||
dst_width, dst_height,
|
dst_width, dst_height,
|
||||||
|
@ -367,6 +367,41 @@ cogl_texture_set_region (CoglHandle handle,
|
|||||||
unsigned int rowstride,
|
unsigned int rowstride,
|
||||||
const guint8 *data);
|
const guint8 *data);
|
||||||
|
|
||||||
|
#if defined (COGL_ENABLE_EXPERIMENTAL_API)
|
||||||
|
|
||||||
|
#define cogl_texture_set_region_from_bitmap \
|
||||||
|
cogl_texture_set_region_from_bitmap_EXP
|
||||||
|
/**
|
||||||
|
* cogl_texture_set_region_from_bitmap:
|
||||||
|
* @handle: a #CoglHandle for a texture
|
||||||
|
* @src_x: upper left coordinate to use from the source bitmap.
|
||||||
|
* @src_y: upper left coordinate to use from the source bitmap
|
||||||
|
* @dst_x: upper left destination horizontal coordinate.
|
||||||
|
* @dst_y: upper left destination vertical coordinate.
|
||||||
|
* @dst_width: width of destination region to write.
|
||||||
|
* @dst_height: height of destination region to write.
|
||||||
|
* @bitmap: The source bitmap to read from
|
||||||
|
*
|
||||||
|
* Copies a specified source region from @bitmap to the position
|
||||||
|
* (@src_x, @src_y) of the given destination texture @handle.
|
||||||
|
*
|
||||||
|
* Return value: %TRUE if the subregion upload was successful, and
|
||||||
|
* %FALSE otherwise
|
||||||
|
*
|
||||||
|
* Since: 1.8
|
||||||
|
* Stability: unstable
|
||||||
|
*/
|
||||||
|
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 *bitmap);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_texture_new_from_sub_texture:
|
* cogl_texture_new_from_sub_texture:
|
||||||
* @full_texture: a #CoglHandle to an existing texture
|
* @full_texture: a #CoglHandle to an existing texture
|
||||||
|
Loading…
Reference in New Issue
Block a user