2013-03-22 17:18:53 -04:00
|
|
|
#define COGL_VERSION_MIN_REQUIRED COGL_VERSION_1_0
|
|
|
|
|
2011-05-05 18:34:38 -04:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
2019-01-20 05:41:48 -05:00
|
|
|
#include "test-declarations.h"
|
2012-01-28 08:19:01 -05:00
|
|
|
#include "test-utils.h"
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
#define RED 0
|
|
|
|
#define GREEN 1
|
|
|
|
#define BLUE 2
|
|
|
|
|
2012-01-28 08:19:01 -05:00
|
|
|
typedef struct _TestState
|
|
|
|
{
|
|
|
|
int fb_width;
|
|
|
|
int fb_height;
|
|
|
|
} TestState;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-01-28 08:19:01 -05:00
|
|
|
static void
|
|
|
|
check_quadrant (TestState *state,
|
|
|
|
int qx,
|
|
|
|
int qy,
|
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_rgba)
|
2012-01-28 08:19:01 -05:00
|
|
|
{
|
|
|
|
/* The quadrants are all stuffed into the top right corner of the
|
|
|
|
framebuffer */
|
|
|
|
int x = state->fb_width * qx / 4 + state->fb_width / 2;
|
|
|
|
int y = state->fb_height * qy / 4;
|
|
|
|
int width = state->fb_width / 4;
|
|
|
|
int height = state->fb_height / 4;
|
|
|
|
|
|
|
|
/* Subtract a two-pixel gap around the edges to allow some rounding
|
|
|
|
differences */
|
|
|
|
x += 2;
|
|
|
|
y += 2;
|
|
|
|
width -= 4;
|
|
|
|
height -= 4;
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_region (test_fb, x, y, width, height, expected_rgba);
|
2012-01-28 08:19:01 -05:00
|
|
|
}
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
static void
|
2012-01-28 08:43:54 -05:00
|
|
|
test_paint (TestState *state)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2012-01-28 08:19:01 -05:00
|
|
|
CoglTexture2D *tex_2d;
|
|
|
|
CoglTexture *tex;
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglOffscreen *offscreen;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
tex_2d = cogl_texture_2d_new_with_size (test_ctx,
|
2012-01-28 08:19:01 -05:00
|
|
|
state->fb_width,
|
2013-07-01 20:48:54 -04:00
|
|
|
state->fb_height);
|
2013-10-09 08:31:12 -04:00
|
|
|
tex = tex_2d;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2013-08-16 17:43:19 -04:00
|
|
|
offscreen = cogl_offscreen_new_with_texture (tex);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-01-28 08:19:01 -05:00
|
|
|
/* Set a scale and translate transform on the window framebuffer
|
|
|
|
* before switching to the offscreen framebuffer so we can verify it
|
|
|
|
* gets restored when we switch back
|
2011-05-05 18:34:38 -04:00
|
|
|
*
|
2012-01-28 08:19:01 -05:00
|
|
|
* The test is going to draw a grid of 4 colors to a texture which
|
|
|
|
* we subsequently draw to the window with a fullscreen rectangle.
|
|
|
|
* This transform will flip the texture left to right, scale it to a
|
|
|
|
* quarter of the window size and slide it to the top right of the
|
|
|
|
* window.
|
2011-05-05 18:34:38 -04:00
|
|
|
*/
|
2012-01-28 08:43:54 -05:00
|
|
|
cogl_push_matrix ();
|
2011-05-05 18:34:38 -04:00
|
|
|
cogl_scale (-0.5, 0.5, 1);
|
2019-03-01 19:44:54 -05:00
|
|
|
cogl_translate (0.5, 0.5, 0);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2013-10-09 08:31:12 -04:00
|
|
|
cogl_push_framebuffer (offscreen);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
/* Cogl should release the last reference when we call cogl_pop_framebuffer()
|
|
|
|
*/
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_object_unref (offscreen);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
|
|
|
/* Setup something other than the identity matrix for the modelview so we can
|
|
|
|
* verify it gets restored when we call cogl_pop_framebuffer () */
|
|
|
|
cogl_scale (2, 2, 1);
|
|
|
|
|
|
|
|
/* red, top left */
|
|
|
|
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
|
|
|
cogl_rectangle (-0.5, 0.5, 0, 0);
|
|
|
|
/* green, top right */
|
|
|
|
cogl_set_source_color4ub (0x00, 0xff, 0x00, 0xff);
|
|
|
|
cogl_rectangle (0, 0.5, 0.5, 0);
|
|
|
|
/* blue, bottom left */
|
|
|
|
cogl_set_source_color4ub (0x00, 0x00, 0xff, 0xff);
|
|
|
|
cogl_rectangle (-0.5, 0, 0, -0.5);
|
|
|
|
/* white, bottom right */
|
|
|
|
cogl_set_source_color4ub (0xff, 0xff, 0xff, 0xff);
|
|
|
|
cogl_rectangle (0, 0, 0.5, -0.5);
|
|
|
|
|
|
|
|
cogl_pop_framebuffer ();
|
|
|
|
|
|
|
|
cogl_set_source_texture (tex);
|
|
|
|
cogl_rectangle (-1, 1, 1, -1);
|
|
|
|
|
2012-01-28 08:19:01 -05:00
|
|
|
cogl_object_unref (tex_2d);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-01-28 08:43:54 -05:00
|
|
|
cogl_pop_matrix ();
|
|
|
|
|
2011-05-05 18:34:38 -04:00
|
|
|
/* NB: The texture is drawn flipped horizontally and scaled to fit in the
|
|
|
|
* top right corner of the window. */
|
|
|
|
|
|
|
|
/* red, top right */
|
2012-01-28 08:19:01 -05:00
|
|
|
check_quadrant (state, 1, 0, 0xff0000ff);
|
2011-05-05 18:34:38 -04:00
|
|
|
/* green, top left */
|
2012-01-28 08:19:01 -05:00
|
|
|
check_quadrant (state, 0, 0, 0x00ff00ff);
|
2011-05-05 18:34:38 -04:00
|
|
|
/* blue, bottom right */
|
2012-01-28 08:19:01 -05:00
|
|
|
check_quadrant (state, 1, 1, 0x0000ffff);
|
2011-05-05 18:34:38 -04:00
|
|
|
/* white, bottom left */
|
2012-01-28 08:19:01 -05:00
|
|
|
check_quadrant (state, 0, 1, 0xffffffff);
|
2011-05-05 18:34:38 -04:00
|
|
|
}
|
|
|
|
|
2012-01-28 08:43:54 -05:00
|
|
|
static void
|
|
|
|
test_flush (TestState *state)
|
|
|
|
{
|
|
|
|
CoglTexture2D *tex_2d;
|
|
|
|
CoglTexture *tex;
|
2012-03-16 15:54:13 -04:00
|
|
|
CoglOffscreen *offscreen;
|
2012-01-28 08:43:54 -05:00
|
|
|
CoglColor clear_color;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
/* This tests that rendering to a framebuffer and then reading back
|
|
|
|
the contents of the texture will automatically flush the
|
|
|
|
journal */
|
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
tex_2d = cogl_texture_2d_new_with_size (test_ctx,
|
2013-07-01 20:48:54 -04:00
|
|
|
16, 16); /* width/height */
|
2013-10-09 08:31:12 -04:00
|
|
|
tex = tex_2d;
|
2012-01-28 08:43:54 -05:00
|
|
|
|
2013-08-16 17:43:19 -04:00
|
|
|
offscreen = cogl_offscreen_new_with_texture (tex);
|
2012-01-28 08:43:54 -05:00
|
|
|
|
2013-10-09 08:31:12 -04:00
|
|
|
cogl_push_framebuffer (offscreen);
|
2012-01-28 08:43:54 -05:00
|
|
|
|
|
|
|
cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 255);
|
|
|
|
cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR);
|
|
|
|
|
|
|
|
cogl_set_source_color4ub (255, 0, 0, 255);
|
|
|
|
cogl_rectangle (-1, -1, 1, 1);
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
/* First time check using read pixels on the offscreen */
|
2013-10-09 08:31:12 -04:00
|
|
|
test_utils_check_region (offscreen,
|
2012-03-16 15:54:13 -04:00
|
|
|
1, 1, 15, 15, 0xff0000ff);
|
2012-01-28 08:43:54 -05:00
|
|
|
else if (i == 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
|
|
|
uint8_t data[16 * 4 * 16];
|
2012-01-28 08:43:54 -05:00
|
|
|
int x, y;
|
|
|
|
|
|
|
|
/* Second time try reading back the texture contents */
|
|
|
|
cogl_texture_get_data (tex,
|
|
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
|
|
16 * 4, /* rowstride */
|
|
|
|
data);
|
|
|
|
|
|
|
|
for (y = 1; y < 15; y++)
|
|
|
|
for (x = 1; x < 15; x++)
|
|
|
|
test_utils_compare_pixel (data + x * 4 + y * 16 * 4,
|
|
|
|
0xff0000ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_pop_framebuffer ();
|
|
|
|
|
|
|
|
if (i == 2)
|
|
|
|
{
|
|
|
|
/* Third time try drawing the texture to the screen */
|
|
|
|
cogl_set_source_texture (tex);
|
|
|
|
cogl_rectangle (-1, -1, 1, 1);
|
2013-01-18 12:57:06 -05:00
|
|
|
test_utils_check_region (test_fb,
|
2012-03-16 15:54:13 -04:00
|
|
|
2, 2, /* x/y */
|
2012-01-28 08:43:54 -05:00
|
|
|
state->fb_width - 4,
|
|
|
|
state->fb_height - 4,
|
|
|
|
0xff0000ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_object_unref (tex_2d);
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_object_unref (offscreen);
|
2012-01-28 08:43:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-05 18:34:38 -04:00
|
|
|
void
|
2012-03-16 15:54:13 -04:00
|
|
|
test_offscreen (void)
|
2011-05-05 18:34:38 -04:00
|
|
|
{
|
2012-01-28 08:19:01 -05:00
|
|
|
TestState state;
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2013-01-18 12:57:06 -05:00
|
|
|
state.fb_width = cogl_framebuffer_get_width (test_fb);
|
|
|
|
state.fb_height = cogl_framebuffer_get_height (test_fb);
|
2011-05-05 18:34:38 -04:00
|
|
|
|
2012-03-16 15:54:13 -04:00
|
|
|
/* XXX: we have to push/pop a framebuffer since this test currently
|
|
|
|
* uses the legacy cogl_rectangle() api. */
|
2013-01-18 12:57:06 -05:00
|
|
|
cogl_push_framebuffer (test_fb);
|
2012-01-28 08:43:54 -05:00
|
|
|
test_paint (&state);
|
|
|
|
test_flush (&state);
|
2012-03-16 15:54:13 -04:00
|
|
|
cogl_pop_framebuffer ();
|
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");
|
|
|
|
}
|