static const CoglTextureVtable cogl_sub_texture_vtable;
-/* Maps from the texture coordinates of this texture to the texture
- coordinates of the full texture */
-
static void
-_cogl_sub_texture_map_coordinate_pair (CoglSubTexture *sub_tex,
- gfloat *tx, gfloat *ty)
+_cogl_sub_texture_map_range (gfloat *t1, gfloat *t2,
+ gint sub_offset,
+ gint sub_size,
+ gint full_size)
{
- *tx = *tx * (sub_tex->tx2 - sub_tex->tx1) + sub_tex->tx1;
- *ty = *ty * (sub_tex->ty2 - sub_tex->ty1) + sub_tex->ty1;
+ gfloat t1_frac, t1_int, t2_frac, t2_int;
+
+ t1_frac = modff (*t1, &t1_int);
+ t2_frac = modff (*t2, &t2_int);
+
+ if (t1_frac < 0.0f)
+ {
+ t1_frac += 1.0f;
+ t1_int -= 1.0f;
+ }
+ if (t2_frac < 0.0f)
+ {
+ t2_frac += 1.0f;
+ t2_int -= 1.0f;
+ }
+
+ /* If one of the coordinates is zero we need to make sure it is
+ still greater than the other coordinate if it was originally so
+ we'll flip it to the other side */
+ if (*t1 < *t2)
+ {
+ if (t2_frac == 0.0f)
+ {
+ t2_frac = 1.0f;
+ t2_int -= 1.0f;
+ }
+ }
+ else
+ {
+ if (t1_frac == 0.0f)
+ {
+ t1_frac = 1.0f;
+ t1_int -= 1.0f;
+ }
+ }
+
+ /* Convert the fractional part leaving the integer part intact */
+ t1_frac = (sub_offset + t1_frac * sub_size) / full_size;
+ *t1 = t1_frac + t1_int;
+
+ t2_frac = (sub_offset + t2_frac * sub_size) / full_size;
+ *t2 = t2_frac + t2_int;
}
static void
-_cogl_sub_texture_map_coordinate_set (CoglSubTexture *sub_tex,
- gfloat *tx1, gfloat *ty1,
- gfloat *tx2, gfloat *ty2)
+_cogl_sub_texture_map_quad (CoglSubTexture *sub_tex,
+ gfloat *coords)
{
- _cogl_sub_texture_map_coordinate_pair (sub_tex, tx1, ty1);
- _cogl_sub_texture_map_coordinate_pair (sub_tex, tx2, ty2);
+ guint full_width = cogl_texture_get_width (sub_tex->full_texture);
+ guint full_height = cogl_texture_get_height (sub_tex->full_texture);
+
+ _cogl_sub_texture_map_range (coords + 0, coords + 2,
+ sub_tex->sub_x, sub_tex->sub_width,
+ full_width);
+ _cogl_sub_texture_map_range (coords + 1, coords + 3,
+ sub_tex->sub_y, sub_tex->sub_height,
+ full_height);
}
/* Maps from the texture coordinates of the full texture to the
texture coordinates of the sub texture */
-static void
-_cogl_sub_texture_unmap_coordinate_pair (CoglSubTexture *sub_tex,
- gfloat *coords)
+static gfloat
+_cogl_sub_texture_unmap_coord (gfloat t,
+ gint sub_offset,
+ gint sub_size,
+ gint full_size)
{
- if (sub_tex->tx1 == sub_tex->tx2)
- coords[0] = sub_tex->tx1;
- else
- coords[0] = (coords[0] - sub_tex->tx1) / (sub_tex->tx2 - sub_tex->tx1);
+ gfloat frac_part, int_part;
+
+ /* Convert the fractional part leaving the integer part in tact */
+ frac_part = modff (t, &int_part);
- if (sub_tex->ty1 == sub_tex->ty2)
- coords[0] = sub_tex->ty1;
+ if (signbit (frac_part))
+ frac_part = ((1.0f + frac_part) * full_size -
+ sub_offset - sub_size) / sub_size;
else
- coords[1] = (coords[1] - sub_tex->ty1) / (sub_tex->ty2 - sub_tex->ty1);
-}
+ frac_part = (frac_part * full_size - sub_offset) / sub_size;
-static void
-_cogl_sub_texture_unmap_coordinate_set (CoglSubTexture *sub_tex,
- gfloat *coords)
-{
- _cogl_sub_texture_unmap_coordinate_pair (sub_tex, coords);
- _cogl_sub_texture_unmap_coordinate_pair (sub_tex, coords + 2);
+ return frac_part + int_part;
}
-static gboolean
-_cogl_sub_texture_same_int_part (float t1, float t2)
+static void
+_cogl_sub_texture_unmap_coords (CoglSubTexture *sub_tex,
+ gfloat *s,
+ gfloat *t)
{
- float int_part1, int_part2;
- float frac_part1, frac_part2;
-
- frac_part1 = modff (t1, &int_part1);
- frac_part2 = modff (t2, &int_part2);
+ guint full_width = cogl_texture_get_width (sub_tex->full_texture);
+ guint full_height = cogl_texture_get_height (sub_tex->full_texture);
- return (int_part1 == int_part2 ||
- ((frac_part1 == 0.0f || frac_part2 == 0.0f) &&
- ABS (int_part1 - int_part2) == 1.0f));
+ *s = _cogl_sub_texture_unmap_coord (*s, sub_tex->sub_x, sub_tex->sub_width,
+ full_width);
+ *t = _cogl_sub_texture_unmap_coord (*t, sub_tex->sub_y, sub_tex->sub_height,
+ full_height);
}
typedef struct _CoglSubTextureForeachData
memcpy (virtual_coords, full_virtual_coords, sizeof (virtual_coords));
/* Convert the virtual coords from the full-texture space to the sub
texture space */
- _cogl_sub_texture_unmap_coordinate_set (data->sub_tex, virtual_coords);
+ _cogl_sub_texture_unmap_coords (data->sub_tex,
+ &virtual_coords[0],
+ &virtual_coords[1]);
+ _cogl_sub_texture_unmap_coords (data->sub_tex,
+ &virtual_coords[2],
+ &virtual_coords[3]);
data->callback (handle, gl_handle, gl_target,
slice_coords, virtual_coords,
memcpy (mapped_coords, coords, sizeof (mapped_coords));
- _cogl_sub_texture_map_coordinate_set (data->sub_tex,
- &mapped_coords[0],
- &mapped_coords[1],
- &mapped_coords[2],
- &mapped_coords[3]);
+ _cogl_sub_texture_map_quad (data->sub_tex, mapped_coords);
_cogl_texture_foreach_sub_texture_in_region (data->sub_tex->full_texture,
mapped_coords[0],
data.callback = callback;
data.user_data = user_data;
- /* If there is no repeating or the sub texture coordinates are a
- multiple of the whole texture then we can just directly map the
- texture coordinates */
- if (sub_tex->tex_coords_are_a_multiple ||
- (_cogl_sub_texture_same_int_part (virtual_tx_1, virtual_tx_2) &&
- _cogl_sub_texture_same_int_part (virtual_ty_1, virtual_ty_2)))
- {
- _cogl_sub_texture_map_coordinate_set (sub_tex,
- &virtual_tx_1,
- &virtual_ty_1,
- &virtual_tx_2,
- &virtual_ty_2);
-
- _cogl_texture_foreach_sub_texture_in_region
- (sub_tex->full_texture,
- virtual_tx_1, virtual_ty_1,
- virtual_tx_2, virtual_ty_2,
- _cogl_sub_texture_foreach_cb, &data);
- }
- else
- _cogl_texture_iterate_manual_repeats (_cogl_sub_texture_manual_repeat_cb,
- virtual_tx_1, virtual_ty_1,
- virtual_tx_2, virtual_ty_2,
- &data);
+ _cogl_texture_iterate_manual_repeats (_cogl_sub_texture_manual_repeat_cb,
+ virtual_tx_1, virtual_ty_1,
+ virtual_tx_2, virtual_ty_2,
+ &data);
}
static void
CoglHandle
_cogl_sub_texture_new (CoglHandle full_texture,
- gfloat tx1, gfloat ty1,
- gfloat tx2, gfloat ty2)
+ gint sub_x, gint sub_y,
+ gint sub_width, gint sub_height)
{
CoglSubTexture *sub_tex;
CoglTexture *tex;
- gfloat integer_part;
+ guint full_width, full_height;
+
+ full_width = cogl_texture_get_width (full_texture);
+ full_height = cogl_texture_get_width (full_texture);
+
+ /* The region must specify a non-zero subset of the full texture */
+ g_return_val_if_fail (sub_x >= 0 && sub_y >= 0, COGL_INVALID_HANDLE);
+ g_return_val_if_fail (sub_width > 0 && sub_height > 0, COGL_INVALID_HANDLE);
+ g_return_val_if_fail (sub_x + sub_width <= full_width, COGL_INVALID_HANDLE);
+ g_return_val_if_fail (sub_y + sub_height <= full_height, COGL_INVALID_HANDLE);
sub_tex = g_new (CoglSubTexture, 1);
sub_tex->full_texture = cogl_handle_ref (full_texture);
- sub_tex->tx1 = tx1;
- sub_tex->ty1 = ty1;
- sub_tex->tx2 = tx2;
- sub_tex->ty2 = ty2;
-
- /* Track whether the texture coords are a multiple of one because in
- that case we can use hardware repeating */
- sub_tex->tex_coords_are_a_multiple
- = (modff (tx1, &integer_part) == 0.0f &&
- modff (ty1, &integer_part) == 0.0f &&
- modff (tx2, &integer_part) == 0.0f &&
- modff (ty2, &integer_part) == 0.0f);
+ sub_tex->sub_x = sub_x;
+ sub_tex->sub_y = sub_y;
+ sub_tex->sub_width = sub_width;
+ sub_tex->sub_height = sub_height;
return _cogl_sub_texture_handle_new (sub_tex);
}
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
- /* We can hardware repeat if the full texture can hardware repeat
- and the coordinates for the subregion are all a multiple of the
- full size of the texture (ie, they have no fractional part) */
-
- return (sub_tex->tex_coords_are_a_multiple &&
+ /* We can hardware repeat if the subtexture actually represents all of the
+ of the full texture */
+ return (sub_tex->sub_width ==
+ cogl_texture_get_width (sub_tex->full_texture) &&
+ sub_tex->sub_height ==
+ cogl_texture_get_height (sub_tex->full_texture) &&
_cogl_texture_can_hardware_repeat (sub_tex->full_texture));
}
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
- _cogl_sub_texture_map_coordinate_pair (sub_tex, s, t);
- _cogl_texture_transform_coords_to_gl (sub_tex->full_texture, s, t);
+ /* This won't work if the sub texture is not the size of the full
+ texture and the coordinates are outside the range [0,1] */
+ *s = ((*s * sub_tex->sub_width + sub_tex->sub_x) /
+ cogl_texture_get_width (sub_tex->full_texture));
+ *t = ((*t * sub_tex->sub_height + sub_tex->sub_y) /
+ cogl_texture_get_height (sub_tex->full_texture));
+
+ return _cogl_texture_transform_coords_to_gl (sub_tex->full_texture, s, t);
+}
+
+static gboolean
+_cogl_sub_texture_transform_quad_coords_to_gl (CoglTexture *tex,
+ float *coords)
+{
+ CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
+ int i;
+
+ /* We can't support repeating with this method. In this case
+ cogl-primitives will resort to manual repeating */
+ for (i = 0; i < 4; i++)
+ if (coords[i] < 0.0f || coords[i] > 1.0f)
+ return FALSE;
+
+ _cogl_sub_texture_map_quad (sub_tex, coords);
+
+ _cogl_texture_transform_quad_coords_to_gl (sub_tex->full_texture, coords);
+
+ return TRUE;
}
static gboolean
}
static void
-_cogl_sub_texture_get_next_chunk (int pos, int end,
- int tex_size,
- int *chunk_start, int *chunk_end)
+_cogl_sub_texture_ensure_non_quad_rendering (CoglTexture *tex)
{
- /* pos and end may be negative or greater than the size of the
- texture. We want to calculate the next largest range we can copy
- in one chunk */
-
- if (pos < 0)
- /* The behaviour of % for negative numbers is implementation
- dependant in C89 so we have to do this */
- *chunk_start = (tex_size - pos) % tex_size;
- else
- *chunk_start = pos % tex_size;
-
- /* If the region is larger than the remaining size of the texture
- then we need to crop it */
- if (end - pos > tex_size - *chunk_start)
- end = pos + tex_size - *chunk_start;
-
- if (end < 0)
- *chunk_end = (tex_size - end) % tex_size;
- else
- *chunk_end = end % tex_size;
-
- if (*chunk_end == 0)
- *chunk_end = tex_size;
-}
-
-static void
-_cogl_sub_texture_get_x_pixel_pos (CoglSubTexture *sub_tex,
- gint *px1, gint *px2)
-{
- gint full_width = cogl_texture_get_width (sub_tex->full_texture);
-
- *px1 = full_width * sub_tex->tx1;
- *px2 = full_width * sub_tex->tx2;
-
- if (*px1 > *px2)
- {
- gint temp = *px1;
- *px1 = *px2;
- *px2 = temp;
- }
-}
-
-static void
-_cogl_sub_texture_get_y_pixel_pos (CoglSubTexture *sub_tex,
- gint *py1, gint *py2)
-{
- gint full_height = cogl_texture_get_height (sub_tex->full_texture);
-
- *py1 = full_height * sub_tex->ty1;
- *py2 = full_height * sub_tex->ty2;
-
- if (*py1 > *py2)
- {
- gint temp = *py1;
- *py1 = *py2;
- *py2 = temp;
- }
}
static gboolean
unsigned int rowstride,
const guint8 *data)
{
- CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
- gint full_tex_width, full_tex_height;
- gint bpp;
- gint px1, py1, px2, py2;
- gint it_x, it_y;
- gint src_x1, src_y1, src_x2, src_y2;
- CoglBitmap source_bmp;
- CoglBitmap temp_bmp;
- gboolean source_bmp_owner = FALSE;
- CoglPixelFormat closest_format;
- GLenum closest_gl_format;
- GLenum closest_gl_type;
- gboolean success;
- CoglPixelFormat tex_format;
-
- /* 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;
-
- /* FIXME: If the sub texture coordinates are swapped around then we
- should flip the bitmap */
-
- _cogl_sub_texture_get_x_pixel_pos (sub_tex, &px1, &px2);
- _cogl_sub_texture_get_y_pixel_pos (sub_tex, &py1, &py2);
-
- full_tex_width = cogl_texture_get_width (sub_tex->full_texture);
- full_tex_height = cogl_texture_get_height (sub_tex->full_texture);
-
- /* Init source bitmap */
- source_bmp.width = width;
- source_bmp.height = height;
- source_bmp.format = format;
- source_bmp.data = (guchar*) data;
-
- /* Rowstride from texture width if none specified */
- bpp = _cogl_get_format_bpp (format);
- source_bmp.rowstride = (rowstride == 0) ? width * bpp : rowstride;
-
- /* Find closest format to internal that's supported by GL */
- tex_format = cogl_texture_get_format (sub_tex->full_texture);
- closest_format = _cogl_pixel_format_to_gl (tex_format,
- NULL, /* don't need */
- &closest_gl_format,
- &closest_gl_type);
-
- /* If no direct match, convert */
- if (closest_format != format)
- {
- /* Convert to required format */
- success = _cogl_bitmap_convert_and_premult (&source_bmp,
- &temp_bmp,
- closest_format);
-
- /* Swap bitmaps if succeeded */
- if (!success) return FALSE;
- source_bmp = temp_bmp;
- source_bmp_owner = TRUE;
- }
-
- for (it_y = py1; it_y < py2; it_y += src_y2 - src_y1)
- {
- _cogl_sub_texture_get_next_chunk (it_y, py2, full_tex_width,
- &src_y1, &src_y2);
-
- for (it_x = px1; it_x < px2; it_x += src_x2 - src_x1)
- {
- gint virt_x_1, virt_y_1, virt_width, virt_height;
- gint copy_dst_x, copy_dst_y, copy_dst_width, copy_dst_height;
-
- _cogl_sub_texture_get_next_chunk (it_x, px2, full_tex_height,
- &src_x1, &src_x2);
-
- /* Offset of the chunk from the left edge in the virtual sub
- texture coordinates */
- virt_x_1 = it_x - px1;
- /* Pixel width covered by this chunk */
- virt_width = src_x2 - src_x1;
- /* Offset of the chunk from the top edge in the virtual sub
- texture coordinates */
- virt_y_1 = it_y - py1;
- /* Pixel height covered by this chunk */
- virt_height = src_y2 - src_y1;
-
- /* Check if this chunk intersects with the update region */
- if (dst_x + dst_width <= virt_x_1 ||
- dst_x >= virt_x_1 + virt_width ||
- dst_y + dst_height <= it_y - py1 ||
- dst_y >= virt_y_1 + virt_height)
- continue;
-
- /* Calculate the intersection in virtual coordinates */
- copy_dst_width = dst_width;
- if (dst_x < virt_x_1)
- {
- copy_dst_width -= virt_x_1 - dst_x;
- copy_dst_x = virt_x_1;
- }
- else
- copy_dst_x = dst_x;
- if (copy_dst_width + copy_dst_x > virt_x_1 + virt_width)
- copy_dst_width = virt_x_1 + virt_width - copy_dst_x;
-
- copy_dst_height = dst_height;
- if (dst_y < virt_y_1)
- {
- copy_dst_height -= virt_y_1 - dst_y;
- copy_dst_y = virt_y_1;
- }
- else
- copy_dst_y = dst_y;
- if (copy_dst_height + copy_dst_y > virt_y_1 + virt_height)
- copy_dst_height = virt_y_1 + virt_height - copy_dst_y;
-
- /* Update the region in the full texture */
- cogl_texture_set_region (sub_tex->full_texture,
- src_x + copy_dst_x - dst_x,
- src_y + copy_dst_y - dst_y,
- src_x1 + copy_dst_x - virt_x_1,
- src_y1 + copy_dst_y - virt_y_1,
- copy_dst_width,
- copy_dst_height,
- width,
- height,
- format,
- rowstride,
- data);
- }
- }
-
- /* Free data if owner */
- if (source_bmp_owner)
- g_free (source_bmp.data);
-
- return TRUE;
+ 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);
}
static void
guint8 *full_data;
int byte_size, full_size;
gint bpp;
- gint px1, py1, px2, py2;
gint full_tex_width, full_tex_height;
/* FIXME: This gets the full data from the full texture and then
if (format == COGL_PIXEL_FORMAT_ANY)
format = cogl_texture_get_format (sub_tex->full_texture);
- _cogl_sub_texture_get_x_pixel_pos (sub_tex, &px1, &px2);
- _cogl_sub_texture_get_y_pixel_pos (sub_tex, &py1, &py2);
-
full_tex_width = cogl_texture_get_width (sub_tex->full_texture);
full_tex_height = cogl_texture_get_height (sub_tex->full_texture);
/* Rowstride from texture width if none specified */
bpp = _cogl_get_format_bpp (format);
if (rowstride == 0)
- rowstride = px2 - px1;
+ rowstride = sub_tex->sub_width * bpp;
/* Return byte size if only that requested */
- byte_size = (py2 - py1) * rowstride;
+ byte_size = sub_tex->sub_height * rowstride;
if (data == NULL)
return byte_size;
full_rowstride, full_data);
if (full_size)
- {
- int dst_x, dst_y;
- int src_x1, src_y1;
- int src_x2, src_y2;
-
- for (dst_y = py1; dst_y < py2; dst_y += src_y2 - src_y1)
- {
- _cogl_sub_texture_get_next_chunk (dst_y, py2, full_tex_width,
- &src_y1, &src_y2);
-
- for (dst_x = px1; dst_x < px2; dst_x += src_x2 - src_x1)
- {
- _cogl_sub_texture_get_next_chunk (dst_x, px2, full_tex_height,
- &src_x1, &src_x2);
-
- _cogl_sub_texture_copy_region (data, full_data,
- dst_x - px1, dst_y - py1,
- src_x1, src_y1,
- src_x2 - src_x1,
- src_y2 - src_y1,
- rowstride,
- full_rowstride,
- bpp);
- }
- }
- }
+ _cogl_sub_texture_copy_region (data, full_data,
+ 0, 0,
+ sub_tex->sub_x,
+ sub_tex->sub_y,
+ sub_tex->sub_width,
+ sub_tex->sub_height,
+ rowstride,
+ full_rowstride,
+ bpp);
else
byte_size = 0;
_cogl_sub_texture_get_width (CoglTexture *tex)
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
- gint px1, px2;
-
- _cogl_sub_texture_get_x_pixel_pos (sub_tex, &px1, &px2);
- return px2 - px1;
+ return sub_tex->sub_width;
}
static gint
_cogl_sub_texture_get_height (CoglTexture *tex)
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (tex);
- gint py1, py2;
-
- _cogl_sub_texture_get_y_pixel_pos (sub_tex, &py1, &py2);
- return py2 - py1;
+ return sub_tex->sub_height;
}
static const CoglTextureVtable
_cogl_sub_texture_is_sliced,
_cogl_sub_texture_can_hardware_repeat,
_cogl_sub_texture_transform_coords_to_gl,
+ _cogl_sub_texture_transform_quad_coords_to_gl,
_cogl_sub_texture_get_gl_texture,
_cogl_sub_texture_set_filters,
_cogl_sub_texture_ensure_mipmaps,
+ _cogl_sub_texture_ensure_non_quad_rendering,
_cogl_sub_texture_set_wrap_mode_parameter,
_cogl_sub_texture_get_format,
_cogl_sub_texture_get_gl_format,
/* Create a sub texture of the bottom right quarter of the texture */
sub_texture = cogl_texture_new_from_sub_texture (state->tex,
- 1.0f / SOURCE_DIVISIONS_X,
- 1.0f / SOURCE_DIVISIONS_Y,
- 1.0f, 1.0f);
+ DIVISION_WIDTH,
+ DIVISION_HEIGHT,
+ DIVISION_WIDTH,
+ DIVISION_HEIGHT);
/* Paint it */
cogl_set_source_texture (sub_texture);
cogl_handle_unref (sub_texture);
- /* Repeat a sub texture of the top half of the full texture */
+ /* Repeat a sub texture of the top half of the full texture. This is
+ documented to be undefined so it doesn't technically have to work
+ but it will with the current implementation */
sub_texture = cogl_texture_new_from_sub_texture (state->tex,
- 0.0f, 0.0f, 1.0f, 0.5f);
+ 0, 0,
+ SOURCE_SIZE,
+ DIVISION_HEIGHT);
cogl_set_source_texture (sub_texture);
cogl_rectangle_with_texture_coords (0.0f, SOURCE_SIZE,
SOURCE_SIZE * 2.0f, SOURCE_SIZE * 1.5f,
0.0f, 0.0f,
2.0f, 1.0f);
cogl_handle_unref (sub_texture);
-
- /* Create a texture that repeats the source texture twice */
- sub_texture = cogl_texture_new_from_sub_texture (state->tex,
- 0.0f, 0.0f, 2.0f, 2.0f);
- cogl_set_source_texture (sub_texture);
- cogl_rectangle (0.0f, SOURCE_SIZE * 2, SOURCE_SIZE * 2, SOURCE_SIZE * 4);
- cogl_handle_unref (sub_texture);
}
static gboolean
DIVISION_WIDTH, DIVISION_HEIGHT,
corner_colors + division_num));
- /* Sub texture that repeats the texture (the opposite of a sub-texture?) */
- for (y = 0; y < SOURCE_DIVISIONS_Y * 2; y++)
- for (x = 0; x < SOURCE_DIVISIONS_X * 2; x++)
- {
- guint color_num = (y % SOURCE_DIVISIONS_Y * SOURCE_DIVISIONS_X +
- x % SOURCE_DIVISIONS_X);
- g_assert (validate_part (state,
- x * DIVISION_WIDTH,
- y * DIVISION_WIDTH + SOURCE_SIZE * 2,
- DIVISION_WIDTH, DIVISION_HEIGHT,
- corner_colors + color_num));
- }
-
/* Try reading back the texture data */
sub_texture = cogl_texture_new_from_sub_texture (state->tex,
- 0.25f, 0.25f, 0.75f, 0.75f);
+ SOURCE_SIZE / 4,
+ SOURCE_SIZE / 4,
+ SOURCE_SIZE / 2,
+ SOURCE_SIZE / 2);
tex_width = cogl_texture_get_width (sub_texture);
tex_height = cogl_texture_get_height (sub_texture);
p = texture_data = g_malloc (tex_width * tex_height * 4);
g_free (texture_data);
cogl_handle_unref (sub_texture);
- /* Try reading back the repeated texture data */
- sub_texture = cogl_texture_new_from_sub_texture (state->tex,
- 0.0f, 0.0f, 2.0f, 2.0f);
- tex_width = cogl_texture_get_width (sub_texture);
- tex_height = cogl_texture_get_height (sub_texture);
- p = texture_data = g_malloc (tex_width * tex_height * 4);
- cogl_texture_get_data (sub_texture, COGL_PIXEL_FORMAT_RGBA_8888,
- tex_width * 4,
- texture_data);
- for (y = 0; y < tex_height; y++)
- for (x = 0; x < tex_width; x++)
- {
- int div_x = x / DIVISION_WIDTH % SOURCE_DIVISIONS_X;
- int div_y = y / DIVISION_HEIGHT % SOURCE_DIVISIONS_Y;
- const ClutterColor *color = (corner_colors + div_x +
- div_y * SOURCE_DIVISIONS_X);
- g_assert (p[0] == color->red);
- g_assert (p[1] == color->green);
- g_assert (p[2] == color->blue);
- p += 4;
- }
- g_free (texture_data);
- cogl_handle_unref (sub_texture);
-
/* Create a 256x256 test texture */
test_tex = create_test_texture ();
- /* Create a sub texture the views the bottom right and top left of
- the texture by wrapping around */
+ /* Create a sub texture the views the center half of the texture */
sub_texture = cogl_texture_new_from_sub_texture (test_tex,
- 0.5f, 0.5f, 1.5f, 1.5f);
- /* Update the center of the sub texture */
+ 64, 64, 128, 128);
+ /* Update the center half of the sub texture */
texture_data = create_update_data ();
- cogl_texture_set_region (sub_texture, 0, 0, 64, 64, 128, 128, 256, 256,
+ cogl_texture_set_region (sub_texture, 0, 0, 32, 32, 64, 64, 256, 256,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, 256 * 4,
texture_data);
g_free (texture_data);
for (y = 0; y < 256; y++)
for (x = 0; x < 256; x++)
{
- /* If we're in the center of the subregion.. */
- if ((x < 64 || x >= 192) && (y < 64 || y >= 192))
+ /* If we're in the center quarter */
+ if (x >= 96 && x < 160 && y >= 96 && y < 160)
{
g_assert ((*p++) == 0);
g_assert ((*p++) == 0);
- g_assert ((*p++) == ((x + 64) & 0xff));
- g_assert ((*p++) == ((y + 64) & 0xff));
+ g_assert ((*p++) == x - 96);
+ g_assert ((*p++) == y - 96);
}
else
{