2012-11-21 22:12:54 +00:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
2011-05-05 22:34:38 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-11-21 22:12:54 +00:00
|
|
|
#include "test-utils.h"
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
check_texture (int width, int height, CoglTextureFlags flags)
|
|
|
|
{
|
2012-11-21 22:12:54 +00:00
|
|
|
CoglTexture *tex;
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 20:56:40 +00:00
|
|
|
uint8_t *data, *p;
|
2011-05-05 22:34:38 +00:00
|
|
|
int y, x;
|
2012-11-21 22:12:54 +00:00
|
|
|
int rowstride;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
p = data = g_malloc (width * height * 4);
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
*(p++) = x;
|
|
|
|
*(p++) = y;
|
|
|
|
*(p++) = 128;
|
|
|
|
*(p++) = (x ^ y);
|
|
|
|
}
|
|
|
|
|
|
|
|
tex = cogl_texture_new_from_data (width, height,
|
|
|
|
flags,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
width * 4,
|
|
|
|
data);
|
|
|
|
|
|
|
|
/* Replace the bottom right quarter of the data with negated data to
|
|
|
|
test set_region */
|
2012-11-21 22:12:54 +00:00
|
|
|
rowstride = width * 4;
|
|
|
|
p = data + (height / 2) * rowstride + rowstride / 2;
|
2011-05-05 22:34:38 +00:00
|
|
|
for (y = 0; y < height / 2; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < width / 2; x++)
|
|
|
|
{
|
|
|
|
p[0] = ~p[0];
|
|
|
|
p[1] = ~p[1];
|
|
|
|
p[2] = ~p[2];
|
|
|
|
p[3] = ~p[3];
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
p += width * 2;
|
|
|
|
}
|
|
|
|
cogl_texture_set_region (tex,
|
2012-11-21 22:12:54 +00:00
|
|
|
width / 2,
|
|
|
|
height / 2,
|
|
|
|
width / 2, /* dest x */
|
|
|
|
height / 2, /* dest y */
|
|
|
|
width / 2, /* region width */
|
|
|
|
height / 2, /* region height */
|
|
|
|
width, /* src width */
|
|
|
|
height, /* src height */
|
2011-05-05 22:34:38 +00:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888,
|
2012-11-21 22:12:54 +00:00
|
|
|
rowstride,
|
2011-05-05 22:34:38 +00:00
|
|
|
data);
|
|
|
|
|
|
|
|
/* Check passing a NULL pointer and a zero rowstride. The texture
|
|
|
|
should calculate the needed data size and return it */
|
|
|
|
g_assert_cmpint (cogl_texture_get_data (tex, COGL_PIXEL_FORMAT_ANY, 0, NULL),
|
|
|
|
==,
|
|
|
|
width * height * 4);
|
|
|
|
|
|
|
|
/* Try first receiving the data as RGB. This should cause a
|
|
|
|
* conversion */
|
|
|
|
memset (data, 0, width * height * 4);
|
|
|
|
|
|
|
|
cogl_texture_get_data (tex, COGL_PIXEL_FORMAT_RGB_888,
|
|
|
|
width * 3, data);
|
|
|
|
|
|
|
|
p = data;
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
if (x >= width / 2 && y >= height / 2)
|
|
|
|
{
|
|
|
|
g_assert_cmpint (p[0], ==, ~x & 0xff);
|
|
|
|
g_assert_cmpint (p[1], ==, ~y & 0xff);
|
|
|
|
g_assert_cmpint (p[2], ==, ~128 & 0xff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_assert_cmpint (p[0], ==, x & 0xff);
|
|
|
|
g_assert_cmpint (p[1], ==, y & 0xff);
|
|
|
|
g_assert_cmpint (p[2], ==, 128);
|
|
|
|
}
|
|
|
|
p += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now try receiving the data as RGBA. This should not cause a
|
|
|
|
* conversion and no unpremultiplication because we explicitly set
|
|
|
|
* the internal format when we created the texture */
|
|
|
|
memset (data, 0, width * height * 4);
|
|
|
|
|
|
|
|
cogl_texture_get_data (tex, COGL_PIXEL_FORMAT_RGBA_8888,
|
|
|
|
width * 4, data);
|
|
|
|
|
|
|
|
p = data;
|
|
|
|
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
if (x >= width / 2 && y >= height / 2)
|
|
|
|
{
|
|
|
|
g_assert_cmpint (p[0], ==, ~x & 0xff);
|
|
|
|
g_assert_cmpint (p[1], ==, ~y & 0xff);
|
|
|
|
g_assert_cmpint (p[2], ==, ~128 & 0xff);
|
|
|
|
g_assert_cmpint (p[3], ==, ~(x ^ y) & 0xff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_assert_cmpint (p[0], ==, x & 0xff);
|
|
|
|
g_assert_cmpint (p[1], ==, y & 0xff);
|
|
|
|
g_assert_cmpint (p[2], ==, 128);
|
|
|
|
g_assert_cmpint (p[3], ==, (x ^ y) & 0xff);
|
|
|
|
}
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
|
2012-11-21 22:12:54 +00:00
|
|
|
cogl_object_unref (tex);
|
2011-05-05 22:34:38 +00:00
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
|
2012-11-21 22:12:54 +00:00
|
|
|
void
|
|
|
|
test_texture_get_set_data (void)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
/* First try without atlasing */
|
|
|
|
check_texture (256, 256, COGL_TEXTURE_NO_ATLAS);
|
|
|
|
/* Try again with atlasing. This should end up testing the atlas
|
|
|
|
backend and the sub texture backend */
|
|
|
|
check_texture (256, 256, 0);
|
|
|
|
/* Try with a really big texture in the hope that it will end up
|
|
|
|
sliced. */
|
|
|
|
check_texture (4, 5128, COGL_TEXTURE_NO_ATLAS);
|
|
|
|
/* And in the other direction. */
|
|
|
|
check_texture (5128, 4, COGL_TEXTURE_NO_ATLAS);
|
|
|
|
}
|