2011-10-01 05:04:32 -04:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
2011-05-05 18:34:38 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-01-20 05:41:48 -05:00
|
|
|
#include "test-declarations.h"
|
2011-10-01 05:04:32 -04:00
|
|
|
#include "test-utils.h"
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-10-01 05:04:32 -04:00
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
} TestState;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
static void
|
2011-10-01 05:04:32 -04:00
|
|
|
validate_result (TestState *state)
|
|
|
|
{
|
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 *pixels, *p;
|
2011-10-01 05:04:32 -04:00
|
|
|
char *screen_pixel;
|
|
|
|
const char *intended_pixel = "#ffffff";
|
|
|
|
|
|
|
|
/* The textures are setup so that when added together with the
|
|
|
|
correct matrices then all of the pixels should be white. We can
|
|
|
|
verify this by reading back the entire stage */
|
|
|
|
pixels = g_malloc (state->width * state->height * 4);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_read_pixels (test_fb, 0, 0, state->width, state->height,
|
2012-03-16 15:54:13 -04:00
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
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 *)pixels);
|
2011-10-01 05:04:32 -04:00
|
|
|
|
|
|
|
for (p = pixels; p < pixels + state->width * state->height; p++)
|
|
|
|
{
|
|
|
|
screen_pixel = g_strdup_printf ("#%06x", GUINT32_FROM_BE (*p) >> 8);
|
|
|
|
g_assert_cmpstr (screen_pixel, ==, intended_pixel);
|
|
|
|
g_free (screen_pixel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
paint (TestState *state)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
|
|
|
/* This texture is painted mirrored around the x-axis */
|
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 data0[] = {
|
2011-05-05 18:34:38 -04:00
|
|
|
0xff, 0x00, 0x00, /* red -> becomes bottom left */
|
|
|
|
0x00, 0xff, 0x00, /* green -> becomes bottom right */
|
|
|
|
0x00, 0x00, 0xff, /* blue -> becomes top left */
|
|
|
|
0xff, 0x00, 0xff /* magenta -> becomes top right */
|
|
|
|
};
|
|
|
|
/* This texture is painted mirrored about the y-axis */
|
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 data1[] = {
|
2011-05-05 18:34:38 -04:00
|
|
|
0x00, 0xff, 0x00, /* green -> becomes top right */
|
|
|
|
0xff, 0xff, 0x00, /* yellow -> becomes top left */
|
|
|
|
0xff, 0x00, 0xff, /* magenta -> becomes bottom right */
|
|
|
|
0x00, 0xff, 0xff /* cyan -> becomes bottom left */
|
|
|
|
};
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglTexture *tex0, *tex1;
|
2011-05-05 18:34:38 -04:00
|
|
|
CoglPipeline *pipeline;
|
|
|
|
CoglMatrix matrix;
|
2012-08-31 14:28:27 -04:00
|
|
|
CoglError *error = NULL;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_orthographic (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
0, 0,
|
|
|
|
state->width,
|
|
|
|
state->height,
|
|
|
|
-1,
|
|
|
|
100);
|
2011-10-01 05:04:32 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_clear4f (test_fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
|
2011-10-01 05:04:32 -04:00
|
|
|
|
|
|
|
cogl_matrix_init_identity (&matrix);
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_set_modelview_matrix (test_fb, &matrix);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
tex0 = cogl_texture_new_from_data (2, 2,
|
|
|
|
COGL_TEXTURE_NO_ATLAS,
|
|
|
|
COGL_PIXEL_FORMAT_RGB_888,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
6,
|
|
|
|
data0);
|
|
|
|
tex1 = cogl_texture_new_from_data (2, 2,
|
|
|
|
COGL_TEXTURE_NO_ATLAS,
|
|
|
|
COGL_PIXEL_FORMAT_RGB_888,
|
|
|
|
COGL_PIXEL_FORMAT_ANY,
|
|
|
|
6,
|
|
|
|
data1);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
/* Set the two textures as layers */
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 0, tex0);
|
|
|
|
cogl_pipeline_set_layer_filters (pipeline, 0,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST);
|
|
|
|
cogl_pipeline_set_layer_texture (pipeline, 1, tex1);
|
|
|
|
cogl_pipeline_set_layer_filters (pipeline, 1,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST,
|
|
|
|
COGL_PIPELINE_FILTER_NEAREST);
|
|
|
|
|
|
|
|
/* Set a combine mode so that the two textures get added together */
|
2011-10-01 05:04:32 -04:00
|
|
|
if (!cogl_pipeline_set_layer_combine (pipeline, 1,
|
|
|
|
"RGBA=ADD(PREVIOUS, TEXTURE)",
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
g_warning ("Error setting blend string: %s", error->message);
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
/* Set a matrix on the first layer so that it will mirror about the y-axis */
|
|
|
|
cogl_matrix_init_identity (&matrix);
|
|
|
|
cogl_matrix_scale (&matrix, 1.0f, -1.0f, 1.0f);
|
2019-03-01 19:44:54 -05:00
|
|
|
cogl_matrix_translate (&matrix, 0.0f, 1.0f, 0.0f);
|
2011-05-05 18:34:38 -04:00
|
|
|
cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
|
|
|
|
|
|
|
|
/* Set a matrix on the second layer so that it will mirror about the x-axis */
|
|
|
|
cogl_matrix_init_identity (&matrix);
|
|
|
|
cogl_matrix_scale (&matrix, -1.0f, 1.0f, 1.0f);
|
2019-03-01 19:44:54 -05:00
|
|
|
cogl_matrix_translate (&matrix, 1.0f, 0.0f, 0.0f);
|
2011-05-05 18:34:38 -04:00
|
|
|
cogl_pipeline_set_layer_matrix (pipeline, 1, &matrix);
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_framebuffer_draw_rectangle (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
pipeline,
|
|
|
|
0, 0,
|
|
|
|
state->width, state->height);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_object_unref (tex1);
|
|
|
|
cogl_object_unref (tex0);
|
2011-05-05 18:34:38 -04:00
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 15:54:13 -04:00
|
|
|
test_pipeline_user_matrix (void)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2011-10-01 05:04:32 -04:00
|
|
|
TestState state;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
state.width = cogl_framebuffer_get_width (test_fb);
|
|
|
|
state.height = cogl_framebuffer_get_height (test_fb);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2011-10-01 05:04:32 -04:00
|
|
|
paint (&state);
|
|
|
|
validate_result (&state);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-02-23 07:30:51 -05:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 18:34:38 -04:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|