pixel-array: Only allow allocation of arrays with a 2D size
This removes cogl_pixel_array_new which just took a size in bytes. Without the image size and pixel format then the driver often doesn't have enough information to allocate optimal GPU memory that can be textured from directly. This is because GPUs often have ways to spatially alter the layout of a texture to improve cache access patterns which may require special alignment and padding dependant in the images width, height and bpp. Although currently we are limited by OpenGL because it doesn't let us pass on the width and height when allocating a PBO, the hope is that we can define a better extension at some point.
This commit is contained in:
parent
cfef390d87
commit
8a5aed36fe
@ -87,8 +87,8 @@ cogl_malloc_pixel_array_vtable;
|
|||||||
|
|
||||||
COGL_BUFFER_DEFINE (PixelArray, pixel_array)
|
COGL_BUFFER_DEFINE (PixelArray, pixel_array)
|
||||||
|
|
||||||
CoglPixelArray *
|
static CoglPixelArray *
|
||||||
cogl_pixel_array_new (unsigned int size)
|
_cogl_pixel_array_new (unsigned int size)
|
||||||
{
|
{
|
||||||
CoglPixelArray *pixel_array = g_slice_new0 (CoglPixelArray);
|
CoglPixelArray *pixel_array = g_slice_new0 (CoglPixelArray);
|
||||||
CoglBuffer *buffer = COGL_BUFFER (pixel_array);
|
CoglBuffer *buffer = COGL_BUFFER (pixel_array);
|
||||||
@ -148,7 +148,7 @@ cogl_pixel_array_new_with_size (unsigned int width,
|
|||||||
if (rowstride)
|
if (rowstride)
|
||||||
*rowstride = stride;
|
*rowstride = stride;
|
||||||
|
|
||||||
buffer = cogl_pixel_array_new (height * stride);
|
buffer = _cogl_pixel_array_new (height * stride);
|
||||||
if (G_UNLIKELY (buffer == COGL_INVALID_HANDLE))
|
if (G_UNLIKELY (buffer == COGL_INVALID_HANDLE))
|
||||||
return COGL_INVALID_HANDLE;
|
return COGL_INVALID_HANDLE;
|
||||||
|
|
||||||
|
@ -52,22 +52,6 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
typedef struct _CoglPixelArray CoglPixelArray;
|
typedef struct _CoglPixelArray CoglPixelArray;
|
||||||
|
|
||||||
/**
|
|
||||||
* cogl_pixel_array_new:
|
|
||||||
* @size: size of the array in bytes
|
|
||||||
*
|
|
||||||
* Creates a new array to store pixel data. You can create a new texture from
|
|
||||||
* this array using cogl_texture_new_from_buffer().
|
|
||||||
*
|
|
||||||
* Return value: a #CoglPixelArray representing the newly created array or
|
|
||||||
* %NULL on failure
|
|
||||||
*
|
|
||||||
* Since: 1.2
|
|
||||||
* Stability: Unstable
|
|
||||||
*/
|
|
||||||
CoglPixelArray *
|
|
||||||
cogl_pixel_array_new (unsigned int size);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_pixel_array_new_with_size:
|
* cogl_pixel_array_new_with_size:
|
||||||
* @width: width of the pixel array in pixels
|
* @width: width of the pixel array in pixels
|
||||||
|
@ -62,8 +62,13 @@ create_map_tile (TestTile *tile)
|
|||||||
CoglHandle buffer;
|
CoglHandle buffer;
|
||||||
guchar *map;
|
guchar *map;
|
||||||
guint i;
|
guint i;
|
||||||
|
unsigned int stride = 0;
|
||||||
|
guint8 *line;
|
||||||
|
|
||||||
buffer = cogl_pixel_array_new (TILE_SIZE * TILE_SIZE * 4);
|
buffer = cogl_pixel_array_new_with_size (TILE_SIZE,
|
||||||
|
TILE_SIZE,
|
||||||
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
||||||
|
&stride);
|
||||||
|
|
||||||
g_assert (cogl_is_pixel_array (buffer));
|
g_assert (cogl_is_pixel_array (buffer));
|
||||||
g_assert (cogl_is_buffer (buffer));
|
g_assert (cogl_is_buffer (buffer));
|
||||||
@ -76,8 +81,12 @@ create_map_tile (TestTile *tile)
|
|||||||
map = cogl_buffer_map (buffer, COGL_BUFFER_ACCESS_WRITE);
|
map = cogl_buffer_map (buffer, COGL_BUFFER_ACCESS_WRITE);
|
||||||
g_assert (map);
|
g_assert (map);
|
||||||
|
|
||||||
for (i = 0; i < TILE_SIZE * TILE_SIZE * 4; i += 4)
|
line = g_alloca (TILE_SIZE * 4);
|
||||||
memcpy (map + i, &tile->color, 4);
|
for (i = 0; i < TILE_SIZE; i += 4)
|
||||||
|
memcpy (line + i, &tile->color, 4);
|
||||||
|
|
||||||
|
for (i = 0; i < TILE_SIZE; i++)
|
||||||
|
memcpy (map + stride, line, 4);
|
||||||
|
|
||||||
cogl_buffer_unmap (buffer);
|
cogl_buffer_unmap (buffer);
|
||||||
|
|
||||||
@ -95,7 +104,7 @@ create_set_region_tile (TestTile *tile)
|
|||||||
guchar *data;
|
guchar *data;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
buffer = cogl_pixel_array_new_for_size (TILE_SIZE,
|
buffer = cogl_pixel_array_with_size (TILE_SIZE,
|
||||||
TILE_SIZE,
|
TILE_SIZE,
|
||||||
COGL_PIXEL_FORMAT_RGBA_8888,
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
||||||
&rowstride);
|
&rowstride);
|
||||||
@ -143,7 +152,7 @@ create_set_data_tile (TestTile *tile)
|
|||||||
guchar *data;
|
guchar *data;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
buffer = cogl_pixel_array_new_for_size (TILE_SIZE,
|
buffer = cogl_pixel_array_new_with_size (TILE_SIZE,
|
||||||
TILE_SIZE,
|
TILE_SIZE,
|
||||||
COGL_PIXEL_FORMAT_RGBA_8888,
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
||||||
&rowstride);
|
&rowstride);
|
||||||
@ -152,17 +161,12 @@ create_set_data_tile (TestTile *tile)
|
|||||||
g_assert (cogl_is_buffer (buffer));
|
g_assert (cogl_is_buffer (buffer));
|
||||||
g_assert_cmpint (cogl_buffer_get_size (buffer), ==, rowstride * TILE_SIZE);
|
g_assert_cmpint (cogl_buffer_get_size (buffer), ==, rowstride * TILE_SIZE);
|
||||||
|
|
||||||
/* while at it, set/get the hint */
|
|
||||||
cogl_buffer_set_usage_hint (buffer, COGL_BUFFER_USAGE_HINT_TEXTURE);
|
|
||||||
g_assert_cmpint (cogl_buffer_get_usage_hint (buffer),
|
|
||||||
==,
|
|
||||||
COGL_BUFFER_USAGE_HINT_TEXTURE);
|
|
||||||
|
|
||||||
/* create a buffer with the data we want to copy to the buffer */
|
/* create a buffer with the data we want to copy to the buffer */
|
||||||
data = g_malloc (TILE_SIZE * TILE_SIZE * 4);
|
data = g_malloc (TILE_SIZE * TILE_SIZE * 4);
|
||||||
for (i = 0; i < TILE_SIZE * TILE_SIZE * 4; i += 4)
|
for (i = 0; i < TILE_SIZE * TILE_SIZE * 4; i += 4)
|
||||||
memcpy (data + i, &tile->color, 4);
|
memcpy (data + i, &tile->color, 4);
|
||||||
|
|
||||||
|
/* FIXME: this doesn't consider the rowstride */
|
||||||
res = cogl_buffer_set_data (buffer, 0, data, TILE_SIZE * TILE_SIZE * 4);
|
res = cogl_buffer_set_data (buffer, 0, data, TILE_SIZE * TILE_SIZE * 4);
|
||||||
g_assert (res);
|
g_assert (res);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user