2012-02-29 19:40:34 -05:00
|
|
|
#include <cogl/cogl2-experimental.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This tests writing data to an RGBA texture in all of the available
|
|
|
|
* pixel formats
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_color (CoglTexture *texture,
|
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 16:56:40 -04:00
|
|
|
uint32_t expected_pixel)
|
2012-02-29 19:40:34 -05:00
|
|
|
{
|
2013-01-21 13:43:24 -05:00
|
|
|
uint8_t received_pixel[4];
|
2012-02-29 19:40:34 -05:00
|
|
|
|
|
|
|
cogl_texture_get_data (texture,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
4, /* rowstride */
|
2013-01-21 13:43:24 -05:00
|
|
|
received_pixel);
|
2012-02-29 19:40:34 -05:00
|
|
|
|
2013-01-21 13:43:24 -05:00
|
|
|
test_utils_compare_pixel_and_alpha (received_pixel, expected_pixel);
|
2012-02-29 19:40:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_write_byte (CoglContext *context,
|
|
|
|
CoglPixelFormat format,
|
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 16:56:40 -04:00
|
|
|
uint8_t byte,
|
|
|
|
uint32_t expected_pixel)
|
2012-02-29 19:40:34 -05:00
|
|
|
{
|
|
|
|
CoglTexture *texture = test_utils_create_color_texture (context, 0);
|
|
|
|
|
|
|
|
cogl_texture_set_region (texture,
|
|
|
|
0, 0, /* src_x / src_y */
|
|
|
|
0, 0, /* dst_x / dst_y */
|
|
|
|
1, 1, /* dst_w / dst_h */
|
|
|
|
1, 1, /* width / height */
|
|
|
|
format,
|
|
|
|
1, /* rowstride */
|
|
|
|
&byte);
|
|
|
|
|
|
|
|
test_color (texture, expected_pixel);
|
|
|
|
|
|
|
|
cogl_object_unref (texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_write_short (CoglContext *context,
|
|
|
|
CoglPixelFormat format,
|
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 16:56:40 -04:00
|
|
|
uint16_t value,
|
|
|
|
uint32_t expected_pixel)
|
2012-02-29 19:40:34 -05:00
|
|
|
{
|
|
|
|
CoglTexture *texture = test_utils_create_color_texture (context, 0);
|
|
|
|
|
|
|
|
cogl_texture_set_region (texture,
|
|
|
|
0, 0, /* src_x / src_y */
|
|
|
|
0, 0, /* dst_x / dst_y */
|
|
|
|
1, 1, /* dst_w / dst_h */
|
|
|
|
1, 1, /* width / height */
|
|
|
|
format,
|
|
|
|
2, /* rowstride */
|
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 16:56:40 -04:00
|
|
|
(uint8_t *) &value);
|
2012-02-29 19:40:34 -05:00
|
|
|
|
|
|
|
test_color (texture, expected_pixel);
|
|
|
|
|
|
|
|
cogl_object_unref (texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_write_bytes (CoglContext *context,
|
|
|
|
CoglPixelFormat format,
|
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 16:56:40 -04:00
|
|
|
uint32_t value,
|
|
|
|
uint32_t expected_pixel)
|
2012-02-29 19:40:34 -05:00
|
|
|
{
|
|
|
|
CoglTexture *texture = test_utils_create_color_texture (context, 0);
|
|
|
|
|
|
|
|
value = GUINT32_TO_BE (value);
|
|
|
|
|
|
|
|
cogl_texture_set_region (texture,
|
|
|
|
0, 0, /* src_x / src_y */
|
|
|
|
0, 0, /* dst_x / dst_y */
|
|
|
|
1, 1, /* dst_w / dst_h */
|
|
|
|
1, 1, /* width / height */
|
|
|
|
format,
|
|
|
|
4, /* rowstride */
|
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 16:56:40 -04:00
|
|
|
(uint8_t *) &value);
|
2012-02-29 19:40:34 -05:00
|
|
|
|
|
|
|
test_color (texture, expected_pixel);
|
|
|
|
|
|
|
|
cogl_object_unref (texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_write_int (CoglContext *context,
|
|
|
|
CoglPixelFormat format,
|
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 16:56:40 -04:00
|
|
|
uint32_t expected_pixel,
|
2012-02-29 19:40:34 -05:00
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int bits;
|
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 16:56:40 -04:00
|
|
|
uint32_t tex_data = 0;
|
2012-02-29 19:40:34 -05:00
|
|
|
int bits_sum = 0;
|
|
|
|
CoglTexture *texture = test_utils_create_color_texture (context, 0);
|
|
|
|
|
|
|
|
va_start (ap, expected_pixel);
|
|
|
|
|
|
|
|
/* Convert the va args into a single 32-bit value */
|
|
|
|
while ((bits = va_arg (ap, int)) != -1)
|
|
|
|
{
|
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 16:56:40 -04:00
|
|
|
uint32_t value = (va_arg (ap, int) * ((1 << bits) - 1) + 127) / 255;
|
2012-02-29 19:40:34 -05:00
|
|
|
|
|
|
|
bits_sum += bits;
|
|
|
|
|
|
|
|
tex_data |= value << (32 - bits_sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
cogl_texture_set_region (texture,
|
|
|
|
0, 0, /* src_x / src_y */
|
|
|
|
0, 0, /* dst_x / dst_y */
|
|
|
|
1, 1, /* dst_w / dst_h */
|
|
|
|
1, 1, /* width / height */
|
|
|
|
format,
|
|
|
|
4, /* rowstride */
|
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 16:56:40 -04:00
|
|
|
(uint8_t *) &tex_data);
|
2012-02-29 19:40:34 -05:00
|
|
|
|
|
|
|
test_color (texture, expected_pixel);
|
|
|
|
|
|
|
|
cogl_object_unref (texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 15:54:13 -04:00
|
|
|
test_write_texture_formats (void)
|
2012-02-29 19:40:34 -05:00
|
|
|
{
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_byte (test_ctx, COGL_PIXEL_FORMAT_A_8, 0x34, 0x00000034);
|
2012-02-29 19:40:34 -05:00
|
|
|
#if 0
|
|
|
|
/* I'm not sure what's the right value to put here because Nvidia
|
|
|
|
and Mesa seem to behave differently so one of them must be
|
|
|
|
wrong. */
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_byte (test_ctx, COGL_PIXEL_FORMAT_G_8, 0x34, 0x340000ff);
|
2012-02-29 19:40:34 -05:00
|
|
|
#endif
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_short (test_ctx, COGL_PIXEL_FORMAT_RGB_565, 0x0843, 0x080819ff);
|
|
|
|
test_write_short (test_ctx, COGL_PIXEL_FORMAT_RGBA_4444_PRE, 0x1234, 0x11223344);
|
|
|
|
test_write_short (test_ctx, COGL_PIXEL_FORMAT_RGBA_5551_PRE, 0x0887, 0x081019ff);
|
2012-02-29 19:40:34 -05:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_bytes (test_ctx, COGL_PIXEL_FORMAT_RGB_888, 0x123456ff, 0x123456ff);
|
|
|
|
test_write_bytes (test_ctx, COGL_PIXEL_FORMAT_BGR_888, 0x563412ff, 0x123456ff);
|
2012-02-29 19:40:34 -05:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_bytes (test_ctx, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
2012-02-29 19:40:34 -05:00
|
|
|
0x12345678, 0x12345678);
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_bytes (test_ctx, COGL_PIXEL_FORMAT_BGRA_8888_PRE,
|
2012-02-29 19:40:34 -05:00
|
|
|
0x56341278, 0x12345678);
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_bytes (test_ctx, COGL_PIXEL_FORMAT_ARGB_8888_PRE,
|
2012-02-29 19:40:34 -05:00
|
|
|
0x78123456, 0x12345678);
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_bytes (test_ctx, COGL_PIXEL_FORMAT_ABGR_8888_PRE,
|
2012-02-29 19:40:34 -05:00
|
|
|
0x78563412, 0x12345678);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_int (test_ctx, COGL_PIXEL_FORMAT_RGBA_1010102_PRE,
|
2012-02-29 19:40:34 -05:00
|
|
|
0x123456ff,
|
|
|
|
10, 0x12, 10, 0x34, 10, 0x56, 2, 0xff,
|
|
|
|
-1);
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_int (test_ctx, COGL_PIXEL_FORMAT_BGRA_1010102_PRE,
|
2012-02-29 19:40:34 -05:00
|
|
|
0x123456ff,
|
|
|
|
10, 0x56, 10, 0x34, 10, 0x12, 2, 0xff,
|
|
|
|
-1);
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_int (test_ctx, COGL_PIXEL_FORMAT_ARGB_2101010_PRE,
|
2012-02-29 19:40:34 -05:00
|
|
|
0x123456ff,
|
|
|
|
2, 0xff, 10, 0x12, 10, 0x34, 10, 0x56,
|
|
|
|
-1);
|
2013-01-18 12:57:06 -05:00
|
|
|
test_write_int (test_ctx, COGL_PIXEL_FORMAT_ABGR_2101010_PRE,
|
2012-02-29 19:40:34 -05:00
|
|
|
0x123456ff,
|
|
|
|
2, 0xff, 10, 0x56, 10, 0x34, 10, 0x12,
|
|
|
|
-1);
|
|
|
|
|
2012-09-16 21:18:10 -04:00
|
|
|
if (cogl_test_verbose ())
|
2012-02-29 19:40:34 -05:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|