2013-03-22 21:18:53 +00:00
|
|
|
#define COGL_VERSION_MIN_REQUIRED COGL_VERSION_1_0
|
|
|
|
|
2011-05-05 22:34:38 +00:00
|
|
|
#include <cogl/cogl.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-01-20 10:41:48 +00:00
|
|
|
#include "test-declarations.h"
|
2011-05-05 22:34:38 +00:00
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
|
|
#define QUAD_WIDTH 20
|
|
|
|
|
|
|
|
#define RED 0
|
|
|
|
#define GREEN 1
|
|
|
|
#define BLUE 2
|
|
|
|
#define ALPHA 3
|
|
|
|
|
|
|
|
#define MASK_RED(COLOR) ((COLOR & 0xff000000) >> 24)
|
|
|
|
#define MASK_GREEN(COLOR) ((COLOR & 0xff0000) >> 16)
|
|
|
|
#define MASK_BLUE(COLOR) ((COLOR & 0xff00) >> 8)
|
|
|
|
#define MASK_ALPHA(COLOR) (COLOR & 0xff)
|
|
|
|
|
|
|
|
typedef struct _TestState
|
|
|
|
{
|
2012-03-16 19:54:13 +00:00
|
|
|
int padding;
|
2011-05-05 22:34:38 +00:00
|
|
|
} TestState;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
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
|
|
|
uint32_t color;
|
2011-05-05 22:34:38 +00:00
|
|
|
float depth;
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean test_enable;
|
2011-05-05 22:34:38 +00:00
|
|
|
CoglDepthTestFunction test_function;
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean write_enable;
|
|
|
|
gboolean fb_write_enable;
|
2011-05-05 22:34:38 +00:00
|
|
|
float range_near;
|
|
|
|
float range_far;
|
|
|
|
} TestDepthState;
|
|
|
|
|
2018-11-24 12:04:47 +00:00
|
|
|
static gboolean
|
2011-05-05 22:34:38 +00:00
|
|
|
draw_rectangle (TestState *state,
|
|
|
|
int x,
|
|
|
|
int y,
|
2012-03-16 19:54:13 +00:00
|
|
|
TestDepthState *rect_state,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean legacy_mode)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
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 Cr = MASK_RED (rect_state->color);
|
|
|
|
uint8_t Cg = MASK_GREEN (rect_state->color);
|
|
|
|
uint8_t Cb = MASK_BLUE (rect_state->color);
|
|
|
|
uint8_t Ca = MASK_ALPHA (rect_state->color);
|
2012-03-16 19:54:13 +00:00
|
|
|
CoglPipeline *pipeline;
|
2011-05-05 22:34:38 +00:00
|
|
|
CoglDepthState depth_state;
|
|
|
|
|
|
|
|
cogl_depth_state_init (&depth_state);
|
|
|
|
cogl_depth_state_set_test_enabled (&depth_state, rect_state->test_enable);
|
|
|
|
cogl_depth_state_set_test_function (&depth_state, rect_state->test_function);
|
|
|
|
cogl_depth_state_set_write_enabled (&depth_state, rect_state->write_enable);
|
|
|
|
cogl_depth_state_set_range (&depth_state,
|
|
|
|
rect_state->range_near,
|
|
|
|
rect_state->range_far);
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
pipeline = cogl_pipeline_new (test_ctx);
|
2011-05-05 22:34:38 +00:00
|
|
|
if (!cogl_pipeline_set_depth_state (pipeline, &depth_state, NULL))
|
|
|
|
{
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-03-16 19:54:13 +00:00
|
|
|
if (!legacy_mode)
|
|
|
|
{
|
|
|
|
cogl_pipeline_set_color4ub (pipeline, Cr, Cg, Cb, Ca);
|
|
|
|
|
2013-10-10 16:10:52 +00:00
|
|
|
cogl_framebuffer_set_depth_write_enabled (test_fb,
|
|
|
|
rect_state->fb_write_enable);
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_push_matrix (test_fb);
|
|
|
|
cogl_framebuffer_translate (test_fb, 0, 0, rect_state->depth);
|
|
|
|
cogl_framebuffer_draw_rectangle (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
pipeline,
|
|
|
|
x * QUAD_WIDTH,
|
|
|
|
y * QUAD_WIDTH,
|
|
|
|
x * QUAD_WIDTH + QUAD_WIDTH,
|
|
|
|
y * QUAD_WIDTH + QUAD_WIDTH);
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_pop_matrix (test_fb);
|
2012-03-16 19:54:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_push_framebuffer (test_fb);
|
2012-03-16 19:54:13 +00:00
|
|
|
cogl_push_matrix ();
|
|
|
|
cogl_set_source_color4ub (Cr, Cg, Cb, Ca);
|
|
|
|
cogl_translate (0, 0, rect_state->depth);
|
|
|
|
cogl_rectangle (x * QUAD_WIDTH,
|
|
|
|
y * QUAD_WIDTH,
|
|
|
|
x * QUAD_WIDTH + QUAD_WIDTH,
|
|
|
|
y * QUAD_WIDTH + QUAD_WIDTH);
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
cogl_pop_framebuffer ();
|
|
|
|
}
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
cogl_object_unref (pipeline);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_depth (TestState *state,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
TestDepthState *rect0_state,
|
|
|
|
TestDepthState *rect1_state,
|
|
|
|
TestDepthState *rect2_state,
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean legacy_mode,
|
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
|
|
|
uint32_t expected_result)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
2018-11-24 12:04:47 +00:00
|
|
|
gboolean missing_feature = FALSE;
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
if (rect0_state)
|
2012-03-16 19:54:13 +00:00
|
|
|
missing_feature |= !draw_rectangle (state, x, y, rect0_state, legacy_mode);
|
2011-05-05 22:34:38 +00:00
|
|
|
if (rect1_state)
|
2012-03-16 19:54:13 +00:00
|
|
|
missing_feature |= !draw_rectangle (state, x, y, rect1_state, legacy_mode);
|
2011-05-05 22:34:38 +00:00
|
|
|
if (rect2_state)
|
2012-03-16 19:54:13 +00:00
|
|
|
missing_feature |= !draw_rectangle (state, x, y, rect2_state, legacy_mode);
|
2011-05-05 22:34:38 +00:00
|
|
|
|
|
|
|
/* We don't consider it an error that we can't test something
|
|
|
|
* the driver doesn't support. */
|
|
|
|
if (missing_feature)
|
|
|
|
return;
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
test_utils_check_pixel (test_fb,
|
2012-03-16 19:54:13 +00:00
|
|
|
x * QUAD_WIDTH + (QUAD_WIDTH / 2),
|
2011-10-26 13:15:14 +00:00
|
|
|
y * QUAD_WIDTH + (QUAD_WIDTH / 2),
|
|
|
|
expected_result);
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
paint (TestState *state)
|
|
|
|
{
|
|
|
|
/* Sanity check a few of the different depth test functions
|
|
|
|
* and that depth writing can be disabled... */
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Closest */
|
|
|
|
TestDepthState rect0_state = {
|
|
|
|
0xff0000ff, /* rgba color */
|
|
|
|
-10, /* depth */
|
|
|
|
FALSE, /* depth test enable */
|
|
|
|
COGL_DEPTH_TEST_FUNCTION_ALWAYS,
|
|
|
|
TRUE, /* depth write enable */
|
2013-10-10 16:10:52 +00:00
|
|
|
TRUE, /* FB depth write enable */
|
2011-05-05 22:34:38 +00:00
|
|
|
0, 1 /* depth range */
|
|
|
|
};
|
|
|
|
/* Furthest */
|
|
|
|
TestDepthState rect1_state = {
|
|
|
|
0x00ff00ff, /* rgba color */
|
|
|
|
-70, /* depth */
|
|
|
|
TRUE, /* depth test enable */
|
|
|
|
COGL_DEPTH_TEST_FUNCTION_ALWAYS,
|
|
|
|
TRUE, /* depth write enable */
|
2013-10-10 16:10:52 +00:00
|
|
|
TRUE, /* FB depth write enable */
|
2011-05-05 22:34:38 +00:00
|
|
|
0, 1 /* depth range */
|
|
|
|
};
|
|
|
|
/* In the middle */
|
|
|
|
TestDepthState rect2_state = {
|
|
|
|
0x0000ffff, /* rgba color */
|
|
|
|
-20, /* depth */
|
|
|
|
TRUE, /* depth test enable */
|
|
|
|
COGL_DEPTH_TEST_FUNCTION_NEVER,
|
|
|
|
TRUE, /* depth write enable */
|
2013-10-10 16:10:52 +00:00
|
|
|
TRUE, /* FB depth write enable */
|
2011-05-05 22:34:38 +00:00
|
|
|
0, 1 /* depth range */
|
|
|
|
};
|
|
|
|
|
|
|
|
test_depth (state, 0, 0, /* position */
|
|
|
|
&rect0_state, &rect1_state, &rect2_state,
|
2012-03-16 19:54:13 +00:00
|
|
|
FALSE, /* legacy mode */
|
2011-05-05 22:34:38 +00:00
|
|
|
0x00ff00ff); /* expected */
|
|
|
|
|
|
|
|
rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_ALWAYS;
|
|
|
|
test_depth (state, 1, 0, /* position */
|
|
|
|
&rect0_state, &rect1_state, &rect2_state,
|
2012-03-16 19:54:13 +00:00
|
|
|
FALSE, /* legacy mode */
|
2011-05-05 22:34:38 +00:00
|
|
|
0x0000ffff); /* expected */
|
|
|
|
|
|
|
|
rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_LESS;
|
|
|
|
test_depth (state, 2, 0, /* position */
|
|
|
|
&rect0_state, &rect1_state, &rect2_state,
|
2012-03-16 19:54:13 +00:00
|
|
|
FALSE, /* legacy mode */
|
2011-05-05 22:34:38 +00:00
|
|
|
0x0000ffff); /* expected */
|
|
|
|
|
|
|
|
rect2_state.test_function = COGL_DEPTH_TEST_FUNCTION_GREATER;
|
|
|
|
test_depth (state, 3, 0, /* position */
|
|
|
|
&rect0_state, &rect1_state, &rect2_state,
|
2012-03-16 19:54:13 +00:00
|
|
|
FALSE, /* legacy mode */
|
2011-05-05 22:34:38 +00:00
|
|
|
0x00ff00ff); /* expected */
|
|
|
|
|
|
|
|
rect0_state.test_enable = TRUE;
|
|
|
|
rect1_state.write_enable = FALSE;
|
|
|
|
test_depth (state, 4, 0, /* position */
|
|
|
|
&rect0_state, &rect1_state, &rect2_state,
|
2012-03-16 19:54:13 +00:00
|
|
|
FALSE, /* legacy mode */
|
2011-05-05 22:34:38 +00:00
|
|
|
0x0000ffff); /* expected */
|
2013-10-10 16:10:52 +00:00
|
|
|
|
|
|
|
rect1_state.write_enable = TRUE;
|
|
|
|
rect1_state.fb_write_enable = FALSE;
|
|
|
|
test_depth (state, 4, 0, /* position */
|
|
|
|
&rect0_state, &rect1_state, &rect2_state,
|
|
|
|
FALSE, /* legacy mode */
|
|
|
|
0x0000ffff); /* expected */
|
|
|
|
|
|
|
|
/* Re-enable FB depth writing to verify state flush */
|
|
|
|
rect1_state.write_enable = TRUE;
|
|
|
|
rect1_state.fb_write_enable = TRUE;
|
|
|
|
test_depth (state, 4, 0, /* position */
|
|
|
|
&rect0_state, &rect1_state, &rect2_state,
|
|
|
|
FALSE, /* legacy mode */
|
|
|
|
0x00ff00ff); /* expected */
|
2011-05-05 22:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the depth buffer values can be mapped into different
|
|
|
|
* ranges... */
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Closest by depth, furthest by depth range */
|
|
|
|
TestDepthState rect0_state = {
|
|
|
|
0xff0000ff, /* rgba color */
|
|
|
|
-10, /* depth */
|
|
|
|
TRUE, /* depth test enable */
|
|
|
|
COGL_DEPTH_TEST_FUNCTION_ALWAYS,
|
|
|
|
TRUE, /* depth write enable */
|
2013-10-10 16:10:52 +00:00
|
|
|
TRUE, /* FB depth write enable */
|
2011-05-05 22:34:38 +00:00
|
|
|
0.5, 1 /* depth range */
|
|
|
|
};
|
|
|
|
/* Furthest by depth, nearest by depth range */
|
|
|
|
TestDepthState rect1_state = {
|
|
|
|
0x00ff00ff, /* rgba color */
|
|
|
|
-70, /* depth */
|
|
|
|
TRUE, /* depth test enable */
|
|
|
|
COGL_DEPTH_TEST_FUNCTION_GREATER,
|
|
|
|
TRUE, /* depth write enable */
|
2013-10-10 16:10:52 +00:00
|
|
|
TRUE, /* FB depth write enable */
|
2011-05-05 22:34:38 +00:00
|
|
|
0, 0.5 /* depth range */
|
|
|
|
};
|
|
|
|
|
|
|
|
test_depth (state, 0, 1, /* position */
|
|
|
|
&rect0_state, &rect1_state, NULL,
|
2012-03-16 19:54:13 +00:00
|
|
|
FALSE, /* legacy mode */
|
2011-05-05 22:34:38 +00:00
|
|
|
0xff0000ff); /* expected */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test that the legacy cogl_set_depth_test_enabled() API still
|
|
|
|
* works... */
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Nearest */
|
|
|
|
TestDepthState rect0_state = {
|
|
|
|
0xff0000ff, /* rgba color */
|
|
|
|
-10, /* depth */
|
|
|
|
FALSE, /* depth test enable */
|
|
|
|
COGL_DEPTH_TEST_FUNCTION_LESS,
|
|
|
|
TRUE, /* depth write enable */
|
2013-10-10 16:10:52 +00:00
|
|
|
TRUE, /* FB depth write enable */
|
2011-05-05 22:34:38 +00:00
|
|
|
0, 1 /* depth range */
|
|
|
|
};
|
|
|
|
/* Furthest */
|
|
|
|
TestDepthState rect1_state = {
|
|
|
|
0x00ff00ff, /* rgba color */
|
|
|
|
-70, /* depth */
|
|
|
|
FALSE, /* depth test enable */
|
|
|
|
COGL_DEPTH_TEST_FUNCTION_LESS,
|
|
|
|
TRUE, /* depth write enable */
|
2013-10-10 16:10:52 +00:00
|
|
|
TRUE, /* FB depth write enable */
|
2011-05-05 22:34:38 +00:00
|
|
|
0, 1 /* depth range */
|
|
|
|
};
|
|
|
|
|
|
|
|
cogl_set_depth_test_enabled (TRUE);
|
|
|
|
test_depth (state, 0, 2, /* position */
|
|
|
|
&rect0_state, &rect1_state, NULL,
|
2012-03-16 19:54:13 +00:00
|
|
|
TRUE, /* legacy mode */
|
2011-05-05 22:34:38 +00:00
|
|
|
0xff0000ff); /* expected */
|
|
|
|
cogl_set_depth_test_enabled (FALSE);
|
|
|
|
test_depth (state, 1, 2, /* position */
|
|
|
|
&rect0_state, &rect1_state, NULL,
|
2012-03-16 19:54:13 +00:00
|
|
|
TRUE, /* legacy mode */
|
2011-05-05 22:34:38 +00:00
|
|
|
0x00ff00ff); /* expected */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-16 19:54:13 +00:00
|
|
|
test_depth_test (void)
|
2011-05-05 22:34:38 +00:00
|
|
|
{
|
|
|
|
TestState state;
|
|
|
|
|
2013-01-18 17:57:06 +00:00
|
|
|
cogl_framebuffer_orthographic (test_fb, 0, 0,
|
|
|
|
cogl_framebuffer_get_width (test_fb),
|
|
|
|
cogl_framebuffer_get_height (test_fb),
|
2012-03-16 19:54:13 +00:00
|
|
|
-1,
|
|
|
|
100);
|
2011-10-01 14:34:24 +00:00
|
|
|
|
2011-05-05 22:34:38 +00:00
|
|
|
paint (&state);
|
|
|
|
|
2012-02-23 12:30:51 +00:00
|
|
|
if (cogl_test_verbose ())
|
2011-05-05 22:34:38 +00:00
|
|
|
g_print ("OK\n");
|
|
|
|
}
|
|
|
|
|